Question

In: Computer Science

Data Structures Homework – Singly Linked Lists Create a singly linked that represents a school. The...

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..!!

Solutions

Expert Solution

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!!


Related Solutions

04 Prove : Homework - Data Structures Linked Lists Outcomes At the end of this study,...
04 Prove : Homework - Data Structures Linked Lists Outcomes At the end of this study, successful students will be able to: Articulate the strengths and weaknesses of Linked Lists. Use Linked Lists in Python to solve problems. Preparation Material Read the following sections from Wikipedia: Linked Lists: The Introduction Advantages Disadvantages Basic concepts and nomenclature The following subsections are sufficient: Intro Singly Linked Lists Doubly Linked Lists Tradeoffs The following subsections are sufficient: Linked Lists vs. Dynamic Arrays Data...
Data Structures in Java In the following Singly Linked List implementation, add the following methods, and...
Data Structures in Java In the following Singly Linked List implementation, add the following methods, and write test cases in another java file to make sure these methods work. - Write a private method addAfter(int k, Item item) that takes two arguments, an int argument k and a data item, and inserts the item into the list after the K-th list item. - Write a method removeAfter(Node node) that takes a linked-list Node as an argument and removes the node...
towers of hanoi c++ program using stacks and singly linked lists.
towers of hanoi c++ program using stacks and singly linked lists.
Exercise 1: Write a program in Java to manipulate a Singly Linked List: 1. Create Singly...
Exercise 1: Write a program in Java to manipulate a Singly Linked List: 1. Create Singly Linked List 2. Display the list 3. Count the number of nodes 4. Insert a new node at the beginning of a Singly Linked List. 5. Insert a new node at the end of a Singly Linked List 6. Insert a new node after the value 5 of Singly Linked List 7. Delete the node with value 6. 8. Search an existing element in...
How would you show two linked lists are equal? (Java for Data Structures and Algorithms)
How would you show two linked lists are equal? (Java for Data Structures and Algorithms)
2.1 Linked Lists Linked lists are an example of an unbound data structure. Whereas the array...
2.1 Linked Lists Linked lists are an example of an unbound data structure. Whereas the array is based around having a fixed size per array creation, there is no logical limit on the ability of a linked list to grow. Physical limitations aside, linked lists are capable of growing largely without any limitations. To achieve this, they trade easier access to their individual elements. This is because linked lists have to be traversed from their root node to any node...
Write a pseudocode function that interchanges two adjacent items of: (a) singly linked lists (b) doubly...
Write a pseudocode function that interchanges two adjacent items of: (a) singly linked lists (b) doubly linked lists if you can make it clean and short that be nice
JAVA *** All data structures, including array operations, queues, stacks, linked lists, trees, etc need to...
JAVA *** All data structures, including array operations, queues, stacks, linked lists, trees, etc need to be implemented by you. Write a menu driven program that implements the following Binary Search Tree Operations FIND (item) INSERT (item) DELETE (item) DELETE_TREE (delete all nodes - be careful with the traversal!)
6.9 Lab: Singly-Linked Lists As an entry-level programmer you have to be able to read, understand...
6.9 Lab: Singly-Linked Lists As an entry-level programmer you have to be able to read, understand existing code and update it (add new features). One of this assignment’s goals is to read about 400 lines of code in five files, compile and run the program, understand it, and change it as required. Download and review the following files (read code and all comments carefully): College.h College.cpp LinkedList.h LinkedList.cpp main.cpp --------------------------------------------------------- //colleges.txt 3 SBCC Santa Barbara City College; 18524 97 ZZC...
Using the singly linked list code as a base, create a class that implements a doubly...
Using the singly linked list code as a base, create a class that implements a doubly linked list. A doubly linked list has a Previous link so you can move backwards in the list. Be sure the class is a template class so the user can create a list with any data type. Be sure to test all the member functions in your test program. c++
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT