Question
A University has a need to maintain student records such as their personal details and their grades. Currently they are maintaining these records on papers.
A University has a need to maintain student records such as their personal details and their grades. Currently they are maintaining these records on papers. But that involves a lot of manual work for their employees to store and fetch the records. Also sometimes they are facing some problems such as losing student records and taking lot of time to search a particular record. As the University is gaining more recognition the number of students getting registered is increasing year by year. The University has shortage of funds to hire more employees to maintain the records of student details. The University Management decides to hire an application developer to design an application that will be able to store and search their students records. Application should be capable of storing students personal records and their grades. Personal records include Students First Name, Last Name , UIN , Date of Birth , GPA. Your task is to create the Double Linked Linked List which implements the following functions: Creates a Linked List to store student records. Inserts an element at a particular position. Displays student records. Searches a particular student record based on the Student UIN. Free the list on user request. Resources Provided: You are provided with a program that implements single linked list. This program performs the following functions: Creates a Linked List to store student records. Displays the student records. Searches a particular student record based on the Student UIN. Free the list on user request.
cpp
_______________________________________________________________
#include
using namespace std; // creating a structure which will hold all the student records. struct StudentRecord { string firstName; string lastName; int oduUin; string dateOfBirth; double gpa; StudentRecord *next; }; StudentRecord *head = NULL;
void free_list() { // We will create a current node and assign head to it, then we will iterate the node through the linked list and delete all the records stored in the linked list StudentRecord *current = head; while(current!=NULL) // as I am considering tail->next = NULL { head->next = current->next; current->next = NULL; free(current); current = head->next; }
head = NULL; }
void display_data() { cout << endl << endl << "Listing all student records: " << endl; cout << "---------------------------" << endl; // We will create a node named start and will iterate it through the whole linked list and display the data StudentRecord *start = head; if (!start) { cout << "No Data!" << endl; return; } while(start) { cout << start -> firstName << endl; cout << start -> lastName << endl; cout << start -> oduUin << endl; cout << start -> dateOfBirth << endl; cout << start -> gpa << endl << endl; start = start -> next; } }
StudentRecord *get_data() { //creating a temporary node in which we will store all the student records and return the temporary node in the end of the function StudentRecord *rec = new StudentRecord; cout << endl; cout << "You chose option #1." << endl; cout << "What is the student's first name?: "; cin >> rec->firstName; cout << "What is the student's last name?: "; cin >> rec->lastName; cout << "What is the student's uin?: "; cin >> rec->oduUin; cout << "What is the student's date of birth?: "; cin >> rec->dateOfBirth; cout << "What is the student's GPA?: "; cin >> rec->gpa; rec->next = head; return rec; }
void add_data(StudentRecord *current) { // We will store the address of the present head node in the next field of the current node and later we will make the current node as head node current->next=head; // store the address of the pointer head(second field) head = current;
}
void search(double key) { // We will iterate the head through the linked list until it finds the required variable or until the end of linked list while (head != NULL) { if (head->oduUin == key) { cout<<"key found"< void processMenu() { // creating current node for StudentRecord struct StudentRecord *current = NULL; int ser; char choice = 0; while(true) { cout << endl <<"What would you like to do?" << endl; cout <<"==========================" << endl; cout << "1. Enter a student record. " << endl; cout << "2. List all student records. " << endl; cout << "3. Exit program. " < cin >> choice; while(cin.get() != ' '); if(choice == '1'){ current = get_data(); add_data(current); } else if(choice == '2'){ display_data(); } else if (choice == '3'){ free_list(); return; } else if (choice == '4'){ cout<<"Enter student uin to search for records"< int main() { // Program starts execution from main block cout << "Student Record Program." << endl << endl; processMenu(); // calling process function which inturn calls create and display functions system("pause"); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started