Sie sind auf Seite 1von 1

HiLCoE

School of Computer Science & Technology

CS222 Computer programming II Autumn 2oo9


Worksheet 4 (Common variables)
Objective:
• To use common variables as a means of communication among functions.
• To see the drawbacks of common variables.
Instruction
First draw the inter module communication designs for the following problems then after
write an entirely modular programs for each one of the designs. Your modular programs
should provide a mechanism to allow users to terminate the program in their own time.

1. Draw a design that shows the inter module communication among the functions given
below then write an entirely modular program that computes the standard deviation of a
data set of n numbers x 0, . . . , x n-1 using the following formula

n-1 _
_ 2 Where x is the mean of
xi- x the data
S =
i=0

n -1

Your program must contain the following four functions


Functions names Descriptions
inpNumbers Accepts a data set of n numbers.
Mean Computes the mean of the numbers.
stdDev Computes the standard deviation of the numbers.
Display Displays the numbers together with their standard deviation.
Remark:- The mean function should only be called in the stdDev function.

2. Based on the suggested function prototypes given below, draw the inter module
communication design into two different ways. Then after, write a modular program that
computes and displays the maximum, the minimum & the range of the list of marks that
has been accepted from the user.

Function prototypes Descriptions


void readList( ); Accepts list of marks from the user.
void findMax( ); Computes the maximum mark from the list.
void findMin( ); Computes the minimum mark from the list.
void findRange( ); Computes the range of the marks.
void display ( ); Displays the list of marks together with the maximum
mark, minimum marks and the range of the marks.
3. Draw a design that shows the inter module communication among the functions given
below then write a modular program that does the functionalities of a simple calculator.
Use the following suggested function prototypes.

Function prototypes Descriptions


void menu( ); Displays a menu of operations.
void inputNum ( ); Accepts lists of numbers or operands.
void sum ( ); Computes the sum of the list of numbers.
void difference( ); Computes the difference of the list of numbers.
void product ( ); Computes the product of the list of numbers.
void quotient ( ); Computes the quotient of the list of numbers.
void display ( ); Displays the operands together with the result of the operation.

Das könnte Ihnen auch gefallen