0% found this document useful (0 votes)
22 views6 pages

Result Card - With Structures

Uploaded by

Malik Areeb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views6 pages

Result Card - With Structures

Uploaded by

Malik Areeb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

// Result Card - Using Structures

#include <iostream>
#include <cstring>
using namespace std;

#define MAXST 60 // Max Students


#define MAXSUB 5 // Max Subjects

// 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;

cout << "Name: ";


cin.ignore(30,'\n');
getline(cin, ss[i].name);

cout << "Reg#: ";


cin >> ss[i].rno; // reg#

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];
}

ss[i].mobt = sum; // marks obtained

// %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

void appFun(student ss[], int& nn)


{
int sum;

cout << "Enter Data for Student: " << nn << endl;

cout << "Name: ";


cin.ignore(30,'\n');
getline(cin, ss[nn].name);

cout << "Reg#: ";


cin >> ss[nn].rno; // reg#

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];
}

ss[nn].mobt = sum; // marks obtained

// %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

int searchFun(student ss[], int nn, int s)


{
int p = -1;
for (int i = 0; i < nn; i++)
{
if (s == ss[i].rno)
{
p = i;
break;
}
}
return p;
}// end of searchFun

void sortFun(student ss[], int nn)


{
int nofpass = nn - 1;
student temp;
for (int i=0; i<nofpass; i++) // Selection Sort method
for (int j=i+1; j<nn; j++)
if (ss[i].rno > ss[j].rno)
{
temp = ss[i];
ss[i] = ss[j];
ss[j] = temp;
}
cout << "Data Sorted successfully..." << endl;
}// end of sortFun

void delFun(student ss[], int& nn, int s)


{
int p;
p = searchFun(ss, nn, s);
if (p != -1) // student found in the list
{
for (int i = p; i < nn-1; i++)
ss[i] = ss[i+1];

nn--;
cout << "Student deleted successfully..." << endl;
}
else
cout << "Student Not found in the List, can't be deleted..." << endl;
}// end of delFun

void updFun(student ss[], int nn, int s)


{
int p;
p = searchFun(ss, nn, s);
if (p != -1) // student found in the list
{
cout << "OLD RECORD" << endl;
cout << p+1 << " - ";
cout << ss[p].rno << " - ";
cout << ss[p].name << " - ";
for (int j = 0; j < MAXSUB; j++)
cout << ss[p].mks[j] << " - ";
cout << ss[p].mobt << " - " <<ss[p].perc << " - "
<< ss[p].grad << endl;

cout << "--------------------------------------------------" << endl;

cout << "Now Enter New Data" << endl;

int sum;
cout << "Enter Data for Student Having Reg#: " << ss[p].rno << endl;

cout << "Name: ";


cin.ignore(30,'\n');
getline(cin, ss[p].name);

cout << "Reg#: ";


cin >> ss[p].rno; // reg#

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];
}

ss[p].mobt = sum; // marks obtained

// %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';

cout << "Student's Record Updated successfully..." << endl;


}
else
cout << "Student Not found in the List, can't be updated..." << endl;
}// end of updFun

void dispFun(student ss[], int nn)


{
for (int i = 0; i < nn; i++)
{
cout << i+1 << " - ";
cout << ss[i].rno << " - ";
cout << ss[i].name << " - ";
for (int j = 0; j < MAXSUB; j++)
cout << ss[i].mks[j] << " - ";
cout << ss[i].mobt << " - " <<ss[i].perc << " - "
<< ss[i].grad << endl;
}
}// end of dispFun

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

You might also like