CMIS 102
A. Problem Statement:
Design a program that will allow a user to Input a list of their family members along with their age and state where they reside. Determine and output the average age of their family and output the names of anyone who lives in Tennessee.
B. Problem Analysis
The program is to calculate the total average of the family age wise and determine their location with only printing out those members that are from Tennessee. The program will take inputs from the user who will input the name, age and location of each family member. The program will take the years of all members entered and add them all together and then take the total of members entered and divide the total coming up with the average age. The program will also calculate and identify each state of each person entered and using the defined input identifies those people from Tennessee and prints their names out only. The output of the program is three fold. The total average age of all family entries, identify who is from Tennessee and print their name out.
Required Input:
· Name of family member
· Age of family member
· State of family member
Required Output:
· Average age of family
· Display names of members living in Tennessee
First of all, in main module user will be prompted to input number of family members. On the base of number family members in that family arrays will be created to store name, age and state.
Then, user will be asked to enter name, age and state of family members in a loop. In each iteration, user inputted values will be stored in respective arrays locations. Also the ages will be added.
In last step, loop will run as many times as number of family members. Inside this loop state array will be check to see if it has value ‘Tennessee’. If so, the corresponding name array value will be printed. Also in that loop sum of family member age is calculated which is used to calculate average age.
Following formula will be used to calculate average age
AverageAge = SumAge / NumberOfMember
Variables Used:
|
Sr. No. |
Variable Name |
Description |
Data Type |
Module Referenced |
Scope |
|
1. |
numMembers |
integer to store number of family members |
Integer |
get_Family_Data, display_Family_Data |
Local |
|
2. |
Name |
array to store names of family members |
String |
get_Family_Data, display_Family_Data |
Local |
|
3. |
Age |
array to store ages of family members |
Integer |
get_Family_Data, display_Family_Data |
Local |
|
4. |
State |
array to store states of family members |
String |
get_Family_Data, display_Family_Data |
Local |
|
5. |
AverageAge |
store average age of family members |
Integer |
display_Family_Data |
Local |
|
6. |
SumAge |
store addition of ages of family members |
Integer |
display_Family_Data |
Local |
C. Test Cases:
Test cases to validate the program.
|
Test Case # |
Input |
Expected Output |
|
1 |
Name: Fred, Age: 82, State: MD Name: Mary, Age:75, State: OH Name: Joe, Age: 45, State: TX Name: Julie, Age: 47, State: TN Name: Beth, Age: 9, State: TN |
Average age: 51.6 Names of members who live in Tennessee: Julie Beth |
|
2 |
Name: Tom, Age: 21, State: TN Name: Bill, Age:4, State: FL Name: Joe, Age: 22, State: TX Name: Stacy, Age: 25, State: FL Name: Nancy, Age: 27, State: FL |
Average age: 21.8 Names of members who live in Tennessee: Joe |
|
3 |
Name: Morris, Age: 20, State: TN Name: Kelvin, Age:20, State: FL Name: Billy, Age: 30, State: TX Name: Marry, Age: 40, State: FL Name: Nancy, Age: 50, State: TX |
Average age: 32 Names of members who live in Tennessee: Morris |
D. Peudocode:
The code will ask first about number of family members and create array of this length. It can handle any number of family members.
Main module
//Declare a variable for number of members
Declare numMembers
Write “Enter number of family members : “
//getting input from user
Input numMembers
//Declaring arrays with length numMembers
Declare name[numMembers] as String
Declare age[numMembers] as Integer
Declare state[numMembers] as String
Call get_Family_Data(numMembers, Name, Age, State)
Call display_Family_Data(numMembers, Name, Age, State)
End main
//module to get user input
get_Family_Data ()
// Asking details from user
For i = 0 to numMembers -1
Write “Enter name of family member: “, (i+1)
Input name[i]
Write “Enter age of family member: “, (i+1)
Input age[i]
Write “Enter state of family member: “, (i+1)
Input state [i]
End For
End get_Family_Data
//module to display family details
Start display_Family_Data ()
//Declare a variable for storing average age
Declare averageAge as double
//Declare a variable for storing sum of age
Declare sumAge as double = 0
// For loop to calculate sum of age of family members
For (i=0; i < numMembers; i++)
sumAge = sumAge + age[i]
End for
// Calculate average age of the family
averageAge = sumAge / numMembers
Write “Average age: “,averageAge
Write “Members who live in TN: “
// For loop to display family members living in TN
For (i=0; i < numMembers; i++)
sumAge = sumAge + age[i]
If Input state [i] = “Tennessee”
Write name[i]
End if
End for
End display_Family_Data