Ok so basically this is what I'm supposed to do:
Write a program that will display and gather info on seven patients.
Use a file already given that contains the last name, first name and age for each person.
Read into arrays and initialize blood pressure to 0 and high pressure to false.
Print out the full name and age of each patient in alphabetical order by last name.
Next enter the blood pressure numbers and set the high pressure flag for each person. Assume the high pressure flag will be true if the systolic value is greater than 159.
The print out the full name, age and blood pressure for each patient. Finally print out just the full names of all the patients with high blood pressure.
I know it's alot but I figured I might as well put it all in. Heres what I have so far and keep in mind right now I'm just trying to get the general idea of the program down not all of the specific ways to print info out.
Code:#include<iostream> #include<fstream> using namespace std; struct pressure { int systolic; int diastolic; }; struct patient { string lastName; string firstName; int age; pressure bloodPressure; bool highPressure; }; void greeting(); //Displays greeting. void sortAlpha(patient ln[], int x); //Sorts the names by last name in alphabetical order. ifstream fin; int main() { const int NUMBER = 7; patient patients[NUMBER]; bool sorted; greeting(); fin.open("F:\\C++\\Disk\\DataDisk\\PATIENTS.dat"); if(fin.fail()) { cout << "Error opening file for input!\n"; system("pause"); exit(1); } for(int i=0; i < NUMBER; i++) fin >> patients[i].lastName >> patients[i].firstName >> patients[i].age; sortAlpha(patients, NUMBER); for(int i=0; i <NUMBER; i++) { cout << "The patients name is: " << patients[i].lastName << ", " << patients[i].firstName << "\nAge: " << patients[i].age << endl; patients[i].highPressure = false; patients[i].bloodPressure.diastolic = 0; patients[i].bloodPressure.systolic = 0; } for(int i=0; i < NUMBER; i++) { cout << "Please enter the blood pressure numbers (systolic then " << "diastolic) for \n" << patients[i].firstName << " " << patients[i].lastName << ": "; cin >> patients[i].bloodPressure.systolic >> patients[i].bloodPressure.diastolic; if(patients[i].bloodPressure.systolic > 159) patients[i].highPressure = true; cout << patients[i].firstName << " " << patients[i].lastName << " who " << "is " << patients[i].age << " years old, has a blood pressure " << "of " << patients[i].bloodPressure.systolic << "/" << patients[i].bloodPressure.diastolic << endl; } cout << "The patients with high blood pressure are: \n"; for(int i=0; i < NUMBER; i++) { if(patients[i].highPressure == true) cout << patients[i].firstName << " " << patients[i].lastName << endl; } fin.close(); system("pause"); return 0; } void greeting() { cout << "This program will display and gather info for seven patients.\n\n"; } void sortAlpha(patient ln[], int x) { bool sorted; do { sorted = true; for(int i = 0; i < x; i++) if(patient.ln[i] > patient.ln[i + 1]) //parse error here saying "parse error before '.' token" { swap(patient.ln[i], patient.ln[i + 1]); //and another one here saying the same thing sorted = false; } } while(!sorted); }
As you can probably see I'm having issues with the alphabetically sorting things. Please help, any suggestions at all would be greatly appreciated. I just fixed stuff so now this is the newer version of the program. Now all I need is the sort function to work... please help! I can't seem to get it to work no matter what I try...
Only two errors now as parse errors. I commented where they are in the program.