Download Problem Statement

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Pattern recognition wikipedia , lookup

Transcript
Problem Document
CS-320
Lab Assignment 0
Measurement Conversion
Tom Jones
7/6/2001
Problem Statement
Fabrics purchased outside the US are often measured in square meters. When sold locally, they must be
marked and priced in square yards. A program is needed to convert an input value in square meters to an
output value in square yards.
Input
Square meters - input via the keyboard, this is a floating-point number representing the value to be
converted.
Output
Square yards – This is a floating-point number representing the calculated measurement in square yards. It
will be output to the display along with a brief leader.
Major Tasks
Read Data – Prompt the user to enter the value in square meters to be converted, and then read in the value
as a floating-point value.
Calc Yards – Calculate the number of square yards that is equivalent to the input value in square meters.
The equality: yard2 = 1.196 * meter2 will be used as the basis for the calculation
Print Data – Write the calculated value in square yards to the display.
Structure Chart
Test Plan
INPUT VALUE
0
1
-100
EXPECTED RESULT
0.00
1.20
-119.60
PURPOSE
Simple verification of multiplication
Verification of multiplication and rounding
Verifies acceptance of negative numbers, displays
conversion factor
/*************************************************************************************
Module Name: measure .c
Description:
This program converts fabric measurements given in square meters
to the equivalent measurement in square yards.
Date:
6/25/2001
Designer:
Tom Jones
Course #:
CS320
Assignment:
Lab 0
main – Top level logic of program
Read_data – Accepts input from user via Keyboard
Calc_yards – Performs conversion of square meters to square yards
Print_data – Displays results on terminal
*************************************************************************************/
Functions:
#include <stdio.h>
/*************************************************************************************
Function:
Read_data
Description:
Prompts for and read the number of square meters
Input:
Keyboard:
meters – square meters
Output:
Return Value: Square meters value as entered by user
Algorithm:
Display prompt, read value as float. No validation is performed
Calls to: None
************************************************************************************/
float Read_data()
{
float meters;
/* Temporary storage for square meters input */
/* Prompt for and read square meters */
printf ( “ Enter fabric size in square meters: ” );
scanf ( “%f”, &meters );
return meters;
}
/*************************************************************************************
Function:
Calc_yards
Description:
Converts square meters to square yards
Input:
Parameters:
meters – measurement in square meters
Output:
Return Value: Calculated value in square yards
Algorithm:
Multiply square meters measurement by 1.196
Calls to: None
************************************************************************************/
float Calc_yards( float meters )
{
float conversion_factor = 1.196;
return ( meters * conversion_factor);
}
/*************************************************************************************
Function:
Print_data
Description:
Display the square yards measurement on the monitor
Input:
Parameters:
yards – measurement in square yards
Output:
Display:
Value of yards along with descriptive label
Algorithm:
Print label followed by yards
Calls to: None
*************************************************************************************/
void Print_data( float yards )
{
printf( “ Equivalent measurements in square yards id %5.3f”, yards );
}
/*************************************************************************************
Function:
main
Description:
main function for program
Input:
None
Output:
Display:
Header printed before each call to Read_data
Algorithm:
Prints header and then calls Read_data, Calc_yards, and Print_data
In order
Calls to: Read_data, Calc_yards, Print_data
*************************************************************************************/
void main()
{
float square_meters;
float square_yards;
/* Fabric measurement in square meters */
/* Fabric measurement in square yards */
/* Display Program header */
printf( “\n Fabric Measurement Conversion \n” );
/* read square meters */
square_meters = Read_data();
/* Convert square meters to square yards */
yards = Calc_yards(meters);
/* Print result */
Print_data(yards);
}