Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Bookmarks window Help 0 When the user runs the program, they shall be greeted wi

ID: 3705295 • Letter: B

Question

Bookmarks window Help 0 When the user runs the program, they shall be greeted with a menu of options like what is shown selects "E" to exit (at which point the program shall stop). below. This menu shall be repeated to the user (over and over) unal the user tinaly Fees Pai like to do (h-Add record to 1 W-Write al1 records prompted to enter a struct (record), this record shall be added to the end of your struct list, and a report shall be record that was just added to the end of the list printod that shows the ne user chooses "W", the program shall write all the structs (one struct per line) to a text file. ?ifthe user chooses ?, the program shall read allthe struct data from a text fle (one line holds one struct). This operaen st al replace to ament struct array. Then, the program shall print a report showing all the struct data Gust read from the text file). Design Specifications Your program shall meet the following design and coding specifications 1. The top of the program shall contain these comments: o homework name ('Text File") o your name and the date you completed your program file that contains my input functions but this is not 2. Remember to include the two header files that provide String functionality. I also recommend that you reference a header mandatory #ine lude tring.b finelude

Explanation / Answer

#include<fstream.h>

#include<stdio.h>

#include<string.h>

#include<conio.h>

#include<process.h>

using namespace std;

class filedetails

{

private:

int roll;

float age;

char name[100];

public:

void input();

void show();

char *getn()

{

return name;

}

};filedetails filedetailsobj;

void filedetails::input()

{

cout<<"Enter the roll, Age and name :";

cin>>roll>>age;

gets(name);

}

void filedetails::show()

{

cout<<"Roll==> "<<roll<<endl;

cout<<"Age ==> "<<age<<endl;

cout<<"Name==> "<<name<<endl;

}

void CreateRecord();

void AddRecord();

void DisplayRecord();

void DisplayRecordP();

void ModifyRecord();

void DeleteRecord();

fstream fil;

int main()

{

int opt;

while(1)

{

clrscr();

cout<<"1.CreateRecord Data filedetails"<<endl;

cout<<"2.AddRecord New Record in Data filedetails"<<endl;

cout<<"3.DisplayRecord Record From Data filedetails"<<endl;

cout<<"4.DisplayRecord Particular Record From Data filedetails"<<endl;

cout<<"5.ModifyRecord Paricular Record From Data filedetails"<<endl;

cout<<"6.DeleteRecord Particular Record From Data filedetails"<<endl;

cout<<"7.Exit From the Program"<<endl;

cout<<"Enter your Option : "<<endl;

cin>>opt;

switch(opt)

{

case 1:

{

CreateRecord();

cout<<"DisplayRecord Main Menu"<<endl;

getch();

break;

}

case 2:

{

AddRecord();

cout<<"DisplayRecord Main Menu"<<endl;

getch();

break;

}

case 3:

{

DisplayRecord();

cout<<"DisplayRecord Main Menu"<<endl;

getch();

break;

}

case 4:

{

DisplayRecordP();

cout<<"DisplayRecord Main Menu"<<endl;

getch();

break;

}

case 5:

{

ModifyRecord();

cout<<"DisplayRecord Main Menu"<<endl;

getch();

break;

}

case 6:

{

DeleteRecord();

cout<<"DisplayRecord Main Menu"<<endl;

getch();

break;

}

case 7:

{

exit(0);

}

default:

{

cout<<"Wrong Choice....Press Key For View the Main Menu";

getch();

clrscr();

}

}

}

}

void CreateRecord() //Function to CreateRecord Data filedetails

{

char ch='y';

fil.open("binary.dat",ios::out| ios::binary);

while(ch=='y' || ch =='Y')

{

filedetailsobj.input();

fil.write((char*)&filedetailsobj, sizeof(filedetailsobj));

cout<<"Want to Continue.....";

cin>>ch;

}

fil.close();

}

void AddRecord() //Function to AddRecord New Record in Data filedetails

{

char ch='y';

fil.open("binary.dat",ios::app| ios::binary);

while(ch=='y' || ch =='Y')

{

filedetailsobj.input();

fil.write((char*)&filedetailsobj, sizeof(filedetailsobj));

cout<<"Want to Continue.....";

cin>>ch;

}

fil.close();

}

void DisplayRecord() //Function to DisplayRecord All Record from Data filedetails

{

fil.open("binary.dat",ios::in| ios::binary);

if(!fil)

{

cout<<"filedetails not Found";

exit(0);

}

else

{

fil.read((char*)&filedetailsobj, sizeof(filedetailsobj));

while(!fil.eof())

{

filedetailsobj.show();

cout<<"Press Any Key....For Next Record"<<endl;

getch();

fil.read((char*)&filedetailsobj, sizeof(filedetailsobj));

}

}

fil.close();

}

void DisplayRecordP() //Function to DisplayRecord particular Record from Data filedetails

{

char n[100];

cout<<"Enter Name that should be searched:";

gets(n);

fil.open("binary.dat",ios::in| ios::binary);

if(!fil)

{

cout<<"filedetails not Found";

exit(0);

}

else

{

fil.read((char*)&filedetailsobj, sizeof(filedetailsobj));

while(!fil.eof())

{

if(strcmp(n,filedetailsobj.getn())==0)

{

filedetailsobj.show();

cout<<"Press Any Key...."<<endl;

getch();

}

else

{

cout<<"Press Any Key....For Search"<<endl;

getch();

}

fil.read((char*)&filedetailsobj, sizeof(filedetailsobj));

}

}

fil.close();

}

void ModifyRecord() //Function to ModifyRecord Particular Record from Data filedetails

{

char n[100];

cout<<"Enter Name that should be searched:";

gets(n);

fil.open("binary.dat",ios::in| ios::out|ios::binary);

if(!fil)

{

cout<<"filedetails not Found";

exit(0);

}

else

{

fil.read((char*)&filedetailsobj, sizeof(filedetailsobj));

while(!fil.eof())

{

if(strcmp(n,filedetailsobj.getn())==0)

{

fil.seekg(0,ios::cur);

cout<<"Enter New Record.."<<endl;

filedetailsobj.input();

fil.seekp(fil.tellg() - sizeof(filedetailsobj));

fil.write((char*)&filedetailsobj, sizeof(filedetailsobj));

}

else

{

cout<<"Press Any Key....For Search"<<endl;

getch();

}

fil.read((char*)&filedetailsobj, sizeof(filedetailsobj));

}

}

fil.close();

}

void DeleteRecord() //Function to DeleteRecord Particular Record from Data filedetails

{

char n[100];

cout<<"Enter Name that should be DeleteRecordd :";

gets(n);

ofstream o;

o.open("new.dat",ios::out|ios::binary);

fil.open("binary.dat",ios::in| ios::binary);

if(!fil)

{

cout<<"filedetails not Found";

exit(0);

}

else

{

fil.read((char*)&filedetailsobj, sizeof(filedetailsobj));

while(!fil.eof())

{

if(strcmp(n,filedetailsobj.getn())!=0)

{

o.write((char*)&filedetailsobj, sizeof(filedetailsobj));

}

else

{

cout<<"Press Any Key....For Search"<<endl;

getch();

}

fil.read((char*)&filedetailsobj, sizeof(filedetailsobj));

}

}

o.close();

fil.close();

remove("binary.dat");

rename("new.dat", "binary.dat");

}//end of program

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote