1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
#include "StudentType.h"
#include <iostream>
#include <string>
#include <fstream>
#include <climits>
using namespace std;
const int MAX_STUDENTS = 20;
void openFile(ifstream& fin);
void getData(int& actNumstu, ifstream& fin, StudentType student[]);
void computeAvg(int actNumstu, StudentType student[]);
void swapData(int actNumstu, StudentType student[]);
void print(int actNumstu, StudentType student[]);
int main () {
StudentType student[MAX_STUDENTS];
int actNumstu;
ifstream fin;
getData(actNumstu, fin, student);
computeAvg(actNumstu, student);
swapData (actNumstu, student);
print(actNumstu, student);
return 0;
}
void openFile(ifstream& fin) {
cout << "Enter a filename: ";
string filename;
cin >> filename;
cout << endl;
fin.open(filename.c_str());
while (!fin) {
cout << "Please enter a VALID file name:";
cin >> filename;
fin.open(filename.c_str());
}
}
void getData (int& actNumstu, ifstream fin, StudentType student[]) {
openFile(fin);
actNumstu = 0;
while (getline (fin, student[actNumstu].name) && actNumstu < MAX_STUDENTS
&& !student[actNumstu].name.empty()) {
student[actNumstu].setName(student.reformat(name));
for (int j = 0; j < NUM_GRADES; j++) {
fin >> student[actNumstu].grades[j];
student[actNumstu].setGrade(student[actNumstu].grades[j], j);
}
++actNumstu;
fin.ignore(INT_MAX, '\n' );
}
}
|