In: Computer Science
Data Structures Homework – Singly Linked Lists
Create a singly linked that represents a school. The school has multiple classes. Each class has a different number of students.
class student
{
Long ID;
string Name;
string Address;
float grades[3];
student *below;
};
class Node // the node represents a class in school
{
int ID;
int NoOfStudents;
int NoOfQuizes;
student *t;// a linked list of students is allocated dynamically
Node *Next;
};
class school {
string Name;
Node *Head;
int n;//number of classes in school
};
First, you need to implement the following constructors and destructors:
1- School constructor: Creates an empty school. It takes the school name as a parameter and sets the number of classes to zero.
2- Class (Node) constructor: Sets the class ID, sets the number of students to zero, the NoOfQuizes to zero and the pointers to NULL.
3- Student constructor: Sets the student’s ID, Name and address which are passed as parameters once a student is created.
4- Student destructor: contains the cout statement: ”student destructor is called”
5- Class (Node) destructor: deletes all students in class.
6- School destructor: deletes all the classes in the school.
In your main function create an empty school by entering the name of the school from keyboard (this calls the school constructor), then display the following menu to the user and perform tasks accordingly.
In addition to constructors and destructors, you need to define a function to perform each of the following tasks.
Your program must keep on displaying this list until the user chooses Exit (12).
1. Create a class: This function creates a new class in the school by reading the class information from a text file that has the following format. The class is added to the end of the school linked list. Note that this will call the Node constructor (once)+ the student constructor (multiple times).
Class ID
NoOfStudents
Student ID Student Name Student Address
Student ID Student Name Student Address
Student ID Student Name Student Address
……..
2. Read quiz grades: This function takes the class ID and the number of the quiz (first:0, second:1, Final:2) from keyboard and reads the grades for all students in the class in a certain quiz. Sort the students alphabetically then read their grades (this calls the function sort students (8)).
3. Compute student’s average: Take a student’s ID and return his average
4. Add student: Enter class ID, read a student’s information (ID & name & address from keyboard), add a student to the beginning of the class list. Note that this calls the student’s constructor. Also, read (NoOfQuizes) grades for this student.
5. Delete student: Enter student’s ID, search for the student in the school and delete the student from his class (if found).
6. Delete class: Enter class ID, find the class, delete the list of students in the class (this uses class destructor) then delete the class node from the list (the rest of the school list should remain intact).
7. Sort students: Enter class ID and sort the students of that class based on their names in alphabetical order.
8. Find the student with maximum average in a certain class: Enter class ID, find student with maximum average, then display the student (name + ID).
9. Display student given his name: enter student’s name, find the student and display his ID, grades and average.
10. Display a class given its ID: enter a class ID, find the class and neatly display the information of all the students in that class.
11. Display school: Display all classes in a school. Display each class ID together with its students (ID, name and address of each student).
12. Exit .
In your main function, create a school and test all your work above.
make it clearly thanks..!!
A linked list is a datastructure that contains nodes, each node stores not only the data but has a pointer to another node of similar kind.
In this problem, we need to create two different kinds of linked list together.
First, we need to create a linked list of all the classes, let's call this 'main linked list' and it can be represent as follows
class1------>class2------->class3 and so on till class n
*one thing to remember here is that in school class we have varaible name 'head' of 'Node' data type, we need to assign 'class1' to this variable.
head----->class1----->class2----->class3
next thing to assign the students to various classes, again this has to be done on in the form of linked list.
student1--------->student2---------->student3 and so on( each class is assigned one of this linked list)
* here also, in Node class we have a variable called 'student', for which we require to pass the reference of 'student1'.So school can be considered as a linked list of classes while inturn classes are linked lists of students.
the other questions can be solved by get and put method in respective classes. Happy learning!!