EXAMPLE OF AN ANALYSIS PROBLEM


AN ASSIGNMENT INVOLVING SEQUENTIAL STRUCTURE

The analysis assignments in this course present the student with a "situation" that describes a reason for developing a program. From it the student is required to perform an analysis of the task to be accomplished by the program and produce various items of documentation that clearly illustrate the decisions made by the student during the problem solving process.

The Situation:

You want a fast way to determine the true "per bite" value of a pizza given its price and diameter. For example: Is a 10 inch diameter pizza that costs $6.95 a better buy than 12 inch diameter pizza priced at $8.99? Which one costs less per square inch?

You want a program that you could run once for each pizza that you are considering. The program would ask for the necessary data about a pizza and then calculate and display that pizza's value in units of "cents per square inch".

A Typical Assignment:

A student would be asked to analyze this problem in preparation for writing a computer program to accomplish the objective stated above, given the following facts:

The program should evaluate just one pizza each time it is run. It should be developed to work for any size pizza of any price. It should request the pizza's diameter in inches and its price in dollars. It will be run once for each pizza to be evaluated. The analysis should be documented clearly so that any programmer could write the program's code later. Although program code is often developed by different people than those who perform the analysis, in this example the development of the program code will be included.

Typical Submission Instructions:

At the beginning of class on the day that the assignment is due, the student would be told to submit the following items:

Each item of documentation should be clearly labeled. Each page should contain at least: your name, the program's name, the date, and the page number.


SOLUTION

The following documentation is intended to serve as an example of what would be expected from an analyst when designing a program related to the situation described above. All italicized text below serves only to clarify the documentation for students, but would not actually appear in the real documentation.

PROBLEM STATEMENT

This should define the program's task. The "problem" is not to write the program! It is to do whatever task the problem requires for its solution. This statement must be clear and complete enough for the program to be written entirely from just it and the sample outputs that follow it.

Determine and display the true "per bite" value of a pizza in cents per square inch after requesting and storing its price in dollars and its diameter in inches (both input from the keyboard). For the purposes of this program, a "bite" equals one square inch. Allow the input of values with decimal points and display the final answer rounded to two decimal places.

DATA DEFINITION

In the sample output below:

SAMPLE OUTPUT (Softcopy):

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
Pizza Value Calculating Program
by Randolph U. Gibson - 1 January 2003

This program will determine and display the true "per bite"
value of a pizza given its price and diameter. The value will
be displayed in cents per square inch.

Please enter the following data without dollar signs:
Price of the Pizza (in dollars): 99.99
Diameter of the Pizza (in inches): 99.99

The "per bite" value of that pizza is 99.99 cents per square inch.

SAMPLE OUTPUT (Hardcopy):

(none)

 

SYMBOLIC CONSTANT LIST:

Symbolic constants are fixed values that may be referenced using a label at many different locations within a program's instructions rather than repeating the value many times. This practice makes it easy to update the program if the value ever needs to be changed. The constant identified below is typical of those found in most programs. Actually, the value PI will probably never change, but it is being treated as a constant here to demonstrate how constants are handled.

LABEL DESCRIPTION VALUE USAGE DESTINATION
PI Mathematical ratio PI 3.14159 for AREA ---

VARIABLE LIST:

Variables are storage locations that hold values that will be different each time a program is run. Each variable is given a label that can be used by programmers to identify the storage location without having to know its numeric address in computer memory.

LABEL DESCRIPTION SOURCE USAGE DESTINATION
PRICE Price of the pizza in dollars Keyboard for VALUE ---
DIAM Diameter of the pizza in inches Keyboard for AREA ---
AREA Area of the pizza in sq. inches Calculation for VALUE ---
VALUE Per Bite Value in cents per sq. inch Calculation --- Screen

Notice that the description column clearly identifies each piece of data that must be stored including units of measure. The last three columns are used to indicate: (SOURCE) where the data comes from, (USAGE) what happens to it while it is stored, and (DESTINATION) where it will end up (for example, a screen, a printer, or disk storage). Notice that each variable has an entry in the SOURCE column (all data comes from somewhere) and each variable has an entry in one of the other two columns as well. Some variables have an entry in all three columns.

ALGORITHM

A. Start.
B. Output Intro. & Instructions as shown in Softcopy.
   B1. Program Title on Line 1.
   B2. Program Credits (Author and Date) on Line 2.
   B3. Blank Line.
   B4. Introduction on Softcopy Lines 4 - 6.
   B5. Blank Line.
C. Request and store data as shown in Softcopy on lines 8 - 10.
   C1. Display input instructions.
   C2. Display prompt for PRICE (w/o carriage return).
   C3. Read keyboard entry and store it in PRICE, then display car. return.
   C4. Display prompt for DIAM (w/o carriage return).
   C5. Read keyboard entry and store it in DIAM, then display car. return.
D. Calculate and store interim and final answers.
   D1. Store AREA as PI times the square of half the DIAM.
   D2. Store VALUE as PRICE times 100 divided by the AREA.
E. Display answers on the screen as shown in the Softcopy on lines 11 & 12.
   E1. Blank Line 11.
   E2. Line 12.
       E2a. "The "per bite" value of that pizza is " (note trailing space without carriage return).
       E2b. VALUE (rounded to two decimal places with no carriage return).
       E2c. " cents per square inch." (note leading space) followed by a carriage return.
F. End.

DESK CHECK

To perform a desk check, simply make up some sample input data to use as you read through and perform the steps in your algorithm on paper. Whenever your algorithm says to output something, write that on a blank piece of paper simulating either the monitor screen or printed paper output. Whenever your algorithm says to store a value, record that in a tracing chart similar to the one below so that you can easily keep track of all of the variables while performing your test. When you reach the end of your algorithm, the simulated output (softcopy or hardcopy) should exactly match the ones that you wrote as sample goals at the beginning of the analysis.

DATA TRACING CHART USING SAMPLE DATA:

The Data Tracing Chart is used to document what would be happening in the computer's memory during the execution of the steps described in your algorithm. A column is provided for each variable in your analysis with an additional column (#1) to serve as a reference to steps in your algorithm. Note in the chart below that it only relates to steps in the algorithm that effect the memory (ie. steps C & D).

  Input Calculated
  PRICE DIAM AREA VALUE
         
C3 6.95      
C5   10.0    
         
D1     78.53975  
D2       8.8490

TEST OUTPUT (Softcopy):

The Test Output is produced by manually reading through the steps in your algorithm and recording (on paper) any output (softcopy or hardcopy) that your steps would produce. For example, given the test data used in the chart above, the algorithm on the following page would produce the following softcopy.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
Pizza Value Calculating Program
by Randolph U. Gibson - 1 January 2003

This program will determine and display the true "per bite"
value of a pizza given its price and diameter. The value will
be displayed in cents per square inch.

Please enter the following data without dollar signs:
Price of the Pizza (in dollars): 6.95
Diameter of the Pizza (in inches): 10.0

The "per bite" value of that pizza is 8.85 cents per square inch.

SOURCE CODE IN C

Note: Analysis assignments do not require source code. It is included here simply to provide a complete example of a program's development.)

/***********************************
 *  Pizza Program                  *
 *  Written by: Randolph U. Gibson *
 *  Date: August 24, 2001          *
 ***********************************/

#include <stdio.h>  /* Standard I/O header */

#define PI 3.14159   /* Symbolic constant PI representing constant 3.14159 */

float PRICE; /* Price of the pizza in dollars */
float DIAM;  /* Diameter of the pizza in inches */
float AREA;  /* Area of the pizza in square inches */
float VALUE; /* Value of the pizza in cents per square inch */

int main (void)
{
 /* Intro. & Instructions */
 printf ("Pizza Value Calculating Program\n");
 printf ("by Randolph U. Gibson - 1 January 2003\n\n");
 printf ("This program will determine and display the true \"per bite\"\n");
 printf ("value of a pizza given its price and diameter. The value will\n");
 printf ("be displayed in cents per square inch.\n\n");

 /* Data Input Section */
 printf ("Please enter the following data without dollar signs:\n");
 printf ("Price of the Pizza (in dollars): ");
 scanf ("%f", &PRICE);  /*scanf automatically displays \n when done */
 printf ("Diameter of the Pizza (in inches): ");
 scanf ("%f", &DIAM); /*scanf automatically displays \n when done */

 /* Calculation Section */
 AREA = PI * DIAM/2 * DIAM/2;
 VALUE = PRICE * 100 / AREA;

 /* Output Section */
 printf ("\nThe \"per bite\" value of that pizza is %.2f cents per square inch.", VALUE);

 return (0);  /* Return zero error code to parent process */

}

PATH: Instructional Server> COP 2000> Examples>