Result Card - With Structures
Result Card - With Structures
#include <iostream>
#include <cstring>
using namespace std;
// Structure Declaration
struct student
{
string name;
int rno;
int mks[MAXSUB], mobt;
float perc; // %age
char grad;
};
// Function Prototypes
void readFun(student ss[], int& nn);
void appFun(student ss[], int& nn);
int searchFun(student ss[], int nn, int s);
void sortFun(student ss[], int nn);
void delFun(student ss[], int& nn, int s);
void updFun(student ss[], int nn, int s);
void dispFun(student ss[], int nn);
// Function Definitions
void readFun(student ss[], int& nn)
{
int sum;
cout << "Enter Number of Students in the class [Max 60]: ";
cin >> nn;
for (int i=0; i<nn; i++)
{
cout << "Enter Data for Student: " << i+1 << endl;
sum = 0;
cout << "Enter Marks [Max 100] of students:" << endl;
for (int j=0; j < MAXSUB; j++) // 5 subject marks
{
cout << "Enter Marks of Subject: " << j+1 << " : ";
cin >> ss[i].mks[j];
sum += ss[i].mks[j];
}
// %age calculation
ss[i].perc = (ss[i].mobt * 100.0) / 500.0;
// Grage Assignment
if (ss[i].perc >= 80) ss[i].grad = 'A';
else if (ss[i].perc >= 70) ss[i].grad = 'B';
else if (ss[i].perc >= 60) ss[i].grad = 'C';
else if (ss[i].perc >= 50) ss[i].grad = 'D';
else ss[i].grad = 'F';
}
}// end of readFun
cout << "Enter Data for Student: " << nn << endl;
sum = 0;
cout << "Enter Marks [Max 100] of students:" << endl;
for (int j=0; j < MAXSUB; j++) // 5 subject marks
{
cout << "Enter Marks of Subject: " << j+1 << " : ";
cin >> ss[nn].mks[j];
sum += ss[nn].mks[j];
}
// %age calculation
ss[nn].perc = (ss[nn].mobt * 100.0) / 500.0;
// Grage Assignment
if (ss[nn].perc >= 80) ss[nn].grad = 'A';
else if (ss[nn].perc >= 70) ss[nn].grad = 'B';
else if (ss[nn].perc >= 60) ss[nn].grad = 'C';
else if (ss[nn].perc >= 50) ss[nn].grad = 'D';
else ss[nn].grad = 'F';
nn++;
}// end of appFun
nn--;
cout << "Student deleted successfully..." << endl;
}
else
cout << "Student Not found in the List, can't be deleted..." << endl;
}// end of delFun
int sum;
cout << "Enter Data for Student Having Reg#: " << ss[p].rno << endl;
sum = 0;
cout << "Enter Marks [Max 100] of students:" << endl;
for (int j=0; j < MAXSUB; j++) // 5 subject marks
{
cout << "Enter Marks of Subject: " << j+1 << " : ";
cin >> ss[p].mks[j];
sum += ss[p].mks[j];
}
// %age calculation
ss[p].perc = (ss[p].mobt * 100.0) / 500.0;
// Grage Assignment
if (ss[p].perc >= 80) ss[p].grad = 'A';
else if (ss[p].perc >= 70) ss[p].grad = 'B';
else if (ss[p].perc >= 60) ss[p].grad = 'C';
else if (ss[p].perc >= 50) ss[p].grad = 'D';
else ss[p].grad = 'F';
int main() {
//declarations
student s[MAXST];
int n = 0; // number of students sitting in he class
int sinfo, pos;
int choice;
// Menu
do{
cout << "**** MENU ****" << endl
<< " 1. Read & Store Data " << endl
<< " 2. Append new record " << endl
<< " 3. Search a record " << endl
<< " 4. Sort Data " << endl
<< " 5. Delete a record " << endl
<< " 6. Update a record " << endl
<< " 7. Display Result Card " << endl
<< " 8. Exit " << endl;
cout << "Enter your choice: ";
cin >> choice;
switch (choice)
{
case 1:
//cout << "Existing data will be deleted...\n";
readFun(s, n);
break;
case 2:
if (n < MAXST)
appFun(s, n);
else
cout << "ARRAY is Full...\n";
break;
case 3:
if (n != 0)
{
cout << "Enter Reg# of the student to be searched: ";
cin >> sinfo;
pos = searchFun(s, n, sinfo);
if (pos == -1)
cout << "Student ID: " << sinfo << " not exists" <<endl;
else
cout << "Student ID: " << sinfo << " exists at Position No.
" << pos+1 << endl;
}
else
cout << "First, store data using Option-1...\n";
break;
case 4:
if (n != 0)
{
sortFun(s, n);
}
else
cout << "First, store data using Option-1...\n";
break;
case 5:
if (n != 0)
{ cout << "Enter Reg# of the student to be deleted: ";
cin >> sinfo;
delFun(s, n, sinfo);
}
else
cout << "First, store data using Option-1...\n";
break;
case 6:
if (n != 0)
{
cout << "Enter Reg# of the student to be updated: ";
cin >> sinfo;
updFun(s, n, sinfo);
}
else
cout << "First, store data using Option-1...\n";
break;
case 7:
if (n != 0)
{
dispFun(s, n);
}
else
cout << "First, store data using Option-1...\n";
break;
case 8: exit(-1);
default:
cout << "Invalid Choice...\n";
}// end of switch
}while(true);
return 0;
}// end of main