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
|
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
const int STUDENTS = 10;
const int SCORES = 5;
void namesAndGrades(string name[], int id[], int grade[][SCORES], int oGrade[]);
void letterGrd (string letter[], int oGrade[]);
void output (string name[], string letter[], int id[], int grade[][SCORES], int oGrade[]);
void highestGrade(int highScore, string highName, string name[], int oGrade[]);
void searchName(string name[], string search);
void report(string name[], string letter[], int id[], int grade[][SCORES], int oGrade[]);
int main(){
int ids[STUDENTS];
string names[STUDENTS];
int grades[STUDENTS][SCORES];
int overGrade[STUDENTS] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
string ltrGrade[STUDENTS];
int highGrade=0;
string bestGrade;
string searchTerm;
int avg=0;
namesAndGrades (names, ids, grades, overGrade);
letterGrd (ltrGrade, overGrade);
output (names, ltrGrade, ids, grades, overGrade);
highestGrade (highGrade, bestGrade, names, overGrade);
searchName (names, searchTerm);
report (names, ltrGrade, ids, grades, overGrade);
return 0;
}
void namesAndGrades(string name[], int id[], int grade[][SCORES], int oGrade[]){
char o;
ifstream inFile;
inFile.open("data121.txt");
if ("data121.txt"){
for(int x=0; x<STUDENTS; x++){
inFile >> id[x]>>o;
getline(inFile, name[x], ',');
for(int y=0; y<SCORES;y++){
inFile>>grade[x][y]>>o;
oGrade[x]+=grade[x][y];
}
}
}
inFile.close();
}
void letterGrd (string letter[], int oGrade[]){
for(int i=0;i<STUDENTS;i++){
if (oGrade[i]>=90)
letter[i]= "A";
else if (oGrade[i]<90 && oGrade[i]>=80)
letter[i]="B";
else if (oGrade[i]<80 && oGrade[i]>=70)
letter[i]="C";
else if (oGrade[i]<70 && oGrade[i]>=60)
letter[i]="D";
else if (oGrade[i]<60)
letter[i]="F";
}
}
void output (string name[], string letter[], int id[], int grade[][SCORES], int oGrade[]){
for (int x=0; x<STUDENTS; x++){
cout<< id[x]<<" "<<name[x]<<" ";
for (int y=0; y<SCORES; y++){
cout<< grade[x][y]<<" ";
}
cout<< oGrade[x]<<" "<<letter[x]<<endl;
}
}
void highestGrade(int bestScore, string highName, string name[], int oGrade[]){
for (int x=0; x<STUDENTS; x++){
if (oGrade[x] > bestScore){
highName = name[x];
bestScore = oGrade[x];
}
}
cout<<highName<<" "<<bestScore<<endl;
}
void searchName(string name[], string search){
bool found;
cout<< "Please enter the name of the student you would like to look up: ";
getline(cin, search);
for (int x=0; x<STUDENTS; x++){
if (name[x]==search){
found=true;
break;
}
}
if (found)
cout<<"Found the record of "<<search<<endl;
else
cout<< "No record found"<<endl;
}
void reprot(string name[], string letter[], int id[], int grade[][SCORES], int oGrade[]){
ofstream outFile;
outFile.open("report121.txt");
for (int x=0; x<STUDENTS; x++){
outFile<<id[x]<<" "<<name[x]<<" ";
for(int y=0; y<SCORES; y++){
outFile<<grade[x][y]<<" ";
}
outFile<<oGrade[x]<<" "<<letter[x]<<endl;
}
outFile.close();
}
|