Question

in this coding please add an address for the student to enter... note that this coding use linked list and a file text t...

in this coding please add an address for the student to enter... note that this coding use linked list and a file text to store its data ...Please make sure the address will work with all the functions below..to check whether your coding is correct after you finished adding a new dummy student data and its information close the program and reopen it and choose the option 5 ... I've tried adding an address before but an error occurred when I reopen the program and enter option 5

int addStudent();

void display();

int update();

int search();

void save();

void read();

my coding is in the link below

https://docdro.id/2p3LNsA

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Screenshot

uick Launch (Ci+a sual Stucio Fie Feit w Pmjert Build Dehug Team Toele Tet Anaye Windew Help #include <iostream> 6 #1 nclude----------------------------------------------

Program

#include <iostream>
#include <stdlib.h>
#include <fstream>
#include <string>
#include <windows.h>
using namespace std;
struct st
{
   string id;
   char name[50];
   char grade;
   string phone;
   string dateofbirth;
   char address[100];
   struct st* next;
};
struct st* hptr = 0; // declare null header of linked list
int addStudent();
int delete_student();
void display();
int update();
int search();
void save();
void read();
void logo();
int main()
{
   logo();
   char ch;
   int opt;
   ifstream file("database.txt");
   if (!file) {
       goto shortcut;
   }
   else
       read();
   do
   {
   shortcut:
       cout << "\nChoose option :\n\n"
           "============================================\n"
           "\n\t1.Add Student\n"
           "\t2.Remove Student\n"
           "\t3.Update Student Information\n"
           "\t4.Search Student\n"
           "\t5.Display Records\n"
           "\n ======================================"
           << endl;
       cin >> opt;
       cout << endl;
       if (opt == 1) {
           addStudent();
           save();
       }
       else if (opt == 2) {
           delete_student();
           save();
       }
       else if (opt == 3) {
           update();
           save();
       }
       else
           if (opt == 4) {
               search();
           }
           else if (opt == 5) {
               display();
           }
           else {
               cout << "Invaild Option, Try again...!\n";
               cout << "\n" << endl;
               system("pause");
               system("CLS");
               main();
           }
       cout << "Do you wants another operation(y/n)? : ";
       cin >> ch;
   } while (ch == 'Y' || ch == 'y');
}
/* Add Student */
int addStudent()
{
   st* temp = new st;
   st* temp1 = new st;
   cout << "Enter student ID :";
   cin >> temp-> id;
   cout << "Enter name:";
   cin.ignore();
   cin.getline(temp-> name, 50, '\n');
     cout << "Enter grade:";
   cin >> temp-> grade;
   cout<< "Enter phone number: ";
   cin >> temp-> phone;
   cout << "Enter date of birth [day/month/year]: ";
   cin >> temp-> dateofbirth;
   cout << "Enter address: ";
   cin.ignore();
   cin.getline(temp->address, 100, '\n');
   // Head of linked list is null
   if (hptr == 0)
   {
       temp-> next = hptr;
       hptr = temp;
       return 0;
   }
   else
   {
       temp1 = hptr;
       while (temp1-> next)
           temp1 = temp1-> next;
       temp-> next = temp1-> next; //NULL
       temp1-> next = temp;
       return 0;
   }
   return -1;
}
/* Delete Student */
int delete_student()
{
   string idno;
   st* temp = new st;
   st* temp1 = new st;
   cout << "Do you want to delete a record ,then enter student ID : ";
   cin >> idno;
   temp = hptr;
   while (temp)
   {
       if (temp-> id == idno)
       {
           // searching record is head
           if (temp == hptr)
           {
               hptr = temp-> next;
               free(temp);
               return 0;
           }
           else
           {
               temp-> next = temp-> next;
               free(temp);
               return 0;
           }
       }
       temp1 = temp;
       temp = temp-> next;
   }
   cout << "Record is not found..!\n";
   return -1;
}
/* Update the grade of the st
udent */
int update()
{
   string idno;
   st* temp = new st;
   st* temp1 = new st;
   cout << "Enter student ID :";
   cin >> idno;
   temp = hptr;
   while (temp)
   {
       if (temp-> id == idno)
       {
           cout<< "Enter grade to update:";
           cin >> temp-> grade;
           cout << "Enter phone number to update:";
           cin >> temp-> phone;
           cout << "Enter address to update: ";
           cin.ignore();
           cin.getline(temp->address, 100, '\n');
           return 0;
       }
       temp1 = temp;
       temp = temp-> next;
   }
   cout<< "Record not found..!\n";
   return -1;
}
/* search the student */
int search()
{
   string idno;
   st* temp = new st;
   st* temp1 = new st;
   cout << "Enter student ID :";
   cin >> idno;
   temp = hptr;
   cout<< "|Student ID .\n | Name\n | Grade\n | Phone number\n | Date of birth\n | Address" << endl;
   cout << "------------------------------------------ -\n";
       while (temp)
       {
           if (temp-> id == idno)
           {
               cout << temp-> id << "\n" << temp-> name << "\n" << temp-> grade << "\n" <<temp-> phone << "\n" << temp-> dateofbirth << "\n" <<temp->address<<"\n"<<endl;
cout << "------------------------------------------------ -"<<endl;
return 0;
           }
           temp1 = temp;
           temp = temp-> next;
       }
   cout << "Record is not present..!\n";
}
/* Display the record */
void display()
{
   system("cls");
   cout << "|Student ID.\n | Name\n | Grade\n | Phone number\n | Date of birth\n | Address" << endl;
   cout<< "------------------------------------------ -\n";
   struct st* ptr;
   ptr = hptr;
   while (ptr)
   {
       cout << ptr-> id << "\n" << ptr-> name << "\n"<< ptr-> grade << "\n" << ptr-> phone<< "\n" << ptr->dateofbirth << "\n"<<ptr->address<<"\n"<<endl;
cout << "------------------------------------------------ -"<<endl;
ptr = ptr-> next;
   }
}
void save()
{
   // stores the current data of linked list in database.txt
   ofstream fout("database.txt");
   struct st* ptr;
   ptr = hptr;
   while (ptr)
   {
       fout << ptr-> id << "\n" << ptr-> name << "\n" << ptr-> grade << "\n" << ptr-> phone<< "\n"<<ptr-> dateofbirth << "\n"<<ptr->address<<"\n";
ptr = ptr-> next;
   }
}
void read()
{
   // reads from file database.txt
   // keeps reading till end of file.
       // stores the data in the currect linked list.
       // you can use display() to view data that is read from database.txt.
       ifstream fin("database.txt");
   string id;
   while (fin >> id) {
       st* temp = new st;
       st* temp1 = new st;
       temp-> id = id;
       fin.ignore();
       fin.getline(temp-> name, 49, '\n');
fin >> temp-> grade;
       fin >> temp-> phone;
       fin >> temp-> dateofbirth;
       fin.ignore();
       fin.getline(temp->address, 99, '\n');
       // Head of linked list is null
           if (hptr == 0)
           {
               temp-> next = hptr;
               hptr = temp;
           }
           else
           {
               temp1 = hptr;
               while (temp1-> next)
                   temp1 = temp1-> next;
               temp-> next = temp1-> next; //NULL
               temp1-> next = temp;
           }
   }
}
void logo()
{
   system("COLOR 0E");
   cout << "\n\n\n\n";
       cout<< "\t\t======================================== = " << endl;
       string hello = "\n\n\t\t WELCOME TO STUDENT MANAGMENT SYSTEM ";
       int x = 0;
   while (hello[x] != '\0') {
       cout << hello[x];
   if (hello[x] != ' ' && hello[x] != '\n')
       Sleep(50);
       x++;
};
cout << "\n\n\t\t======================================== = " << endl;
cout << "\n";

system("pause");
   system("COLOR 07");
   system("cls");
   }

-------------------------------------------

Output(After exit then restart application and press 5)

|Student ID.
| Name
| Grade
| Phone number
| Date of birth
| Address
------------------------------------------ -
2
Mia Mark
A
457896
05/05/2001
#403,block 3,RTSD

------------------------------------------------ -
Do you wants another operation(y/n)? : n

Add a comment
Know the answer?
Add Answer to:
in this coding please add an address for the student to enter... note that this coding use linked list and a file text t...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT