Professional Documents
Culture Documents
#include<iostream>
using namespace std;
struct classinfo {
int stud_id;
float test, assignment, quiz, exam;
classinfo *next;
classinfo() {
test = 0;
assignment = 0;
quiz = 0;
exam = 0;
};
};
class classlist {
classinfo* head;
public:
classlist() {
this->head = NULL;
}
void newrecord() {
classinfo * newStud = new classinfo();
classinfo * current = head;
int check = 0;
//cout << current << endl;
if (check > 0) {
cout << "Error : Duplicate Student ID";
}
else {
if (head == NULL) {
head = newStud;
}
else {
classinfo * last = head;
while (last->next != NULL) {
last = last->next;
}
last->next = newStud;
}
}
cout << endl;
}
if (head == NULL) {
cout << "No record in the list" << endl;
}
else {
void displayrecord() {
classinfo * current = head;
if (current == NULL) {
cout << "No record in the list" << endl;
}
else {
while (current != NULL) {
cout << "Student ID : " << current->stud_id << " -> Midterm
: " << current->test << ", Quiz : " << current->quiz << ", Assignment : " << current-
>assignment << ", Final Exam : " << current->exam << endl;
current = current->next;
}
}cout << endl;
}
void beststudent() {
classinfo * current = head;
int bestID, currentID;
float bestMark = 0, currentMark;
cout << "Best student is " << bestID << "with " << bestMark << " marks."
<< endl;
cout << endl;
}
};
void main() {
int selection, id;
classlist A;
do {
cout << ":: STUDENT RECORD PROGRAM ::" << endl;
cout << "1. Add new record" << endl;
cout << "2. Delete record" << endl;
cout << "3. Display record" << endl;
cout << "4. Display best student" << endl;
cout << "5. Quit the program" << endl;
cout << "Enter selection : ";
cin >> selection;
switch (selection) {
case 1:
A.newrecord();
break;
case 2:
cout << "Please enter the student ID to be deleted : ";
cin >> id;
A.deleterecord(id);
break;
case 3:
A.displayrecord();
break;
case 4:
A.beststudent();
break;
case 5:
break;
}
} while (selection != 5);
}