A University has a need to maintain student records such as their personal detai
ID: 3917286 • Letter: A
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. 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 a lot of time to search for a particular record. As the University is gaining more recognition, the number of students getting registered is increasing year by year. The University has a 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 student’s personal records and their grades. Personal records include Student’s First Name, Last Name, UIN, Date of Birth, and 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 for 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.
code given singleList.cpp:
Explanation / Answer
#include <iostream>
#include <cstdlib>
#include <string>
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 *prev;
};
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)
{
head = head->next;
free(current);
current = head;
}
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 = NULL;
rec->prev = NULL;
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->prev = current;
head = current;
}
void insert_data(StudentRecord *current, int pos)
{
if (pos < 0){
cout << "Invalid position ";
}
else {
if (pos == 0){
current->next = head;
head->prev = current;
head = current;
}
else {
StudentRecord *p;
p = head;
int count = 0;
while (p!= NULL && count != pos -1 ){
p = p->next;
}
if (p == NULL){
cout << "Invalid index ";
}
else {
current->next = p->next;
p->next->prev = current;
p->next = current;
current->prev = p;
}
}
}
// 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->prev = current;
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"<<endl;
// cout<<head->uin<<endl;
cout<<"first name = "<<head->firstName<<endl;
cout<<"last name = "<<head->lastName<<endl;
cout<<"date of birth = "<<head->dateOfBirth<<endl;
cout<<"gpa = "<<head->gpa<<endl;
return;
}
head = head->next;
}
cout<<"Key not found"<<endl;
}
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. " <<endl;
cout << "4. Search. " << endl;
cout << "5. Insert a node at a position. " << endl;
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"<<endl;
cin>>ser;
search(ser);
}
else if (choice == '5'){
current = get_data();
cout << "Enter the position:";
int n;
cin >> n;
insert_data(current,n);
}
else {
cout << "Allowed Selections are 1, 2, and 3!" << endl;
}
}
}
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;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.