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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <vector>
#include <iterator>
#include "studentType.h"
using namespace std;
void getStudentData(ifstream& infile,
vector<studentType> &studentList);
void printGradeReports(ofstream& outfile,
vector<studentType> studentList,
double tuitionRate);
int main()
{
vector<studentType> studentList;
double tuitionRate;
ifstream infile;
ofstream outfile;
infile.open("c:\\Martin\\MalikDownloads\\Chapter 4 Source Code\\GradeReport2018\\ch4_GradeData.txt");
if(!infile)
{
cerr<<"Input file does not exist. "
<<"Program terminates."<<endl;
return 1;
}
outfile.open("c:\\Martin\\MalikDownloads\\Chapter 4 Source Code\\GradeReport2018\\sDataOut.txt");
infile>>tuitionRate; //get the tuition rate
getStudentData(infile, studentList);
printGradeReports(outfile, studentList, tuitionRate);
infile.close();
outfile.close();
return 0;
}
void getStudentData(ifstream& infile,
vector<studentType> &studentList)
{
//Local variable
string fName; //variable to store the first name
string lName; //variable to store the last name
int ID; //variable to store the student ID
int noOfCourses; //variable to store the number of courses
char isPaid; //variable to store Y/N, that is,
//is tuition paid
bool isTuitionPaid; //variable to store true/false
string cName; //variable to store the course name
string cNo; //variable to store the course number
int credits; //variable to store the course credit hours
char grade; //variable to store the course grade
int i; //loop control variable
vector<courseType> courses; //vector of objects to store course
//information
courseType cTemp;
studentType sTemp;
infile>>fName; //Step 1
while(infile)
{
infile>>lName>>ID>>isPaid; //Step 1
if(isPaid == 'Y') //Step 2
isTuitionPaid = true;
else
isTuitionPaid = false;
infile>>noOfCourses; //Step 3
courses.clear(); //Step 4
for(i = 0; i < noOfCourses; i++) //Step 5
{
infile>>cName>>cNo>>credits>>grade; //Step 5.a
cTemp.setCourseInfo(cName, cNo,
grade, credits); //Step 5.b
courses.push_back(cTemp); //Step 5.c
}
sTemp.setInfo(fName, lName, ID, isTuitionPaid,
courses); //Step 6
studentList.push_back(sTemp); //Step 7
infile>>fName; //Step 1
}//end while
}
void printGradeReports(ofstream& outfile,
vector<studentType> studentList,
double tuitionRate)
{
unsigned int count;
for(count = 0; count < studentList.size(); count++)
studentList[count].print(outfile, tuitionRate);
}
|