I need some help with my program. The program is supposed to read ID#'s for students as well as grades from a file called "grades.txt" After the program reads the the file it displays a menu as follows: 1. Publish(publish contents of file to output file called "report.txt"); 2. Search(program prompts user to enter ID and display the grades for that specific student); 3. Sort( ask user which field to sort records: valid fields are 0-7 and then print specific records in ascending order like user types 4 and shows all students Exam 2 grades); 4. Projected Grade(calculate official grade/display using formula:
(quiz1+quiz2+exam1+exam2+assignment1+assignment2+assignment3)*0.1+((exam1+exam2)/2)*0.15+LAB =15
as well as display letter grade: A=90-100, B = 80-89, C= 70-79, D =60-69, F = <60); 5. Distribution(display number of A's, B's, C's, D's and F's in class based on students scores). The "grades.txt" file looks similar to this: 116807 65 31 41 19 15 72 11 // ID quiz1 quiz2 exam1 exam2 assignment1 assignment2 assignment3. This is my code so far:
#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 sortList(){
cout << "'sortList()' not yet initiated!" << endl;
}
int main(){
int ID;
char command;
int Num_grades = 65;
students grades[Num_grades];
int i =0;
int Num_Students = 65;
ifstream infile;
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':
sortList();
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;
}
So, I am supposed to do a bubble or selection sort for my case 3 and I don't know that much about it. Does anyone have any suggestions as to how I can begin the sort?