Week2 2
Week2 2
– Input:
• Fabric size in square meters (SqMeters).
– Output:
• Equivalent amount in square yards (SqYards).
– Relevant Formulas:
• The relationship between sq. meter & sq. yards
• (1 m2 = 1.196 y2)
Case Study 1
Converting Units of Measurements
• Design:
– Algorithm:
1. Read the fabric size in m2.
2. Convert size to yd2 using the formula
(1 m2 = 1.196 y2).
3. Display fabric size in yd2.
– Refinement of step2:
2.1 Fabric size in yd2 = 1.196 * fabric size in m2
Case Study 1
Converting Units of Measurements
• Implementation
– Program header
• Give a logical name for your program
– Program Name: ConvertSqMtoSqYd;
• The name of the source code file of the program can be
different from the logical name
– Declaration section
• Memory cells used in your program
• Constant declaration: use constants for unchanged
values
• Variable declaration: use variables for values that
change
– Program body
• Data processing takes place here
Case Study 1
Converting Units of Measurements
– Output
• Write labels for Number, Square root, Square, and Cube
• Write values of Number, Square root, Square, and Cube
(This is one way of doing it…)
Case Study 2: Square & Cube
• Design (Algorithm)
• Output:
• Existing data plus new data to file
Case Study 3: Processing Analysis
• Processing:
– Display existing data
• Decide: about how to display the data.
E.g. Table with headers:
Assessment My Score Max Score
HW#1 8 10
…. … ….
– Prompt for new data:
• Data: Name of assessment, My score, Max score
• Decide:
– prompt for data one by one or all 3 at a time?
– prompt for data for a single assessment or multiple assessments?
If multiple assessments, how do you indicate you are done?
– Store old and new data:
• Decide:
– Overwrite the old file?
– Make a new version of the file?
• Decide:
– Display all the data the program knows about before exiting?
Case Study 3:
Revised Problem Statement
• A program that will let me enter and store the score that I
receive for each assessment in the course, the
maximum score that I could have obtained in that
assessment, and the name of the assessment. When I
run the program, it will:
– Retrieve and display the scores it already knows in a table with
suitable headers
– Give me the option to enter data for one or more additional
assessments or to exit
– If I choose to enter data for an assessment it will prompt me for
all three values on one line
– After I enter the values it will again give me the option to enter
new data or to exit.
• When I exit the program
– all the data (old and new) will be stored to a new file so that it
can be retrieved next time the program is run.
– all the data it has for me will be shown.
Are you starting to think that you should use a spreadsheet instead?