Problem The Registrar\'s office here at Ramapo has heard how good you are with C
ID: 3572745 • Letter: P
Question
Problem
The Registrar's office here at Ramapo has heard how good you are with C++. They have requested that you write them a new menu interface to their database. This program will have to accept user input via the terminal, store student information, display student information, and search the student information. A student contains a name, an random R# generated for each new student, a GPA, and a year they started at RCNJ. You can assume no more than 42 students.
Your program must do the following:
Add a new student. Your program should
Input and save
i. The student’s name (no spaces) ii. Student’s GPA (Max 4.0, Min 0.0)
iii. The year the student started at RCNJ (Min 1972, Max 2016)
Generate and save a random 5 digit R# for the student
Print all students. For each student your program should display a. Name
b. GPA
c. R#
Print all students by year. Your program should print all students that started in
a given year. The year should be given by the user.
Print statistics. Your program should display the following statistics
a. Total number of students
b. Average GPA of all students
c. Number of students with a GPA below 2.0
Quit. Your program should terminate.
Implementation Notes:
You must define the following functions:
print_menu: This function should print all of the menu options
get_selection : To read, validate, and return the menu option selected by the
user.
1
It should read the menu option as numerical input and return it as a number;
It should call print_menu defined earlier.
get_name: This function should get and return the student’s name.
get_gpa: This function should get, validate, and return the gpa.
get_year: This function should get, validate, and return the year.
input_new_student : This function should
input and save all the information about one student. It must call get_name, get_gpa, and get_year functions defined earlier.
print_all: This function should display all of the students in the proper format.
print_by_year: This function should
get a year from the user.
print all students that started in that given year, following the proper
formatting.
print_statistics : This function should display all of the statistics based on the
students that have been entered by the user.
Explanation / Answer
Hope this answers your question...
/*Title : Implementing Student Database Management System Using Singly linked list*/
#include<iostream>
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
#include<string>
#include<iomanip>
using namespace std;
struct Node
{
int RollNo;
char name[30];
float marks;
struct Node *next; /*Pointer pointing to the datastructure of type Node ...*/
}*head;
class list
{
public:
Node* Create(Node *head);
Node* Insert(Node *head);
Node* Delete(Node *head);
void Search(Node *head);
void Modify(Node *head);
void Display(Node *head);
void Count(Node *head);
list()
{
head = NULL;
}
};
Node* list::Create(Node *head)
{
int n;
int m;
Node *nn;
Node *p1;
cout<<"How many Entries do you want to create in the Database???"<<endl;
cin>>n;
for(m=0;m<n;m++)
{
if(head==NULL)
{
head= new (struct Node); /*Creating initial node...*/
cout<<"Enter RollNo and make sure it is unique "<<endl;
cin>>nn->RollNo;
cout<<"Enter Name"<<endl;
cin>>nn->name;
cout<<"Enter marks"<<endl;
cin>>nn->marks;
nn->next=NULL; /*Setting next field to NULL in case of single record...*/
head=nn;
}
else
{
p1=nn=head;
while(nn->next!=NULL)
{
nn=nn->next;
}
nn->next=new (struct Node); /*Creating the following nodes...*/
nn=nn->next;
cout<<"Enter RollNo and make sure it is unique"<<endl;
cin>>nn->RollNo;
cout<<"Enter Name "<<endl;
cin>>nn->name;
cout<<"Enter Marks "<<endl;
cin>>nn->marks;
nn->next=NULL;
nn=p1;
}
}
return head;
}
void list::Display(Node *head)
{
Node *p2;
if(head==NULL)
{
cout<<"There is no records in database."<<endl;
}
else
{
p2=head;
cout<<"Updated Student Database"<<endl;
cout<<setw(10)<<"RollNo"<<setw(10)<<"Name"<<setw(10)<<"Marks"<<endl;
while(p2!=NULL)
{
cout<<setw(10)<<p2->RollNo;
cout<<setw(10)<<p2->name;
cout<<setw(10)<<p2->marks<<endl;
p2=p2->next; /*Move to next node...*/
}
}
}
Node* list::Insert(Node *head)
{
int ch2;
int r;
char anss;
Node *p3;
Node *nn;
Node *q;
do
{
cout<<"Where do you want to enter new entry???"<<endl;
cout<<"1.At the Begining" <<endl;
cout<<"2.At the middle"<<endl;
cout<<" 3.At the end"<<endl;
cout<<"Enter your choice:"<<endl;
cin>>ch2;
switch(ch2)
{
case 1:
/*Insertion at The Begining Of Linked List */
p3=head;
nn=new (struct Node);
cout<<"Enter RollNo(unique)"<<endl;
cin>>nn->RollNo;
cout<<"Enter name"<<endl;
cin>>nn->name;
cout<<"Enter marks"<<endl;
cin>>nn->marks;
nn->next=NULL;
nn->next=p3;
head=nn; //Setting the initial node as head node...
cout<<"Entry is Created successfully."<<endl;
Display(head);
break;
case 2:
/* Insertion at The Middle Of Linked List*/
if(head==NULL)
{
cout<<"Yet database is not created."<<endl;
cout<<"Database is empty."<<endl;
cout<<"First Create Database."<<endl;
}
else
{
cout<<"After which RollNo. You want to insert new Data???"<<endl;
cin>>r;
p3=head;
while(p3->RollNo!=r && p3->next!=NULL)
{
p3=p3->next; /*Traverse the Linked List untill the required RollNo is found....*/
}
if(p3->RollNo!=r)
{
cout<<"There is no such entry."<<endl;
}
else
{
nn=new Node;
cout<<"Enter RollNo(unique)"<<endl;
cin>>nn->RollNo;
cout<<"Enter Name"<<endl;
cin>>nn->name;
cout<<"Enter Marks";
cin>>nn->marks;
nn->next=NULL;
q=p3->next;
p3->next=nn;
nn->next=q;
cout<<"Entry is Created successfully."<<endl;
Display(head);
}
}
break;
case 3:
/* Insert at end */
if(head==NULL)
{
cout<<"Yet database is not created."<<endl;
cout<<"Database is empty."<<endl;
cout<<"First Create Database."<<endl;
}
else
{
p3=head;
nn=new Node;
cout<<"Enter RollNo(unique)"<<endl;
cin>>nn->RollNo;
cout<<"Enter Name"<<endl;
cin>>nn->name;
cout<<"Enter Marks"<<endl;
cin>>nn->marks;
nn->next=NULL;
while(p3->next!=NULL)
{
p3=p3->next; /*Traverse the linked list till the last Position...*/
}
p3->next=nn;
cout<<"Entry is Created successfully."<<endl;
Display(head);
}
break;
}
cout<<"Do you want to Insert more data(Y/N)???"<<endl;
cin>>anss;
}while(anss=='y' || anss=='Y');
return head;
}
Node* list::Delete(Node* head)
{
Node *p4;
Node *q;
Node *r;
char ansl;
int ch1;
int n;
do{
cout<<"Which Entry you want to Delete???"<<endl;
cout<<"1.First 2.Middle 3.End"<<endl;
cin>>ch1;
if(head==NULL)
{
cout<<"Yet database is not created."<<endl;
cout<<"Database is empty."<<endl;
cout<<"First Create Database."<<endl;
}
else
{
switch(ch1)
{
case 1:
/*Deleting the first node from the Linked List */
p4=head;
head=head->next; /*Setting the second node as the head node...*/
delete(p4);
cout<<"First entry is deleted."<<endl;
Display(head);
break;
case 2:
/*Deleting the middle Node from the list*/
p4=head;
cout<<"Enter RollNo. which you want to delete:"<<endl;
cin>>n;
while((p4->next)->RollNo!=n && p4->next->next!=NULL)
{
p4=p4->next; /*Traverse the List uptill the predessor of the node that we want to delete...*/
}
if(p4->next->next==NULL)
{
cout<<"There is no such entry."<<endl;
}
else
{
q=p4->next;
r=q->next;
p4->next=r;
delete(q); /*Deleting that node from the memory...*/
cout<<"Entry is deleted."<<endl;
Display(head);
}
break;
case 3:
/* Deleting the last node from the list */
p4=head;
while(p4->next->next!=NULL)
{
p4=p4->next; /*Go upto the predecessor of the node which you want to delete...*/
}
q=p4->next;
delete(q); /*Delete last node from the list...*/
p4->next=NULL;
cout<<"Last entry is deleted."<<endl;
Display(head);
break;
}
}
cout<<"Do you want to delete more data(Y/N)???"<<endl;
cin>>ansl;
}while(ansl=='y'|| ansl=='Y');
return head;
}
void list::Search(Node *head)
{
Node *p5;
int r1;
int cnt=0;
if(head==NULL)
{
cout<<"Yet database is not created."<<endl;
cout<<"Database is empty."<<endl;
cout<<"First Create Database."<<endl;
}
else
{
p5=head;
cout<<"Enter RollNo. which you want to Search:"<<endl;
cin>>r1;
while(p5->RollNo!=r1 && p5->next!=NULL) /*Search for the desired RollNo...*/
{
p5=p5->next;
cnt++;
}
if(p5->RollNo!=r1)
cout<<"There is no such entry."<<endl;
else
{
cout<<r1;
cout<<cnt+1;
cout<<setw(10)<<"RollNo."<<setw(10)<<"Name"<<setw(10)<<"Marks"<<endl;
cout<<setw(10)<<p5->RollNo;
cout<<setw(10)<<p5->name;
cout<<setw(10)<<p5->marks;
}
}
}
void list::Modify(Node * head)
{
Node *p6;
int r2;
if(head==NULL)
{
cout<<"Database is not created yet."<<endl;
cout<<"Database is empty."<<endl;
cout<<"First Create Database."<<endl;
}
else
{
p6=head;
cout<<"Enter the RollNo. whose data you want to modify:"<<endl;
cin>>r2;
while(p6->RollNo!=r2 && p6->next!=NULL)
{
p6=p6->next;
}
if(p6->RollNo!=r2)
{
cout<<"Thre is no such record in Database."<<endl;
}
else
{
cout<<"Entered Roll no's Data is:"<<endl;
cout<<setw(10)<<"Roll No."<<setw(10)<<"Name"<<setw(10)<<"Marks"<<endl; /*Displaying the Data of the record that is going to be modified....*/
cout<<setw(10)<<p6->RollNo;
cout<<setw(10)<<p6->name;
cout<<setw(10)<<p6->marks;
cout<<endl;
cout<<"Enter New Roll no(unique), New name & Marks for this entry:"<<endl;
cin>>p6->RollNo;
cin>>p6->name; /*Enter the new data...*/
cin>>p6->marks;
cout<<"Entered New Data is:"<<endl;
cout<<setw(10)<<"Roll No."<<setw(10)<<" Name"<<setw(10)<<"Marks"<<endl;
cout<<p6->RollNo;
cout<<p6->name;
cout<<p6->marks;
Display(head);
}
}
}
void list::Count(Node *head)
{
Node *p;
int cnt=0;
if(head==NULL)
{
cout<<"database is not created yet."<<endl;
cout<<"Database is empty."<<endl;
cout<<"First Create Database."<<endl;
cout<<"There are 0 records in Database."<<endl;
}
else
{
p=head;
while(p->next!=NULL)
{
p=p->next;
cnt++; /*Counting the number of records...*/
}
cout<<"There are " <<cnt+1<<" records in the data base"<<endl;
}
}
int main()
{
int ch;
char op;
list L1;
head=NULL;
cout<<"*----------Student Database-----------*";
do
{
cout<<endl;
cout<<"please create database prior to other operations";
cout<<endl;
cout<<endl;
cout<<"Menu 1.Create Database 2.Insert 3.Delete 4.Search 5.Modify 6.Display 7.Count Records 8.Exit ";
cout<<"Enter your choice"<<endl;
cin>>ch;
switch(ch)
{
case 1:
head=L1.Create(head); /*Call to Create function...*/
break;
case 2:
head=L1.Insert(head); /*Call to Insert function...*/
break;
case 3:
head=L1.Delete(head); /*Call to Delete function...*/
break;
case 4:
L1.Search(head); /*Call to Search function...*/
break;
case 5:
L1.Modify(head); /*Call to Modify function...*/
break;
case 6:
L1.Display(head); /*Call to Display...*/
break;
case 7:
L1.Count(head); /*Call to counting records function...*/
break;
case 8:
exit(0); /*Exiting the program...*/
default :
cout<<"You entered wrong choice. "<<endl;
}
cout<<endl;
cout<<"Do you want to Exit(Y/N)??? "<<endl;
cin>>op;
}while(op=='n' || op=='N');
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.