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
|
#include<iostream>
#include<fstream>
using namespace std;
struct students{
int ID;
int q1;
int q2;
int e1;
int e2;
int assg1;
int assg2;
int assg3;
};
int searchList(students grades[], int Num_Students, int ID){
int index = 0;
bool found =false;
while (index < Num_Students && !found){
if (grades[index].ID == ID){
found = true;
cout << grades[index].q1;
cout << grades[index].q2;
cout << grades[index].e1;
cout << grades[index].e2;
cout << grades[index].assg1;
cout << grades[index].assg2;
cout << grades[index].assg3;
break;
}
index++;
}
if( found )
return index;
else
return -1;
}
int searchList2(students grades[], int Num_Students, int ID){
int LAB =15;
int index = 0;
bool found = false;
double total = 0;
while (index < Num_Students && !found){
if (grades[index].ID == ID){
found = true;
total = (grades[index].q1+grades[index].q2
+grades[index].e1+grades[index].e2+grades[index].assg1+
grades[index].assg2+grades[index].assg3)*0.1 + ((grades[index].e1+grades[index].e2)/2)*.15 + LAB;
}
index++;
}
if( found ){
if (total < 60)
cout << "You have an F" << endl;
else if(total <69)
cout << " You have a D" << endl;
else if(total < 79)
cout << "You have a C" << endl;
else if(total < 89)
cout << "You have a B" << endl;
else if( total <= 100)
cout << "You have an A" << endl;
return 1;
}
else
return -1;
}
void showList(int grades[], int num){
for(int m = 0; m < num; m++)
cout << grades[m] << " ";
cout << endl;
}
void sortField( students grades[], int num, string sortThis){
bool swap;
int temp;
do{
swap = false;
for(int k = 0; k < (num - 1); k++){
if(grades[k].ID > grades[k + 1].ID){
temp = grades[k].ID;
grades[k] = grades[k + 1];
grades[k +1].ID = temp;
swap = true;
}
}
}while (swap);
}
int main(){
int ID;
char command;
int Num_grades = 65;
students grades[Num_grades];
int i =0;
int Num_Students = 65;
int sortWhat;
char sortField;
string sortList;
ifstream infile;
int sortThis;
infile.open("grades.txt");
while(!infile.eof()){
infile >> grades[i].ID;
infile >> grades[i].q1;
infile >> grades[i].q2;
infile >> grades[i].e1;
infile >> grades[i].e2;
infile >> grades[i].assg1;
infile >> grades[i].assg2;
infile >> grades[i].assg3;
i++;
}
ofstream outfile;
outfile.open("report.txt");
bool exit = false;
do{
cout << "1: Publish grade report" << endl;
cout << "2: Search for student grade by ID" << endl;
cout << "3: Sort grades" << endl;
cout << "4: Projected grade" << endl;
cout << "5: Distribute grades" << endl;
cout << endl;
cout << "Enter an operator: ";
cin >> command;
switch (command) {
case '1':
for(int j = 0; j<0;j++){
outfile << grades[j].ID;
j++;
}
break;
case '2':
cout << "Enter an ID" << endl;
cin >> ID;
if( searchList( grades, Num_Students, ID ) == -1);
cout << "Student not found!" << endl;
break;
case '3':
do{
cout << "1: Student ID" << endl;
cout << "2: Quiz 1 Grade" << endl;
cout << "3: Quiz 2 Grade" << endl;
cout << "4: Exam 1 Grade" << endl;
cout << "5: Exam 2 Grade" << endl;
cout << "6: Assignment 1 Grade" << endl;
cout << "7: Assignment 2 Grade" << endl;
cout << "8: Assignment 3 Grade" << endl;
cout << endl;
cout << "Enter field to be sorted(0-7): ";
cin >> sortWhat;
switch (sortThis){
case '1':
sortField(students grades[], int num, string sortThis);
showList(grades[].ID, Num_Students);
break;
case '2':
sortList(grades[].q1, Num_Students);
showList(grades[].q1, Num_Students);
break;
case '3':
sortList(grades[].q2, Num_Students);
showList(grades[].q2, Num_Students);
break;
case '4':
sortList(grades[].e1, Num_Students);
showList(grades[].e1, Num_Students);
break;
case '5':
sortList(grades[].e2, Num_Students);
showList(grades[].e2, Num_Students);
break;
case '6':
sortList(grades[].assg1, Num_Students);
showList(grades[].assg1, Num_Students);
break;
case '7':
sortList(grades[].assg2, Num_Students);
showList(grades[].assg2, Num_Students);
break;
case '8':
sortList(grades[].assg3, Num_Students);
showList(grades[].assg3, Num_Students);
break;
default:
cout << "Invalid Command" << endl;
}
}while( !exit );
break;
case '4':
cout << "Enter an ID" << endl;
cin >> ID;
if( searchList2(grades, Num_Students, ID) == -1 )
cout << "Student not found!" << endl;
break;
case '5':
break;
default:
exit = true;
}
}while( !exit );
infile.close();
system("PAUSE");
return 0;
}
| |