Write a program for keeping a course list for each student in a college. Informa
ID: 3575440 • Letter: W
Question
Write a program for keeping a course list for each student in a college. Information about each student should be kept in an object that contains the student id (four digit integer), name (string), and a list of courses completed by the student.
The course taken by a student are stored as a linked list in which each node contain course name (string such as CS41, MATH10), course unit (1 to 4) and the course grade (A,B,C,D,F).
The program provides a menu with choices that include adding a student record, deleting a student record, adding a single course record to a student’s record, deleting a single course record from a student’s record, and print a student’s record to a screen.
A student record should include a GPA (Grade Point Average) when display on the screen. The GPA is calculated by following formula:
When the user is through with the program, the program should store the records in a file. The next time the program is run, the records should be read back out of the file and the list should be reconstructed
You will need to implement a List container to hold a list of student records, each of which has a List container as its member. Note that no duplicate items should be permitted in either (student and course) List container.
Develop a test driver program that allow options to add, remove, and display student records and the course list of each student.
You may use class template technique (in C++) or generic programming (in Java) to implement a List ADT that could be used for both student list and the course list..
To calculate G.P.A. for one term:
Multiply the point value of the letter grade (A=4, B=3, C=2, D=1, F=0) by the number of credit hours. The result is the grade points (quality points) earned.
Total the credit hours for the student; total the quality points for the student.
Divide the total quality points by the total credit hours.
Print the source code, dialog with users (program input/output), and a copy of the executable (.exe or jar file in USB or CD) for grading.
Explanation / Answer
#include<iostream>
using namespace std;
struct course{
string courseName;
int courseUnit;
char courseGrade;
};
struct student {
int studentID;
string name;
course crs[4];
struct student *next;
};
struct student *head = NULL;
void addCourseRecord(struct student *);
void addStudentRecord(){
struct student *temp;
temp = new (struct student);
cout<<"Enter Student Details ";
cout<<"Student ID : "; cin>>temp->studentID;
cout<<"Student Name : "; cin>>temp->name;
addCourseRecord(temp);
temp->next = NULL;
if(head == NULL){
head = temp;
}
else{
temp->next = head;
head = temp;
}
}
void deleteStudentRecord(){
struct student *temp, *temp1;
int node1;
cout<<"Enter Student ID you wants to delete : ";
cin>>node1;
if(head->studentID == node1){
temp = head->next;
delete head;
head = temp;
}
else{
temp = head;
while(temp->next){
temp1 = temp->next;
if(temp1->studentID == node1 && temp1->next == NULL){
delete temp1;
temp->next = NULL;
}
if(temp1->studentID == node1){
temp->next = temp1->next;
delete temp1;
temp1 = temp->next;
}
temp = temp->next;
}
}
}
void addCourseRecord(struct student *temp){
cout<<"----- Course Details ----- ";
for(int j = 0; j<3; j++){
cout<<"Course Unit : "; cin>>temp->crs[j].courseUnit;
cout<<"Course Name : "; cin>>temp->crs[j].courseName;
cout<<"Course Grade : "; cin>>temp->crs[j].courseGrade;
}
}
void deleteCourseRecord(){
struct student *temp, *temp1;
int stID, crsID;
cout<<"Enter student ID : ";
cin>>stID;
cout<<"Enter Course unit :";
cin>>crsID;
if(head->studentID == stID){
temp = head->next;
delete head;
head = temp;
}
else{
temp = head;
while(temp->next){
temp1 = temp->next;
if(temp1->studentID == stID && temp1->next == NULL){
delete temp1;
temp->next = NULL;
}
if(temp1->studentID == stID){
temp->next = temp1->next;
delete temp1;
temp1 = temp->next;
}
temp = temp->next;
}
}
}
void printRecord(){
cout<<" ";
struct student *head1;
head1 = head;
while(head1){
cout<<" Student ID: "<<head1->studentID<<" Student Name: "<<head1->name<<" ";
cout<<"--- Course Details --- ";
for(int i=0; i<3; i++){
cout<<head1->crs[i].courseUnit<<" | ";
cout<<head1->crs[i].courseName<<" |";
cout<<head1->crs[i].courseGrade<<" ";
}
head1 = head1->next;
}
}
int main(){
struct student *temp;
int opt;
char ch;
do {
cout<<" 1. Add Student Record 2. Delete Student Record 3. Add Course Record 4. Delete Course Record 5. Print Records ";
cout<<"Choose Option : "; cin>>opt;
switch(opt){
case 1: do{
addStudentRecord();
cout<<"wants to add node ? (Y/y) : ";
cin>>ch;
}while(ch =='Y' || ch =='y');
break;
case 2: deleteStudentRecord();
cout<<" Student Record deleted succesfully ";
break;
case 3: addCourseRecord(temp);
break;
case 4: if(head == NULL)
cout<<"No records, Provide some records ";
else
deleteCourseRecord();
break;
case 5: printRecord();
break;
default : cout<<"Invaid option ";
break;
}
}while(opt>0 && opt<6);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.