22
Student Name: Class/Section: Professor Name: Assignment due date: A. Problem Analysis 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 Texas. The program is to calculate the total average age of my family members and determine their location with only printing out those members that are from Texas. The program will take inputs from the user who will input the name, age and location of each 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 Texas 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 Texas and print their name out. Required Output: Average age of all persons entered Print name of person(s) from Texas ONLY In the output description you describe the information, not what the program will do. Actions like print are not appropriate here Required Input: Name of person

Problem Analysis - f01. Web viewIn each iteration, ... Yet another warning for next week is that saying “lives in Texas” after each name ... an integer variable to control the

Embed Size (px)

Citation preview

Page 1: Problem Analysis - f01. Web viewIn each iteration, ... Yet another warning for next week is that saying “lives in Texas” after each name ... an integer variable to control the

Student Name:

Class/Section:

Professor Name:

Assignment due date:

A. Problem Analysis

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 Texas.

The program is to calculate the total average age of my family members and determine their location with only printing out those members that are from Texas. The program will take inputs from the user who will input the name, age and location of each 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 Texas 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 Texas and print their name out.

Required Output: Average age of all persons entered Print name of person(s) from Texas ONLY

In the output description you describe the information, not what the program will do. Actions like print are not appropriate here

Required Input: Name of person Age of person State of where person came from

This is not an adequate description of the input. The input is that set of information for an unknown number of people. Your description seems to say that only a single person will be input.

Need to say how the end of the input is marked

The program will take inputs and calculate the average of all of the ages entered, identify which persons are from Texas and print their name.

Page 2: Problem Analysis - f01. Web viewIn each iteration, ... Yet another warning for next week is that saying “lives in Texas” after each name ... an integer variable to control the

An array will be used to hold the data for calculating who comes from Texas

First of all, the user will be asked to enter name, age and state of family members in a sentinel loop. Then, an array will be used to hold number of names for total count. In each iteration, user inputted values will be stored in respective arrays locations. Also the ages will be added.

The average age can be calculated by dividing the total age of all persons from the number of members. So, formula will be

AverageAge = SumAge / Fam_Size

Next 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 ‘Texas’. If so, the corresponding name array value will be printed.

Example input/output below:*Entry in bold are user input

Enter family member name: Bob Enter family member age: 25 Enter family member state: New York Enter family member name: Jack Enter family member age: 55 Enter family member state: Texas Enter family member name: Mark Enter family member age: 50 Enter family member state: Texas Enter family member name: Paul Enter family member age: 18 Enter family member state: New York Enter family member name: Rick Enter family member age: 23 Enter family member state: Texas Enter family member name: Amy Enter family member age: 61 Enter family member state: Texas

need to show them entering the sentinel value

Fam_Size = 6Average Age = 38.6666666667Members who lives in TexasJack lives in Texas

Page 3: Problem Analysis - f01. Web viewIn each iteration, ... Yet another warning for next week is that saying “lives in Texas” after each name ... an integer variable to control the

Mark lives in Texas

You have not given any of the required formulas. Look at Hints for Final Project to see what was needed

Array data:

Name [0] = Bob Age[0] = 25 State[0] = “New York” Name [1]= Jack Age [1]=55 State [1]=Texas Name [2]= Mark Age [2]=50 State [3]=Texas Name [0] = Paul Age[3] = 18 State[3] = “New York” Name [4]= Rick Age [4]=23 State [4]=Texas Name [5]=Amy Age [5]=61 State [5]=Texas

Page 4: Problem Analysis - f01. Web viewIn each iteration, ... Yet another warning for next week is that saying “lives in Texas” after each name ... an integer variable to control the

Calculating Average Age:

Fam_Size = 6 SumAge = Age[0] + Age [1] + Age [2] Age[3] + Age [4] + Age [5] = 25+55+50+18+23+61 =

232 AverageAge = SumAge / Fam_Size = 232 / 6 = 38.6666666667

The way you show sumage being computed is not a way the computer can do it. Need to have a loop and add a single element from the array on each loop iteration

Printing those who live in TexasLoop from i=0 to Fam_Size = 0

So where is the formula for this?

If State[i] = “Texas”

you have the assignment operator where you need the quality relational operator

Display Name[i], “lives in Texas”End if

Just some warning. If you do it this way, printing as soon as you find a Texan, that is a fundamental violation of modular programming concepts, and you will lose a lot of point next week. What you need to do is assign the name of the Texan to a variable. Need a formula for that

Another warning for next week is that Display is not a valid instruction. Need to use Write’

Yet another warning for next week is that saying “lives in Texas” after each name give cluttered hard to read output. Just say, before the loop, the following people live in Texas, then have only the name, 1 name per line

End For

State[1] is equal to Texas thus: WRITE Name[1] “lives in Texas”

State[2] is equal to Texas thus: WRITE Name[2] “lives in Texas”

Page 5: Problem Analysis - f01. Web viewIn each iteration, ... Yet another warning for next week is that saying “lives in Texas” after each name ... an integer variable to control the

Variables Used:Sr. No.

Variable Name Default Value

Description Data Type

Module/Subprogram Referenced

1. MAX_PERSONS 100 MAX_PERSONS is maximum array size (User can enter details of 100 members).

Integer Main

2. Fam_Size 0 integer number of family members names input

Integer Input, Process, Output

3. Name 100 array to store names of family members

String Input, Output

4. Age 100 array to store ages of family members

Integer Input, Process, Output

5. State 100 array to store states of family members

String Input, Output

6. AverageAge 0 store average age of family members

Integer Process, Output

7. SumAge 0 store addition of ages of family members

Integer Process

8. Index 0 Loop variable Integer Process, Output

variables go before the formulas where they are used, not here at the end

Default values are inappropriate here

MAX_PERSONS looks to be a named constant. That is a good practice to use with arrays, but a variable is variable, and a constant is not. MAX_PERSONS is a constant and should be identified as such

The Module/Subprogram reference is a design detail and is not appropriate in the analysis

When you say that the default value for the arrays is 100, you must be talking about the size of the arrays. But the size is something much different from the default value

Average_Age and Sum_Age should be float, not integer

Need a string variable to hold the names of the Texans

Analysis

Page 6: Problem Analysis - f01. Web viewIn each iteration, ... Yet another warning for next week is that saying “lives in Texas” after each name ... an integer variable to control the

1) Is there a Problem description?

Yes

2) Does analysis include a description of the required output? A description of the necessary input? Is the process for obtaining the output from the input adequately described?

The output and the input are described. A process is not adequately developed

3) Have variable names and definitions been given, and are the names suitable and appropriate?

Yes, though there is no variable named to hold the names of the Texans found

4) Have all necessary formulas and example calculations been provided?

Adequate formulas not provided. Sample calculations do show how the process works

5) Will the analysis result in a design that efficiently and reliably meets the project requirements?

No

6) Documentation of the analysis

Variables are in the wrong location in the analysis. The output description contains inappropriate references to the program and to actions. No formulas provided

(-60)

Project Plan

Your project will be to analyze, design, and document a simple program that utilizes a good design process and incorporates sequential, selection and repetitive programming statements as well as function and subprogram calls and uses arrays. The specific problem you need to solve for the final project is:

Design a program that will allow a user to Input a list of your family members along with their age and state where they reside. Determine and print the average age of your family and print the names of anyone who lives in Texas.

Note: We do not use Modules anymore, call them Subprograms. Yes, Main Module will stay the same.

This assignment will be done in two parts 2 with 4 components of your submission including:

Part 1.

•Program Description- A detailed, clear description of the program you are building.

• Analysis- Demonstrates your thought process and steps used to analyze the problem. Be sure to include the required input and output and how you will obtain the required output from the given

Page 7: Problem Analysis - f01. Web viewIn each iteration, ... Yet another warning for next week is that saying “lives in Texas” after each name ... an integer variable to control the

input? Also, include your variable names and definitions. Be sure to describe the necessary formulas and sample calculations that might be needed. Talk about the functions you plan to use and how you will use arrays. Be sure to talk about the types of programming statements that will be used on why.

Additional details about the program you need to write:

1. Family sizes vary, however you should design to be able to enter at least 50 Family members.

2. Your program needs to determine how many family members were input. You cannot ask the user how many family members will be input

3. Your test cases should have at least 6 family members.

4. Be sure to separate some functionality into functions or subprogram. Having all functionality in the main module is not a good design.

5. Your analysis should consider how to indicate the family member entry is complete.

6. Carefully consider the best data type for each of your variables. (e.g. when to use Float versus Integers versus Strings)

Part 2

•Pseudocode •Provide pseudocode of your overall design that fulfills the requirements of the project

A. detailed pseudocode for each subprogram and function.

B. Add pseudocode comments with all major functionality and most minor functionality commented

C. write in C code (optional, but recommended)

D. Provide C code, compile and run it, using any online C compiler (e.g ideone.com, codetwist.com).

• Show test plan covering all major functionality and most minor functionality. Multiple Input and expected output provided for most subprogram. Remember you need at least 6 sets of input data (Test data) along with their expected output for testing your program.

•Your test data can be presented in the form of a table as follows (note: feel free to adapt to your design)

Example application test data:

Test Case # Input Expected Output

1 Fred, Age: 82, State: MD

Page 8: Problem Analysis - f01. Web viewIn each iteration, ... Yet another warning for next week is that saying “lives in Texas” after each name ... an integer variable to control the

Mary, Age:75, State: OH

Joe, Age: 45, State: TX

Julie, Age: 47, State: TX

Beth, Age: 9, State: TX

* Average Age: 51.6

Members who live in TX:

Joe

Julie

Beth

2 Your input data Your expected output

3 Your input data Your expected output

Your completed assignment should be saved as Word document and submitted no later than the due date. Your document should be neat, well-written with minimal grammatical and spelling errors. Your document should contain page numbers at the bottom of each page. Use single space line formatting.

Index\ Name AgeState

Page 9: Problem Analysis - f01. Web viewIn each iteration, ... Yet another warning for next week is that saying “lives in Texas” after each name ... an integer variable to control the

Array0 Jeff 61 MD1 Doris 53 VA2 John 55 TX3 Ros 91 VA4 Francis 91 TX5 *

Page 10: Problem Analysis - f01. Web viewIn each iteration, ... Yet another warning for next week is that saying “lives in Texas” after each name ... an integer variable to control the

HINTS FOR PROJECT

Variables

Need three arrays, a string array for the names, a string array for the states, and an integer array for the ages

Need to specify the size of the array, and that it is an array in the analysis

Need integer variable to hold the number of family members entered

Need float variable to sum the ages, and to hold the average age

Look below at the two ways to get the names of the Texans. Based on which you choose you need either

o a string scalar (a scalar is a variable that is not an array) that will hold the names of all of the Texans

o a string array to hold the names of the Texans, and an integer variable that will hold the number of Texans found. If you use this approach, need to specify the size of the array

an integer variable to control the for loops you will use, and to serve as the index of the arrays when calculating the average age and generating the variable with the names of the Texans

Formulas in the analysis

You will need 3 formulas

1. Loading the arrays, and counting the number of family members input

2. Use the age array and the number of family members to calculate the average age (see details below)

3. use the name and state arrays, and the number of family members to generate either a string variable with the names of all of the Texans, or an array of strings with the names of all of the Texans

Do not output the name of a Texan when found, place in a variable

Loading the arrays

Cannot ask the user how many family members will be loaded

Use a sentinel loop to input family members, with the sentinel value being based on the name. Typically, the sentinel value is a name of *

Need to count the number of family members input and return this value for use later

Do not sum the ages while inputting them. This will be different from HW3

Page 11: Problem Analysis - f01. Web viewIn each iteration, ... Yet another warning for next week is that saying “lives in Texas” after each name ... an integer variable to control the

The order of the inputs may be tricky. Before the loop, load the first name. Do not load the first state and age.

Enter the loop. In the loop, do the following in the order shown

Input the age and state

add to the count of family members

input the next name

The formula for loading the arrays uses the following variables

Name – string array names of family members. You need to specify array size

Age – integer array ages of family members. You need to specify array size

State – string array state in which family member resides. You need to specify array size

Fam_Size – integer number of family members input

Formula for loading arrays

Fam_Size = 0Input Name[Fam_Size]While Name[Fam_Size] != “*”

Input Age[Fam_Size]Input State [Fam_Size]Fam_Size = Fam_Size + 1Input Name[Fam_Size]

End While

Page 12: Problem Analysis - f01. Web viewIn each iteration, ... Yet another warning for next week is that saying “lives in Texas” after each name ... an integer variable to control the

When you do the sample calculation, a table very nicely shows what is going on. If I have three parallel arrays, named name, age, and state, and in the sample calculation I say the sample data is

Jeff, 61, MD, Doris, 53, VA, John, 55, TX, Ros, 91, VA, Francis, 91, TX, *

my sample calculation would show how the values were put in the arrays (showing the table at the end of each loop iteration, and at the end I would have

Index\Array Name Age State0 Jeff 61 MD1 Doris 53 VA2 John 55 TX3 Ros 91 VA4 Francis 91 TX5 *

Note how the rows are identified by the index, and the columns are headed by the array name

Calculating the averageUse a for loop with the age array and number of family members to calculate the sum, then divide the sum by the number of family members

Formula

Set sum = 0.0

For (i = 0; i < num_family; i + 1)

Set sum = sum + age [i]

End For

Set Average_Age = sum/ num_family

Design considerations

o Good application for a function

Page 13: Problem Analysis - f01. Web viewIn each iteration, ... Yet another warning for next week is that saying “lives in Texas” after each name ... an integer variable to control the

o parameters are the age array and num_family

o sum and i should be local variables

Finding the list of TexansLook through the state array looking for a match to either Texas or TX (or either). If a match is found, the element in the name array with the same index is the name of a Texan

Need to decide which was of two approaches to use

1) String scalar approacha scalar is a non-array variable. With this approach, each time a Texan is found the name is concatenated to the string variable. Need to initially set this variable to an empty string, and add the newline character after the name each time a new Texan is found.

In this approach, some of the variables are

Texans – string scalar containing the names of Texans

Family_Size – integer contains the number of family members input

i - integer variable controlling for loop and index of arrays

Formula for string scalar approach

Set Texans = “ “

For (i = 0; i < Family_Size; i + 1)

If State [i] == “Texas” Then

Set Texans = Texans + Name[i] +”\n”

End If

End For

when you do the sample data for this, state names input need to be spelled out, not abbreviations (e.g. its Texas, not TX). If you want to use abbreviations, change “Texas” to “TX”.

Page 14: Problem Analysis - f01. Web viewIn each iteration, ... Yet another warning for next week is that saying “lives in Texas” after each name ... an integer variable to control the

2) String array approachWith this approach, each time a Texan is found the name is added to a string array variable. Also need an integer variable holding the number of Texans found that is the index here for the array with the number of Texans.

In this approach, some of the variables are

Texans – string array containing the names of Texans. It should be the same size as Name and State

TexCount – integer contains the number of Texans found

Family_Size – integer contains the number of family members input

i - integer variable controlling for loop and index of arrays

Formula for array approach

Set TexCount = 0

For (i = 0; i < Family_Size; i + 1)

If State [i] == “Texas” Then

Set Texans [TexCount] = Name[i]

Set TexCount = TexCount + 1

End If

End For

when you do the sample data for this, state names input need to be spelled out, not abbreviations (e.g. its Texas, not TX). If you want to use abbreviations, change “Texas” to “TX”.

Pay close attention to the index value for name and state, and the index value for Texans.

Sample calculations

Page 15: Problem Analysis - f01. Web viewIn each iteration, ... Yet another warning for next week is that saying “lives in Texas” after each name ... an integer variable to control the

Give all of the formulas before you do any sample calculations. For example, do not show the arrays being loaded in a sample calculation before showing the formula for calculating the average age. After all 3 formulas are shown, give a set of sample data as it would be given to the program, in the order the program takes it, and with the sentinel value in the sample data. Show the arrays being loaded, then do the sample calculations being sure to sure what the index is whenever an array is used in a sample calculation.

Page 16: Problem Analysis - f01. Web viewIn each iteration, ... Yet another warning for next week is that saying “lives in Texas” after each name ... an integer variable to control the

Design Considerations

Which means these are issues for your pseudo code, and do not appear nor are discussed in the analysis.

• Cannot use modules without parameters and arguments

– Use subprograms and functions. All information needs to be passed with arguments/parameters

• Must use modular programming

– Cannot have all of code in Main

– Do not do processing in input module

– Do not do processing in output module

• Use for loops for calculating average, and finding Texans

• Pass arrays, and the number of elements with data in the arrayFor the function for the average age

• Parameters are Age array, and number of family members

• Local variables are the sum and the variable controlling the for loop

• Return value is the average

• Sum in this subprogram, not in Input subprogram

• Use a for loop. Variable controlling loop is index of arrayOutput subprogram

• Parameters are

– Average Age

– Either

• String variable with names of Texans OR

• String Array with names of Texans AND Number of Texans found

• Outputs Average Age

• Output String variable with Texans OR

• Uses a For loop to output contents of Texans array. Loop starts at 0 and goes to the Number of Texans found

• Do not say “lives in Texas” after name of each Texan

• Before loop say “The Following People Live in Texas”

• Then, one name per line, nothing else on the line

Page 17: Problem Analysis - f01. Web viewIn each iteration, ... Yet another warning for next week is that saying “lives in Texas” after each name ... an integer variable to control the

Structure of your program

/***************************************************

Program header comments including name of programmer and date finished

*****************************************************/

MainCall Fill_Arrays (argument list)Call Process_Sub (argument list)Call Output (argument list)

End ProgramNeed to give arguments in calls

// Header for subprogram

Subprogram Fill_Arrays (parameter list)

transfer formula for filling arrays. Add Set where needed. Add prompts for inputsEnd Fill_Arrays// Header for subprogram

Subprogram Process_Sub (parameter list)

Set Average_Age = Average_Calculator (argument list) Call Find_Texans (argument list)End Process_Sub// Header for function

Function Average_Calculator (parameter list) as return type

Declare sum and loop variable as local variables Transfer formula for calculating average ageEnd Average_Calculator// Header for subprogram

Subprogram Find_Texans (parameter list)

declare variable controlling for loop as a local variable transfer whichever of the 2 formulas wyou want to use

Page 18: Problem Analysis - f01. Web viewIn each iteration, ... Yet another warning for next week is that saying “lives in Texas” after each name ... an integer variable to control the

End Find_Texans// Header for subprogram

Subprogram Output (parameter list)

declare local variable to control for loop is needed output average age output list of TexansEnd OutputTest Data

You need to do at least three data sets. Each data set will need to be full and complete, with the name, age and state for at least 4 family members, and include the sentinel value

- One of the sets should have a mixture of Texans and non-Texans, at least 2 of each

- One set should not have any Texas residents

- One set should be all Texans