Question

Below is my C++ program. There is a function to add data, display it and search...

Below is my C++ program. There is a function to add data, display it and search the data. Just add two more functions to this porgram. One function to update the student data and second function to delete the data. Also, change the display function little bit. Right now, it shows all data entered. Make it so you have to put the uin number and it only displays the data of that specific student.

#include <iostream>
#include <string>
using namespace std;
struct StudentRecord {
   string firstName;
   string lastName;
   int oduUin;
   string dateOfBirth;
   double gpa;
   StudentRecord *next;
};
StudentRecord *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" << 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;

       cin >> choice;
       while (cin.get() != '\n');
       if (choice == '1') {
           current = get_data();
           add_data(current);
       }
       else if (choice == '2') {
           display_data();
       }
       else if (choice == '3') {
           exit(1);
           return;
       }
       else if (choice == '4') {
           cout << "Enter student uin to search for records" << endl;
           cin >> ser;
           search(ser);
       }
       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;
}

Homework Answers

Answer #1

#include <iostream.h> // remove .h
#include <string.h> // remove .h
#include<stdlib.h> //remove .h
//using namespace std;
struct StudentRecord {
char firstName[50]; // for linux use string firstName
char lastName[50]; // for linux use string lastName
int oduUin;
char dateOfBirth[50]; //for linux use string dateOfBirth
double gpa;
StudentRecord *next;
};
StudentRecord *head = NULL;
void UpdateData(double key)
{
   StudentRecord *temp;
   temp=head;
// We will iterate the head through the linked list until it finds the required variable or until the end of linked list
while (temp != NULL)
{
if (temp->oduUin == key)
{
   cout << "What is the student's first name?: ";
   cin >> temp->firstName;
   cout << "What is the student's last name?: ";
   cin >> temp->lastName;
   // cout << "What is the student's uin?: "; // in case you want to update uin
   // cin >> head->oduUin;
   cout << "What is the student's date of birth?: ";
   cin >> temp->dateOfBirth;
   cout << "What is the student's GPA?: ";
   cin >> temp->gpa;
cout << "Record updated..." << endl;
   return;
}
temp = temp->next;
}
cout << "Key not found to update" << endl;
}
void DeleteRecord(double key)
{
StudentRecord *temp1,*temp2,*temp;
   temp=head;
// We will iterate the head through the linked list until it finds the required variable or until the end of linked list
while (temp != NULL)
{

if(temp->oduUin == key)

{

head = temp->next;

cout<<"Record Deleted successfully...."<<endl;

return;

}
if (temp->next->oduUin == key)
{
   temp1=temp->next;
   temp2=temp1->next;
   temp->next=temp2;
   cout << "Record Deleted Successfully..." << endl;
   return;
}
temp = temp->next;
}
cout << "Key not found to Delete Record" << endl;
}

void display_data(double key)
{
cout << endl << endl << "Student record: " << 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 != NULL)
{
if (start->oduUin == key)
{
   cout << start->firstName << endl;
cout << start->lastName << endl;
cout << start->oduUin << endl;
cout << start->dateOfBirth << endl;
cout << start->gpa << endl << endl;
   return;
}
start = start->next;
}
cout << "Record not found" << endl;
}

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" << 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 (1) {
cout << endl << "What would you like to do?" << endl;
cout << "==========================" << endl;
cout << "1. Enter a student record. " << endl;
cout << "2. Display student records. " << endl;
cout << "3. Exit program. " << endl;
cout << "4. Search. " << endl;
cout << "5. Update. " << endl;
cout << "6. Delete Record. " << endl;
cin >> choice;
while (cin.get() != '\n');
if (choice == '1') {
   current = get_data();
   add_data(current);
}
else if (choice == '2') {
   cout << "Enter student uin to Display records" << endl;
   cin >> ser;
   display_data(ser);
}
else if (choice == '3') {
   exit(0); // in linux exit(1)
   return;
}
else if (choice == '4') {
   cout << "Enter student uin to search for records" << endl;
   cin >> ser;
   search(ser);
}
   else if (choice == '5') {
   cout << "Enter student uin to Update records" << endl;
   cin >> ser;
   UpdateData(ser);
}
else if (choice == '6') {
   cout << "Enter student uin to Delete records" << endl;
   cin >> ser;
   DeleteRecord(ser);
}
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"); //remove comment in your code
return 0;
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
How to stop the program from exiting after display detail. When there is food detail, it...
How to stop the program from exiting after display detail. When there is food detail, it will display and exit the program. What can i do to make it not exit the program and back to main menu. #include <iostream> #include <iomanip> #include<string.h> using namespace std; struct food{ int order_id; string food_code,flavor,customer_id; string address,name; int weight,unit_price,qty,contact_number; struct food *next; };    class Foodsystem{ food *head,*temp,*temp2,*end; static int id;    public: Foodsystem(){ head=NULL;end=NULL;} void Place_Order(); void View_food_details(); void Modify_food_details(); void Delete_food_details();...
i want to complete this code to insert a new node in the middle of list...
i want to complete this code to insert a new node in the middle of list (take a node data from user, search the node and insert new node after this node). this is the code #include <iostream> #include <stdlib.h> using namespace std ; struct Node{                int data;                Node *link ;}; struct Node *head=NULL, *tail=NULL; /* pointers to Node*/ void InsertFront(); void InsertRear(); void DeleteFront(); void DeleteRear(); int main(){                int choice;                do{                               cout << "1:...
C++ Fix my code This code is for imitating the round robin cpu scheduling algorithim using...
C++ Fix my code This code is for imitating the round robin cpu scheduling algorithim using linked lists. Currently I am able to input processes and store / display them properly. The issue begins somewhere after I have displayed the processlist (I get a segmentation fault (core dumped) or the code doesnt seem to run). I have marked the location of where I think the issue begins with a comment. Please fix the code so that it is working properly....
Write a program that accepts as input the mass, in grams, and density, in grams per...
Write a program that accepts as input the mass, in grams, and density, in grams per cubic centimeters, and outputs the volume of the object using the formula: volume = mass / density. Format your output to two decimal places. ** Add Comments ** Print Name and Assignment on screen ** Date ** Submit .cpp file. Demo // This program uses a type cast to avoid an integer division. #include <iostream> // input - output stream #include <fstream> //working file...
The one missing piece was inserting into a binary search tree; we'll take care of that...
The one missing piece was inserting into a binary search tree; we'll take care of that today and write the insert function, as well as a height function. Both functions will be implemented in the "bst.h" header file, and tested using a provided main program in "main.cpp". Step one is to implement the insert function --- go ahead and modify "bst.h", adding the necessary code to (1) allocate a new node, and (b) link it into the tree. Once you...
Need someone to fix my code: #include<iostream> using namespace std; struct student { double firstQuizz; double...
Need someone to fix my code: #include<iostream> using namespace std; struct student { double firstQuizz; double secondQuizz; double midTerm; double finalTerm; string name; }; int main() { int n; cout<<"enter the number of students"<<endl; cin>>n; struct student students[n]; int i; struct student istudent; for(i=0;i<n;i++) {    cout<<"Student name?"; cin >> istudent.name; cout<<"enter marks in first quizz , second quizz , mid term , final term of student "<<i+1<<endl; cin>>students[i].firstQuizz>>students[i].secondQuizz>>students[i].midTerm>>students[i].finalTerm; } for(i=0;i<n;i++) { double marks=0; double score=students[i].firstQuizz+students[i].secondQuizz+students[i].midTerm+students[i].finalTerm; marks=(students[i].firstQuizz*0.25)+(students[i].secondQuizz*0.25)+(students[i].midTerm*0.25)+(students[i].finalTerm*0.50); double totalArrgegateMarks =...
Create a C++ project. Download and add the attached .h and .cpp to the project. Write...
Create a C++ project. Download and add the attached .h and .cpp to the project. Write an implementation file to implement the namespace declared in the attached CSCI361Proj5.h. Name the implementation file as YourNameProj5.cpp and add it to the project. Run the project to see your grade. .h file: // Provided by: ____________(your name here)__________ // Email Address: ____________(your email address here)________ // FILE: link.h // PROVIDES: A toolkit of 14 functions for manipulating linked lists. Each // node of...
c++ data structures linked list delete node bool deleteNode(int); pass this method an id to delete....
c++ data structures linked list delete node bool deleteNode(int); pass this method an id to delete. Return true or false to indicate success or failure. Delete the memory the node was using The algorithm for deleting a Node to a Linked List (general case): ● Begin at the head. ● Compare the id to the current node. ● If search id > current id, stop. ● Detach the current Node ○ current->previous->next = current->next ○ current->next->previous = current->previous ● Deallocate...
my code has several functions; delete and backward functions are not working, rewrite the code for...
my code has several functions; delete and backward functions are not working, rewrite the code for both functions and check them in the main: #include<iostream> #include<cassert> using namespace std; struct nodeType {    int info;    nodeType *link; }; class linkedList { public:    void initializeList();    bool isEmptyList();    void print();    int length();    void destroyList();    void insertFirst(int newItem);    void insertLast(int newItem);    int front();    linkedList();    void copyList(const linkedList otherList);    void insertNewValue(int value);...
a. Define the class bankAccount to store a bank customer’s account number and balance. Suppose that...
a. Define the class bankAccount to store a bank customer’s account number and balance. Suppose that account number is of type int, and balance is of type double. Your class should, at least, provide the following operations: set the account number, retrieve the account number, retrieve the balance, deposit and withdraw money, and print account information. Add appropriate constructors. b. Every bank offers a checking account. Derive the class checkingAccount from the class bankAccount (designed in part (a)). This class...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT