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 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
|
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <sstream>
using namespace std;
class Person
{
public:
string FirstName;
string LastName;
char comment[256];
double totalgrade;
double hwpoints,hwpointsmax;
double exampoints,exampointsmax;
double prgmpoints,prgmpointsmax;
double percentage;
string grade;
string name;
};
double percentage(double grade1,double grade2)
{
double percent = grade1 / grade2 * 100;
return percent;
}
string grade(double percent)
{
string grade;
if(percent >= 98)
{
grade = "A+";
}
if(percent >= 93 && percent <= 97)
{
grade = "A";
}
if(percent >= 90 && percent <= 92)
{
grade = "A-";
}
if(percent >= 88 && percent <= 89)
{
grade = "B+";
}
if(percent >= 83 && percent <= 87)
{
grade = "B";
}
if(percent >= 80 && percent <= 82)
{
grade = "B-";
}
if(percent >= 78 && percent <= 79)
{
grade = "C+";
}
if(percent >= 73 && percent <= 77)
{
grade = "C";
}
if(percent >= 70 && percent <= 72)
{
grade = "C-";
}
if(percent >= 68 && percent <= 69)
{
grade = "D+";
}
if(percent >= 63 && percent <= 67)
{
grade = "D";
}
if(percent >= 60 && percent <= 62)
{
grade = "D-";
}
if(percent <= 50)
{
grade = "F";
}
return grade;
}
double finalscore(double g1,double g2,double g3,double g4,double g5,double g6)
{
double t1 = g1 + g3 + g5;
double t2 = g2 + g4 + g6;
double result = t1 / t2 * 100;
return result;
}
Person getPerson()
{
Person person;
ofstream data;
cout << "\nEnter another student\n"
<< "First Name: ";
cin >> person.FirstName;
cout << "Last Name: ";
data.open("Grades.txt", fstream::in|fstream::app);
cin >> person.LastName;
person.name = person.FirstName + " " + person.LastName;
data << "Name: \t\t\t\t" << person.name;
data << "\n";
data.close();
cout << "Homework Points: ";
data.open("Grades.txt", fstream::in|fstream::app);
cin >> person.hwpoints;
data << "Homework Points: \t\t\t" << person.hwpoints;
data << "\n";
data.close();
cout << "Max Homework Points: ";
data.open("Grades.txt", fstream::in|fstream::app);
cin >> person.hwpointsmax;
data << "Max Homework Points: \t\t" << person.hwpointsmax;
data << "\n";
data.close();
person.percentage = percentage(person.hwpoints,person.hwpointsmax);
person.grade = grade(person.percentage);
data.open("Grades.txt", fstream::in|fstream::app);
data << "Homework Percentage and Grade: \t" << person.percentage << "%\t" << person.grade << "\n";
data.close();
cout << "Exam Points: ";
data.open("Grades.txt", fstream::in|fstream::app);
cin >> person.exampoints;
data << "Exam Points: \t\t\t" << person.exampoints;
data << "\n";
data.close();
cout << "Max Exam Points: ";
data.open("Grades.txt", fstream::in|fstream::app);
cin >> person.exampointsmax;
data << "Max Exam Points: \t\t\t" << person.exampointsmax;
data << "\n";
data.close();
person.percentage = percentage(person.exampoints,person.exampointsmax);
person.grade = grade(person.percentage);
data.open("Grades.txt", fstream::in|fstream::app);
data << "Exam Percentage and Grade: \t" << person.percentage << "%\t" << person.grade << "\n";
data.close();
cout << "Programming Points: ";
data.open("Grades.txt", fstream::in|fstream::app);
cin >> person.prgmpoints;
data << "Programming Points: \t\t" << person.prgmpoints;
data << "\n";
data.close();
cout << "Max Programming Points: ";
data.open("Grades.txt", fstream::in|fstream::app);
cin >> person.prgmpointsmax;
data << "Max Programming Points: \t\t" << person.prgmpointsmax;
data << "\n";
data.close();
person.percentage = percentage(person.prgmpoints,person.prgmpointsmax);
person.grade = grade(person.percentage);
data.open("Grades.txt", fstream::in|fstream::app);
data << "Programming Percentage and Grade: \t" << person.percentage << "%\t" << person.grade << "\n";
data.close();
person.totalgrade = finalscore(person.hwpoints,person.hwpointsmax,person.exampoints,person.exampointsmax,person.prgmpoints,person.prgmpointsmax);
person.grade = grade(person.totalgrade);
data.open("Grades.txt", fstream::in|fstream::app);
data << "Final Grade: \t\t\t" << person.totalgrade << "%\t" << person.grade << "\n";
data.close();
cin.getline(person.comment,256);
cout << "Please enter your comment: ";
data.open("Grades.txt", fstream::in|fstream::app);
cin.getline(person.comment,256);
data << "Comment: " << person.comment;
data << "\n ---------------------------------------------------------------------------------------------------------------------------\n" << endl;
data.close();
return person;
}
int getPeople(Person people[], int nMaxSize)
{
int index;
for(index = 0; index < nMaxSize; index++)
{
char cAnswer;
cout << "Enter another student? (Y or N): ";
cin >> cAnswer;
if(cAnswer != 'Y' && cAnswer != 'y')
{
break;
}
people[index] = getPerson();
}
return index;
}
void displayPerson(Person person)
{
cout << "Name:\t\t\t\t" << person.FirstName << " " << person.LastName << endl;
cout << "Homework Points / MAX:\t\t" << person.hwpoints << "/" << person.hwpointsmax << endl;
cout << "Exam Points / MAX:\t\t" << person.exampoints << "/" << person.exampointsmax << endl;
cout << "Programming Points / MAX:\t" << person.prgmpoints << "/" << person.prgmpointsmax << endl;
cout << "Final Grade:\t\t\t" << person.totalgrade << "%" << endl << endl;
cout << "Your comment: " << person.comment << endl;
cout << "-----------------------------------------------------------\n" << endl;
}
void displayPeople(Person people[], int nCount)
{
for(int index = 0;index < nCount; index++)
{
displayPerson(people[index]);
}
}
int main(int nNumberofArgs,char* pszArgs[])
{
Person people[256];
cout << "Hello!, this program stores student scores." << endl;
cout << "It will store it temporarily in this console while storing it in 'Grades.txt'." << endl;
cout << "Letter grades and percentages are stored in the .txt file." << endl;
int count = getPeople(people, 256);
cout << endl << "Here is what your entered: " << endl << endl;
displayPeople(people,count);
system("PAUSE");
return 0;
}
|