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
|
void insertionSort_byInteger(int arrtosort[], int size);
void insertionSort_ByString(string arrtosort[], int size);
const int MAXSTUDENTS = 30;
const char FILENAME[40] = "TestScores2.txt";
const char NEWFILENAME[40] = "TestScores_Grades2.txt";
const char SORTEDIDS[40] = "SortedIDs.txt";
int main()
{
string fname[MAXSTUDENTS];
string lname[MAXSTUDENTS];
string grades[MAXSTUDENTS];
int ids[MAXSTUDENTS], scores[MAXSTUDENTS], sortids[MAXSTUDENTS];
ifstream inFile;
int id, idx, score, score2, s = 0, avg, totalgrade = 0, numofstudents = 0;
int num, target, p = 0, percent;
string grade, grade2, firstName, lastName, fnames, lnames, targetGrade, targetLetter;
inFile.open(FILENAME);
//read file and get average
while (s < MAXSTUDENTS)
{
inFile >> id;
inFile >> firstName;
inFile >> lastName;
inFile >> score;
if (score >= 0 && score <= 10)
{
totalgrade = totalgrade + score;
numofstudents++;
}
s = s + 1;
}
avg = totalgrade/numofstudents;
//cout << "The average score is: " << avg << endl << endl;
inFile.clear();
inFile.seekg(0);
//read file, generate letter grade and create new file
ofstream outFile1;
outFile1.open(NEWFILENAME);
for(idx = 0; idx < MAXSTUDENTS; idx++)
{
inFile >> id >> firstName >> lastName >> score;
if ( score != -1 )
{
if (score == avg || score == avg +1)
grade = "B";
else if (score == avg + 2 || score == avg + 3)
grade = "A-";
else if (score >= avg +4 || score == 10 )
grade = "A";
else if (score == avg - 1)
grade = "C";
else if (score >= 0 && score <= (avg - 2))
grade = "F";
outFile1 << id << " " << firstName << " " << lastName << " " << score << " " << grade << endl;
}
else
outFile1 << id << " " << firstName << " " << lastName << " " << score << endl;
//cout << id << " " << firstName << " " << lastName << " " << score << endl;
}
inFile.close();
//read letter grade file and launch menu
ifstream inFile2;
inFile2.open(NEWFILENAME);
idx = 0;
while (idx < MAXSTUDENTS)
{
inFile2 >> ids[idx] >> fname[idx] >> lname[idx] >> scores[idx];
if ( scores[idx] != -1 )
inFile2 >> grades[idx];
cout << ids[idx] << fname[idx] << lname[idx] << scores[idx] << grades[idx] << endl;
idx++;
}
inFile2.close();
do
{
cout << setw(30) << "QUIZ RESULTS MENU " << endl;
cout << setw(30) << "***************************" << endl << endl;
cout << " 1. " << left << setw(30) << "Sort by Student ID" << endl;
cout << " 2. " << setw(30) << "Search for a Student ID and Display Grades" << endl;
cout << " 3. " << setw(30) << "Search by Letter Grade" << endl;
cout << " 4. " << setw(30) << "Sort by Numeric Grade" << endl;
cout << " 5. " << setw(30) << "Calculate Percentage of Students for a Letter Grade" << endl;
cout << " 6. " << setw(30) << "Sort Alphabetically by Student Last Name" << endl;
cout << " 7. " << setw(30) << "Exit the Program" << endl << endl;
cout << right << "Enter an option: " ;
cin >> num;
cout << endl;
ofstream sortedId;
ifstream inFile3;
sortedId.open(SORTEDIDS);
inFile3.open(NEWFILENAME);
if (num == 1)
{
insertionSort_byInteger(ids, MAXSTUDENTS);
for (idx = 0; idx < MAXSTUDENTS; idx++)
{
sortedId >> sortids[idx] >> fnames >> lnames >> score2;
if ( score2 != -1 )
sortedId >> grade2;
idx++;
}
sortedID.close();
ifstream sortedID;
sortedID.open(SORTEDIDS);
for (idx = 0; idx < MAXSTUDENTS; idx++)
{
if(sortids[idx] == ids[idx])
{
cout << ids[idx] << fname[idx] << lname[idx] << scores[idx];
if(scores[idx] != -1)
cout << grades[idx] << endl;
}
}
}
|