123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
#include <iostream> #include <string> #include <fstream> #include <cmath> #include <iomanip> using namespace std; void main() { cout << "Please enter the filename that wish to open: "; string filename; cin >> filename; ifstream infile; infile.open(filename); string fname, lname; float score; int i; string myarray[6]; float myarray1[6]; for(i=0; i<7; i++); { infile >> fname >> lname >> score; myarray[i] = fname + " " + lname; myarray1[i] = score; } int option; while(option < 5) { cout << "Please choose an option: " << endl; cout << "1 Please find the smallest: " << endl; cout << "2 Please find the largest: " << endl; cout << "3 Please find the total: " << endl; cout << "4 Please find the avarage: " << endl; cout << "5 Quit" << endl; cin >> option; if(option==1) { float smallest = myarray1[0]; int smallest_index; for(int i=0; i<6; i++) { if(myarray1[i] < smallest) { smallest = myarray1[i]; smallest_index; } } cout << myarray[smallest_index] << " "; cout << myarray1[smallest_index] << endl; } else if (option ==2) { float largest = myarray1[0]; int largest_index; for(int i2=0; i2<6; i2++) { if (myarray1[i2] > largest) { largest = myarray1[i2]; largest_index = i2; } } cout << myarray[largest_index] << " "; cout << myarray1[largest_index] << endl; } else if(option==3) { float total = 0; for(i=0; i<6; i++) { total = myarray1[i] + total; } cout << "The total is: " << total << endl; } else if (option==4) { float total, avg; total = 0; for(i=0; i<6; i++) { total = myarray1[i] + total; } avg = total / 6; cout << "The avarage is: " << avg << endl; } else if(option>=5) { cout << "Have a nice day!" << endl; } } char ch; cin >> ch; }