Question

in this coding please add an address for the student to enter... note that this coding...

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

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

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...
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
  • 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...

  • Based on this program modify the source code so that it will able to save the student record into a database txt and able to display and modify from a database txt as well. you will also need to able...

    Based on this program modify the source code so that it will able to save the student record into a database txt and able to display and modify from a database txt as well. you will also need to able to modify the code so it will accept name such as "john kenny " and the progrom should also ask for the student id number. #include<iostream> #include<stdlib.h> using namespace std; struct st { int roll; char name[50]; char grade; struct...

  • Add additional information to the student class below such as name, address, major, and contact information...

    Add additional information to the student class below such as name, address, major, and contact information along with all the getters and setters (methods) needed to access all data. Submit your code along with a sample run of your program. Comment all your code. Cite any sources of information you use. Write a note on the process of completing the assignment in a Microsoft Word document. // ShowStudent.java // client to test the Student class class ShowStudent { public static...

  • Add additional information to the student class below such as name, address, major, and contact information...

    Add additional information to the student class below such as name, address, major, and contact information along with all the getters and setters (methods) needed to access all data. Submit your code along with a sample run of your program. Comment all your code. Cite any sources of information you use. Write a note on the process of completing the assignment in a Microsoft Word document. // ShowStudent.java // client to test the Student class class ShowStudent { public static...

  • Using Python. 3) Create a single-linked list (StudentList) where the data in the link is an object of type pointer to Student as defined below. Note that you need to store and pass a pointer of type...

    Using Python. 3) Create a single-linked list (StudentList) where the data in the link is an object of type pointer to Student as defined below. Note that you need to store and pass a pointer of type Student so that you do not create duplicate objects. Test your list with the provided program. You will find example code for a single-linked list of integers in Moodle that you can base your solution on. For your find methods, you can either...

  • I need to add a method high school student, I couldn't connect high school student to...

    I need to add a method high school student, I couldn't connect high school student to student please help!!! package chapter.pkg9; import java.util.ArrayList; import java.util.Scanner; public class Main { public static Student student; public static ArrayList<Student> students; public static HighSchoolStudent highStudent; public static void main(String[] args) { int choice; Scanner scanner = new Scanner(System.in); students = new ArrayList<>(); while (true) { displayMenu(); choice = scanner.nextInt(); switch (choice) { case 1: addCollegeStudent(); break; case 2: addHighSchoolStudent(); case 3: deleteStudent(); break; case...

  • Write program in C. Please ask the user to determine how many numbers to enter, and...

    Write program in C. Please ask the user to determine how many numbers to enter, and then find and display the largest one with two digits. Please call the following two functions in your main functions. void input_numbers(float *data, int num); void find_largest(float *data, int num); Note: In this assignment, please save the entered numbers using pointer, pass the pointer as the arguments. Depending upon the number of elements, the required size is allocated which prevents the wastage of memory....

  • Using Java coding, complete the following: This program should implement a LinkedList data structure to handle...

    Using Java coding, complete the following: This program should implement a LinkedList data structure to handle the management of student records. It will need to be able to store any number of students, using a Linked List. LinearNode.java can be used to aid creating this program Student should be a class defined with the following:    • String name    • int year    • A linked list of college classes (college classes are represented using strings)    • An...

  • I need code in java The Student class: CODE IN JAVA: Student.java file: public class Student...

    I need code in java The Student class: CODE IN JAVA: Student.java file: public class Student {    private String name;    private double gpa;    private int idNumber;    public Student() {        this.name = "";        this.gpa = 0;        this.idNumber = 0;    }    public Student(String name, double gpa, int idNumber) {        this.name = name;        this.gpa = gpa;        this.idNumber = idNumber;    }    public Student(Student s)...

  • Q) Modify the class Linked List below to make it a Doubly Linked List. Name your...

    Q) Modify the class Linked List below to make it a Doubly Linked List. Name your class DoublyLinkedList. Add a method addEnd to add an integer at the end of the list and a method displayInReverse to print the list backwards. void addEnd(int x): create this method to add x to the end of the list. void displayInReverse(): create this method to display the list elements from the last item to the first one. Create a main() function to test...

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