Professional Documents
Culture Documents
#include <string>
#include <iomanip>
string stnumber;
string stname;
char sex;
float quizz1;
float quizz2;
float assigment;
float midterm;
float final;
float total;
int numberOfitem;
};
void displaymenu();
int search(student st[], string , int s);
void add_rec(student st[], int&);
void viewall(student st[], int);
void average(student st[], int);
//show menu
int yourchoice;
char confirm;
do
{
displaymenu();
cout << "Enter your choice(1-4):";
cin >> yourchoice;
switch (yourchoice){
case 1:add_rec(st, itemcount); break;
case 2:
{
cout << "\nEnter student's ID:";
cin >> id;
search(st, id, itemcount); break;
}
case 3:average(st, itemcount); break;
case 4:viewall(st, itemcount); break;
}
//function to display a menu of choices
void displaymenu(){
cout <<
"==========================================" << "\n";
cout << " MENU " << "\n";
cout <<
"==========================================" << "\n";
cout << " 1.Add student records" << "\n";
cout << " 2.Find a student by ID" << "\n";
cout << " 3.Calculate average score of a student" << "\n";
cout << " 4.View all student records" << "\n";
return found;
}
++itemcount;
<< st[i].sex;
cout << setw(5) << st[i].quizz1 << setw(5) <<
st[i].quizz2 << setw(5) << st[i].assigment
<< setw(5) << st[i].midterm << setw(5) <<
st[i].final << setw(5)
<< st[i].total;
}
//function to calculate the average score of a student
void average(student st[], int itemcount)
{
string id;
float avg = 0;
cout << "Enter students'ID:";
cin >> id;
int index = search(st, id, itemcount);
if (index != -1 && itemcount>0)
{
st[index].total = st[index].quizz1 + st[index].quizz2 +
st[index].assigment
+ st[index].midterm + st[index].final;
avg = st[index].total / 5;
}