Answered step by step
Verified Expert Solution
Question
1 Approved Answer
You have the text file imp_h21.txt on you. The Tab_Pers.cpp program is used to read this file, fill in the pers table with objects of
You have the text file imp_h21.txt on you. The Tab_Pers.cpp program is used to read this file, fill in the pers table with objects of the Person class and to transmit by reference the exact number of people read. Adapt this program in C++ allowing also 1. display people read using appropriate function (sli 2. to determine and display the information of a person of the greatest height; 3. determine and display all information a) of a woman with the smallest height b) a man of the lightest weight 4. to calculate and display a) the average weight of women b) the average height of men - 5 This is the imp h21.text F 2187 5 6 180 M 4148 5 11 185 M 2233 6 1 188 4433 4 10 127 2108 5 11 165 F 4100 5 119 F 2176 6 2 187 5423 9 147 M 4169 5 6 123 F 4177 5 9 138 M 2879 2 191 F 5477 5 11 147 M 4869 3 162 F 4354 5 6 169 M 2235 6 2 189 M 5444 5 10 151 F 4198 9 125 F 5678 6 7 190 F 1357 5 6 155 F 3498 4 11 135 This is the Tab_Pers.cpp. 40 1 #include 2 #include 3 #include 4 4 #include 5 6 using namespace std; // librairie standard 7 8 8 class Person 10 private : 11 char sexe i 12 float height, weight ; 13 int number; 14 15 public : 16 17 Person(char sex, int num, float heigh, float weigh) 18 { 19 sexe = sex; 20 number = num; 21 height = heigh; 22 weight = weigh; 23 } 24 25 // constructeur without settings 26 Person() 27 { 28 29 } 30 31 int getNumber(); 32 33 }; 34 35 36 int Person::getNumber() 37 [ 38 return number: 39] 40 41 42 void readFill(const char name ToRead[], Person pers[], int & n) 43 { 44 const float FOOT_IN_METER = 0.3848, 45 LBS_IN_KG = 0.454; 46 int number, nbFoot, nbInch, nbLbs; 47 float height, weight; 48 char sexe; 49 50 ifstream toRead (nameToRead, ios::in); // to localise and open the files ; 51 52 n = 0; 53 while (toRead >> sexe >> number >> mbFuut >> nb Inch >> nbLbs) 54 { 55 height = (nbFoot + nbInch /12.0) * FOOT_IN_METER; 56 weight = nbLbs * LBS_IN_KG; 57 pers[n++] = Person (sexe, number, height, weight); 58 } 59 toRead.close(); 60 61 } 62 63 64 int main() { { 65 66 const int MAX_PERS = 25 ; 67 Person pers[MAX_PERS); 68 int nbPers; 69 70 readFill("imp_h21-1.txt", pers, nbPers); 71 72 cout
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