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
|
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
void greeting();
void getName(ifstream& fin, string& first, string& last);
void readScore(ifstream& fin, int& cscore1, int& cscore2, int& cscore3);
void reportNoScore();
double calculateAverage(int& cscore1, int& cscore2, int& cscore3);
char assignGrade(double& cAveScore);
void printData(string& first, string& last, double& gAveScore, char& cGrade, ofstream& out);
void farewell();
int main()
{
string fname = " ";
string lname = " ";
int score1 = 0;
int score2 = 0;
int score3 = 0;
char grade = ' ';
double aveScore = 0.0;
ifstream in;
in.open("A6Data.txt");
ofstream out;
out.open("Grade.txt");
greeting();
while (!in.eof())
{
getName(in, fname, lname);
readScore(in, score1, score2, score3);
aveScore = calculateAverage(score1, score2, score3);
grade = assignGrade(aveScore);
printData(fname, lname, aveScore, grade, out);
}
//printData(fname, lname, aveScore, grade, out);
farewell();
in.close();
out.close();
return 0;
}
void greeting()
{ cout << "Welcome this is a simple grade calculating program." << endl;
}
void getName(ifstream& fin, string& first, string& last)
{
fin >> first >> last;
//fin.ignore(10, '\n');
cout << first <<" " << last << " " ;
}
void readScore(ifstream& gin, int& cscore1, int& cscore2, int& cscore3)
{
//gin.ignore(20, ' ');
//gin.ignore(20, ' ');
gin >> cscore1 >> cscore2 >> cscore3;
cout << cscore1 << " " << cscore2 << " " << cscore3 << " ";
}
void reportNoScore()
{ cout << "This Person has no score please make sure there is a score";
}
double calculateAverage(int& cscore1, int& cscore2, int& cscore3)
{ double gAveScore;
gAveScore = (cscore1 + cscore2 + cscore3) / 3;
cout << gAveScore << " ";
return gAveScore;
}
char assignGrade(double& gAveScore)
{ char cGrade = ' ';
if (gAveScore >= 90)
{
cGrade = 'A';
}
else if (gAveScore >= 80)
{
cGrade = 'B';
}
else if (gAveScore >= 70)
{
cGrade = 'C';
}
else if(gAveScore >= 60)
{
cGrade = 'D';
}
else if((gAveScore >= 0) && (gAveScore < 60))
{
cGrade = 'F';
}
cout << cGrade << endl;
return cGrade;
}
void printData(string& first, string& last, double& gAveScore, char& cGrade, ofstream& out)
{
out << first << " " << last << " " << gAveScore << " " << cGrade << " " << endl;
}
void farewell()
{ cout << "Thank you for using this simple grade calculator :) " << endl;
}
|