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 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
|
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using std::cout;
using namespace std;
struct StudentRecord
{
char Answer[10];
string name;
int ID;
struct Answers;
double score;
double average;
char letter_grade;
};
//function prototypes
void getInfo(int, string, string, char[10]);
void enterKey(char key[10]);
void calculateScore(char[10], char[10], int, double, char);
void sortName(StudentRecord, int);
void displayHeading();
void displayResults(int, string, string, char[10], int, double, char);
int main()
{
//user defined variables
int ID = 0;
string last;
string first;
int numStudents = 0;
char answers[10];
char key[10];
char letter_grade = 'A';
int score = 0;
double average = 0.0;
StudentRecord *stu;
stu = new StudentRecord[numStudents];
getInfo(ID, last, first, answers);
enterKey(key);
calculateScore(answers, key, score, average, letter_grade);
displayHeading();
displayResults(ID, last, first, answers, score, average, letter_grade);
sortName(stu, numStudents);
}
void getInfo(int ID, string last, string first, char answers[10])
{
ifstream inFile("student.txt"); //open file to read from
while (inFile >> ID >> last >> first >> answers[0] >> answers[1] >> answers[2] >> answers[3] >> answers[4] >> answers[5] >> answers[6] >> answers[7] >> answers[8] >> answers[9]);
{
cout << ID << ", " << last << " " << first << ", " << answers[0] << answers[1] << answers[2] << answers[3] << answers[4] << answers[5] << answers[6] << answers[7] << answers[8] << answers[9] << endl;
}
}
//void enterKey(char key[])
{
cout << "Please enter the answer key." << endl;
for (int index = 0; index < 10; index++)
{
cout << "Answer " << index + 1 << ": ";
cin >> key[index];
}
}
void calculateScore(StudentRecord * stu, char answers[10], char key[10], int score, double average, char letter_grade)
{
int points1 = 0;
int points2 = 0;
int points3 = 0;
int points4 = 0;
int points5 = 0;
int points6 = 0;
int points7 = 0;
int points8 = 0;
int points9 = 0;
int points10 = 0;
//gather's the number of points earned
for (int index = 0; index < 10; index++)
{
if (stu[index].Answer[0] == key[0])
points1 = 5;
else
points1 = 0;
if (stu[index].Answer[1] == key[1])
points2 = 5;
else
points2 = 0;
if (stu[index].Answer[2] == key[2])
points3 = 5;
else
points3 = 0;
if (stu[index].Answer[3] == key[3])
points4 = 5;
else
points4 = 0;
if (stu[index].Answer[4] == key[4])
points5 = 5;
else
points5 = 0;
if (stu[index].Answer[5] == key[5])
points6 = 5;
else
points6 = 0;
if (stu[index].Answer[6] == key[6])
points7 = 5;
else
points7 = 0;
if (stu[index].Answer[7] == key[7])
points8 = 5;
else
points8 = 0;
if (stu[index].Answer[8] == key[8])
points9 = 5;
else
points9 = 0;
if (stu[index].Answer[9] == key[9])
points10 = 5;
else
points10 = 0;
//adds all of the scored points together to get raw total
stu[index].score = points1 + points2 + points3 + points4 + points5 + points6 + points7 + points8 + points9 + points10;
//
stu[index].average = stu[index].score * 2;
//determines the students average letter grade
if ((stu[index].average >= 90) && (stu[index].average <= 100))
stu[index].letter_grade = 'A';
else if ((stu[index].average >= 80) && (stu[index].average <= 89))
stu[index].letter_grade = 'B';
else if ((stu[index].average >= 70) && (stu[index].average <= 79))
stu[index].letter_grade = 'C';
else if ((stu[index].average >= 60) && (stu[index].average <= 69))
stu[index].letter_grade = 'D';
else if ((stu[index].average >= 0) && (stu[index].average <= 59))
stu[index].letter_grade = 'F';
}
}
void sortName(StudentRecord *stu, int numStudents)
{
for (int i = 0; i < numStudents; i++)
{
for (int j = 0; j < numStudents - 1 - i; j++)
{
if (stu[j].name > stu[j + 1].name)
swap(stu[j], stu[j + 1]);
}
}
}
void displayHeading()
{
cout << setw(10) << "Student ID";
cout << setw(15) << "Student Name";
cout << setw(10) << "Answers";
cout << setw(10) << "Total points";
cout << setw(10) << "Average";
cout << setw(15) << "Letter Grade";
cout << endl;
}
void displayResults(StudentRecord *stu, int ID, string last, string first, char answers[10], int score, double average, char letter_grade)
{
int index = 0;
int x = 0;
for (int x = 0; x < 10; x++)
{
//Displays all students
cout << setw(10) << stu[x].ID;
cout << left << setw(15) << stu[x].name;
for (int y = 0; y<5; y++)
{
cout << setw(2) << stu[x].Answer[y] << "";
}
cout << setw(10) << stu[x].score;
cout << setw(10) << stu[x].average;
cout << setw(15) << stu[x].letter_grade;
cout << endl;
}
//Displays students admitted into the program
for(int index = 0; index < 10; index++)
{
if (stu[index].letter_grade == 'A' || stu[index].letter_grade == 'B')
{
//Creates table heading
cout << "Students Admitted to the Graduate Program" << endl;
displayHeading();
//Displays student info
cout << setw(10) << stu[index].ID;
cout << left << setw(15) << stu[index].name;
for (int y = 0; y < 10; y++)
{
cout << setw(2) << stu[index].Answer[y] << "";
}
cout << setw(10) << stu[index].score;
cout << setw(10) << stu[index].average;
cout << setw(10) << stu[index].letter_grade;
cout << endl;
}
}
cout << endl << endl;
//Displays student with conditional admission
for(int index = 0; index < 10; index++)
{
if (stu[index].letter_grade == 'C')
{
//Creates table heading
cout << "Students with Conditional Admission:" << endl;
displayHeading();
//Displays student info
cout << setw(10) << stu[index].ID;
cout << left << setw(15) << stu[index].name;
for (int y = 0; y < 10; y++)
{
cout << setw(2) << stu[index].Answer[y] << "";
}
cout << setw(10) << stu[index].score;
cout << setw(10) << stu[index].average;
cout << setw(10) << stu[index].letter_grade;
cout << endl;
}
}
//Displays students that are not allowed
cout << endl << endl;
for(int index = 0; index < 10; index++)
{
if (stu[index].letter_grade == 'F')
{
//Creates table heading
cout << "Students Not Allowed Admission: " << endl;
displayHeading();
//Displays student info
cout << setw(10) << stu[index].ID;
cout << left << setw(15) << stu[index].name;
for (int y = 0; y < 10; y++)
{
cout << setw(2) << stu[index].Answer[y] << "";
}
cout << setw(10) << stu[index].score;
cout << setw(10) << stu[index].average;
cout << setw(10) << stu[index].letter_grade;
cout << endl;
}
}
}
|