Question: C++ This assignment will require processing a 2 dimensional array. Review section (8th Ed - Section 7-9 starting on page 422 - 9th Ed -
C++
This assignment will require processing a 2 dimensional array.
Review section (8th Ed - Section 7-9 starting on page 422 - 9th Ed - Section 7-8 pg 424). I would recommend printing the attached document.
Using the attached document, build a program that will prompt for a gender and age and height in inches. The age range should be 0-18.
Please disregard the ages 1/4, 1/2, 3/4, 1&1/2, and 2&1/2. Start with Birth (0) and then 1 - 18.
Once you have obtained their growth percentage for the age, display the retrieved growth percentage and calculate and display the expected height in inches and feet+inches.
Allow this input to be entered again unless I choose to exit.
Also see the Assignment 3 Thoughts section below.
Most of the issues around Assignment 3 are related to the defining the array. 2D arrays can be thought of as spreadsheets, with a row and column. General solutions below are :
1. Create a 2 Dimensional Array with 19 rows and 2 columns.
float growthChart[19][2] = { { 28.6, 30.9 }, { 42.2, 44.7 }, { 49.5, 52.8 }, .....
or
float growthChart[19][2];
growthChart[0][0] = 28.6; growthChart[0][1] = 30.9; growthChart[1][0] = 42.2;
The statement "float growthChart[19][2]" implies 19 rows, with 2 columns to choose from. Age is the implied row and gender can be column 0 or 1. Thus growthChart[age 0-18 ][0 or 1 for gender ] is a direct way to get to the data and does not require a loop. 2. Create a 2 Dimensional Array with 19 rows and 3 columns, age -boy% - girl%. float growthChart[19][3] = { { 0, 28.6, 30.9 }, { 1, 42.2, 44.7 }, { 2, 49.5, 52.8 }, ..... or float growthChart[19][3];
growthChart[0][0] = 0; // age
growthChart[0][1] = 28.6;
growthChart[0][2] = 30.9;
Age is column 0, and with boy % for column 1 and girl % for column 2. You could search this array with a for loop.
If growthChart[row][0] == age then percentage=growthChart[age - which is also the row][ gender 1 or 2] Float or Double will handle the decimal place so "int" is not correct. Remember double can "double" the amount of memory used compared to float.
Both option 1 and 2 approaches are valid.
Option 1 appears simpler and takes advantage of the age and row always being the same index. However, this approach would completely fail if the data that was specified to be ignored needed to be added back in - (such as 3/4 or 0.75 age). By knowing the age is the row, there is no need to do a "for loop" to search.
Option 2 allows some flexibility and also clarity to this by explicitly defining the age values. Option 2 allows a serial search (for loop) if desired.
When calculating for number of feet, you can simply calculate into an int variable. Any excess is truncated by default since an int by definition contains only whole numbers.
To determine inches, consider the modulus operator - %. Your text book can direct you - it is listed in the back index under the word "Operators".
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
