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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
/*---------------------------------------------------
Name: Manuel Santana
Student ID: G29167706
COP 1334 - Introduction to C++
Summer 2013 - TR 6:00PM - 8:15PM
Assignment # 8
Plagiarism Statement
I certify that this assignment is my own work and that I
have not copied in part or whole or otherwise plagiarised
the work of other students and/or persons.
----------------------------------------------------------*/
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <vector>
using namespace std;
enum Status {PASSING, FAILING};
struct Student
{
string name;
double grade1, grade2, grade3, average;
Status status;
};
string getInputFileName();
string getOutputFileName();
void readStudents(vector<Student> &students, string );
void writeStudents(vector<Student> &students, string );
void copystudents(Student & s1, Student s2);
void sortstudents(vector<Student> &students);
int main()
{
vector<Student> students;
string inputFileName, outputFileName;
inputFileName = getInputFileName();
outputFileName = getOutputFileName();
readStudents(students, inputFileName);
writeStudents(students, outputFileName);
system("pause");
return 0;
}
string getInputFileName()
{
string filename;
cout << "enter the input file name: ";
cin >> filename;
return(filename);
}
string getOutputFileName()
{
string filename;
cout << "enter the output file name: ";
cin >> filename;
return(filename);
}
void readStudents(vector<Student> &students, string inputFileName)
{
Student student;
fstream infile(inputFileName, ios::in);
while (infile >> student.name)
{
infile >> student.grade1;
infile >> student.grade2;
infile >> student.grade3;
student.average = (student.grade1 + student.grade2 + student.grade3 )/ 3;
students.push_back(student);
if (student.average < 70 )
student.status = FAILING;
else
student.status = PASSING;
}
}
void writeStudents(vector<Student> &students, string outputFileName)
{
fstream outfile;
outfile.open(outputFileName, ios::out);
outfile << " Name\t " << " \tGrade1 " << " \tGrade2 "
<< " \tGrade3 " << " \tAvarage " << " \tStatus" << endl;
for(unsigned count = 0; count < students.size(); count++)
{
outfile << fixed << setprecision(0) << students[count].name << setw(15)
<< students[count].grade1
<< setw(18) << students[count].grade2
<< setw(18) << students[count].grade3 << setw(15)
<< students[count].average << setw(10) ;
if (students[count].average < 70 == FAILING)
outfile << " \tFailing" << endl;
else
outfile << " \tPassing" << endl;
}
outfile.close();
}
void copystudents(Student & s1, Student s2)
{
s1.name = s2.name;
s1.grade1 = s2.grade1;
s1.grade2 = s2.grade2;
s1.grade3 = s2.grade3;
s1.average = s2.average;
s1.status = s2.status;
}
void sortstudents(vector<Student> students)
{
bool swap;
Student temp;
do
{
swap = false;
for(int count = 0; count < students.size(); count++)
{
if (students[count].average < students[count + 1].average)
{
copystudents(temp, students[count]);
copystudents(students[count], students[count + 1]);
copystudents(students[count + 1], temp);
} swap = true;
}
}while(swap);
}]
|