I have a homework assignment that im not really sure how to approach as of right now, I've done some research but. I have not found really anything that would pertain to what I'm doing. Any help would be appreciated <3 . So far this is what I have:
/******************************************************************************
1.WRITE A PROGRAM THAT TAKES AT LEAST SIX PERSONS FROM A FILE, AND LISTS THEM IN
ORDER: (i) SSN ASCENDING, AND (ii) BMI DECREASING
2. INPUT AT LEAST SIX PERSONS FROM A FILE. Prompt the user to enter one SSN of
the given six. For that SSN, find the lowest and highest RBMI among the other
five. Report the person names and RBMI values.
3. Among all the persons, find the two persons having the least RBMI. Report
their names and the value of their RBMI.
*******************************************************************************/
#include <iostream>
#include <math.h>
#include <fstream>
using namespace std;
struct person
{ //define a struct
string pName;
float BMI; // 18.4
long SSN; // 10 digit
};
int main ()
{
string fLine;
int pcount = 0;
ifstream fRap;
fRap.open ("Rappers.txt");
while (!fRap.eof ())
{
getline (fRap, fLine);
//myFavMovieStar[pcount].pname = fLine;
getline (fRap, fLine);
//myFavMovieStar[pcount].pname = fLine;
getline (fRap, fLine);
//myFavMovieStar[pcount].pname = fLine;
pcount++;
}
fRap.close ();
cout << "pcount is: " << pcount << endl;
person myFavRapper[pcount];
fRap.open ("Rappers.txt");
for (int i = 0; i < pcount; i++)
{
getline (fRap, fLine);
myFavRapper[i].pName = fLine;
getline (fRap, fLine);
myFavRapper[i].SSN = stol (fLine);
getline (fRap, fLine);
myFavRapper[i].BMI = stof (fLine);
}
fRap.close ();
cout << "Done reading this file." << endl;
for (int i = 0; i < pcount; i++)
{
cout << myFavRapper[i].pName << " | " << myFavRapper[i].
SSN << " | " << myFavRapper[i].BMI << endl;
}
cout << "" << endl;
cout << "SSN's Ascending: " << endl;
cout << "" << endl;
cout << "BMI's Decreasing: " << endl;
}
Here is the contents of the text file:
Jahseh Onfroy
123456789
19.4
Aristos Petrou
345678912
25.1
Gustav Ahr
234567891
21.5
Scott Arceneaux
101110111
22.4
Jazz Butler
134243332
22.2
Symere Woods
678912345
25.7