Need help! My C++ Program doesn't work when I ran the program especially in Adding, Searching and Deleting a record. What seems to be the error in the code? #include #include #include #include...



Need help! My C++ Program doesn't work when I ran the program especially in Adding, Searching and Deleting a record. What seems to be the error in the code?


#include
#include
#include
#include
#include
using namespace std;
bool check = true;
struct node    //structure of node //
{
 int rollNo;
  char name[20];
  char address[40];
  char gender[20];
  char department[20];
 int year;
  char dob[20];
  node *next;
}*head,*lastptr;


void add()    //Adds record of student//
{
 node *p;
 p=new node;
 cout<"enter id="" number="" of=""><>
 cin>>p->rollNo;
 fflush(stdin);
 cout<"enter name="" of=""><>
 gets(p->name);
 fflush(stdin);
 cout<"enter address="" of=""><>
 gets(p->address);
 fflush(stdin);
 cout<"enter birthday="" of=""><>
 gets(p->dob);
 fflush(stdin);
 cout<"enter gender="" of=""><>
 gets(p->gender);
 fflush(stdin);
 cout<"enter department="" of=""><>
 gets(p->department);
 fflush(stdin);
 cout<"enter training="" year="" of=""><>
 cin>>p->year;
 fflush(stdin);
 p->next=NULL;


 if(check)
 {
  head = p;
  lastptr = p;
  check = false;
 }
 else
 {
  lastptr->next=p;
  lastptr=p;
 }



//  Writing data to file -------------------------------------------------------


// Remove the '------' lines if not required


  ofstream file("student_data.txt");


  file<><>


  file<"student id:="">rollNo<>


  file<"student name:="">name<>


  file<"student address:="">address<>


  file<"student dob:="">dob<>


  file<"student gender:="">gender<>


  file<"student department:="">department<>


  file<"student training="" year:="">year<>


  file<><><><>


 // ------------------------------


 cout<><"recored><>
}
void modify()   //modifies record of student//
{
 node *ptr;
 node *prev=NULL;
 node *current=NULL;
 int roll_no;
 cout<"enter id="" number="" to=""><>
 cin>>roll_no;
 prev=head;
 current=head;
 while(current->rollNo!=roll_no)
 {
  prev=current;
  current=current->next;
 }
 ptr=new node;
 fflush(stdin);

  cout<"enter id="" number="" of=""><>
 cin>>ptr->rollNo;
 fflush(stdin);
 cout<"enter name="" of=""><>
 gets(ptr->name);
 fflush(stdin);
 cout<"enter address="" of=""><>
 gets(ptr->address);
 fflush(stdin);
 cout<"enter birthday="" of=""><>
 gets(ptr->dob);
 fflush(stdin);
 cout<"enter gender="" of=""><>
 gets(ptr->gender);
 fflush(stdin);
 cout<"enter department="" of=""><>
 gets(ptr->department);
 fflush(stdin);
 cout<"enter training="" year="" of=""><>
 cin>>ptr->year;
 fflush(stdin);
 prev->next=ptr;
 ptr->next=current->next;
 current->next=NULL;
 delete current;
 cout<><"recored>
}
void search()   //searches record of student//
{
 node *prev=NULL;
 node *current=NULL;
 int roll_no;
 cout<"enter id="" number="" to=""><>
 cin>>roll_no;
 prev=head;
 current=head;
 while(current->rollNo!=roll_no)
 {
  prev=current;
  current=current->next;
 }


 cout<"\nid>
 coutrollNo;
 cout<"\nname:>
 puts(current->name);
 cout<"\naddress:>
 puts(current->address);
 cout<"\ngender:>
 puts(current->gender);
 cout<"\ndepartment:>
 puts(current->department);
 cout<"\nyear:>
 coutyear;
 cout<"\ndate of="" birth:="">
 puts(current->dob);
}
void del()
{
 node *ptr=NULL;
 node *prev=NULL;
 node *current=NULL;
 int roll_no;
 cout<"enter id="" number="" to=""><>
 cin>>roll_no;
 prev=head;
 current=head;
 while(current->rollNo!=roll_no)
 {
  prev=current;
  current=current->next;
 }
 prev->next = current->next;
 current->next=NULL;
 delete current;
 cout<><"recored>
}


int main()
{
 int x;


 do
 {
  cout<"1--->Press '1' to add New record:"<>
  cout<"2--->Press '2' to search a record:"<>
  cout<"3--->Press '3' to modify a record:"<>
  cout<"4--->Press '4' to delete a record:"<>
  cout<"5--->Press '5' to exit:"<>
  cin>>x;
  switch(x){
   case 1:
    system("cls");
     add();
     break;
    case 2:
     system("cls");
     search();
     break;
    case 3:
     system("cls");
     modify();
     break;
    case 4:
     system("cls");
     del();
     break;
    case 5:
     exit(0);
     break;
    default:
     cout<"enter a="" valid="" option.="">
     break;
  }
 }while(1);
}

Jun 09, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here