Question
A secondary school stores the name of the students, weight of the students in kilogram and the height of the students in meter in a
A secondary school stores the name of the students, weight of the students in kilogram and the height of the students in meter in a file named studentData. txt. The weight and the height information is used to find the BMI (Body Mass Index) measurement to be recorded in the students' yearly report cards. Figure 1 shows the sample content of the input file.
studentData.txt
aziz ahmad.,50,1.82 syazana rosli,55,1.3 darwina daud,60,1.5 faiz aiman, 65,1. 6 zara zainuddin,58,1.4 muhammad muiz,52,1.9 nabila saari, 47,1.4
The BMI is calculated as: BMI = weight in kg / height in meter X height in meter.
Table 4 shows the BMI measurement and the BMI categories.
BMI(kh/m^2 category 0-18.5 underweight >18.5 and <=23 normal >23 and <=25 overweight- at risk >25 and <=30 overweighht- moderately obese more than 30 overweight - severely obese
the student data should be stored in a struct variable of type Student which has 3 components: name of type string, weight of type double and height of type double.
a) write a complete c++ statements to do the following tasks: (i) declare an array of type student of size 100 (ii) write statement to read and write to file I/O (iii) read all data from file studentData.txt (iv) write the output into a file name bmiReport.txt with the sample format as shown in figure 2.
bmiReport.txt
The BMI Report Name Weight(kg) Height(metres) BMI Categories aziz ahmad 50.00 1.82 12.09 Underweight syazana rosli 55.00 1.30 32.54 Overweight- Severely obese darwina daud 60.00 1.50 26.67 overweighht- moderately obese faiz aiman 65.00 1.60 25.39 overweighht- moderately obese zara zainuddin 58.00 1.40 29.59 overweighht- moderately obese muhammad muiz 52.00 1.90 14.40 Underweight nabila saari 47.00 1.40 23.98 Overweight- At risk
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started