UECS1643 Fundamentals of Programming: Practical 10 Answer Guidelines Part D (Practice Exercises)
UECS1643 Fundamentals of Programming: Practical 10 Answer Guidelines Part D (Practice Exercises)
#include <iostream>
#include <iomanip>
#include <cstring>
#define SIZE 30
using namespace std;
typedef struct
{
char name[31];
int mark1;
int mark2;
double average;
} STUDENTREC;
int main(void)
{
int action, index = 0;
bool quit = false;
STUDENTREC students[SIZE];
while(!quit)
{
cout <<"\n\t\t******************************************";
cout <<"\n\t\t**\tStudent Records Menu\t\t**";
cout <<"\n\t\t******************************************\n\n";
cout <<"\t\t<1> Read Marks.\n";
cout <<"\t\t<2> List.\n";
cout <<"\t\t<3> Quit.\n\n";
cout <<"\tPlease enter your option --> ";
cin >> action;
cout <<"\n\n";
if(action == 1)
index = read_mark(students, index);
else if(action == 2)
list(students, index);
else if(action == 3)
quit = true;
else
cout <<"\tWrong selection.\n";
}
}
1
UECS1643 Fundamentals Of Programming
return index;
}
cout <<"Name\t\t\tMark1\t\tMark2\t\tAverage\n";
for(int i = 0; i < size; i++)
{
if (strlen(stud_arr[i].name) < 16)
cout << stud_arr[i].name << "\t\t"
<< setw(3) << stud_arr[i].mark1 << "\t\t"
<< setw(3) << stud_arr[i].mark2 << "\t\t"
<< setw(6) << fixed << setprecision(2)
<< stud_arr[i].average << endl;
else
cout << stud_arr[i].name << "\t"
<< setw(3) << stud_arr[i].mark1 << "\t\t"
<< setw(3) << stud_arr[i].mark2 << "\t\t"
<< setw(6) << fixed << setprecision(2)
<< stud_arr[i].average << endl;
}
}