how to delete and edit?

this program is ok..i can add & save, i can search and display.but i want to put how to edit entry and how to delete..anyone knows how?


#include <iostream.h>
#include <conio.h>
#include <fstream.h>
#include <iomanip.h>
#include <stdlib.h>
int main()
{
char name[30];
double sn;
const int SIZE = 40 ;
char address[60],sec[SIZE],sex[SIZE],cnum[SIZE];
int choice;
double requestsn;



do
{
clrscr();
cout << "\n**************STUDENTS DATA*******************";
cout << "\n\n\n **[1] Add & Save Student's Info** " << endl;
cout << " **[2] Search & View Student's Info** " << endl;
cout << " **[3] Exit **"<< endl;
cout << " \n \nSelect what to do?: " << endl;
cin >> choice;


if (choice == 1)
{//open if 1
clrscr();
cout << "Please enter student name : ";
cin.ignore();
cin.getline(name,30);
cout << endl;
cout << "Please enter student number : ";
cin >> sn;
cout << endl;
cout << "Please enter student address : ";
cin.ignore();
cin.getline(address,60);
cout << endl;
cout << "Please enter student section : ";
cin >> sec;
cout << endl;
cout << "Please enter student gender: ";
cin >>sex;
cout << endl;
cout << "Please enter student contact number : ";
cin >> cnum;

ofstream outfile;
outfile.open("studentdata.txt",ios::app);

outfile << name << endl;
outfile << setprecision(12)<<sn << endl;
outfile << address << endl;
outfile << sec << endl;
outfile << sex << endl;
outfile << cnum << endl;


outfile.close();
cout << "Please press any key to continues... " << endl;
getch();



}//close if 1


if (choice == 2)
{ //open if 2
clrscr();
cout << "Please Input Student number : ";
cin >> requestsn;

clrscr();

ifstream infile;
infile.open("studentdata.txt");


while(!infile.eof() && infile != '\0')
{ //open while

infile.getline(name,30);
infile >> sn;
infile.ignore();
infile.getline(address,60);
infile >> sec;
infile >> sex;
infile >> cnum;
infile.ignore();


if(sn == requestsn)
{ //open if while 1
cout << "Name : ";
cout << name << endl;
cout << "Student Number : ";
cout << setprecision(12)<<sn << endl;
cout << "Address : ";
cout <<setprecision(40)<< address << endl;
cout << "Section : ";
cout << sec << endl;
cout << "Gender : ";
cout << sex << endl;
cout << "Contact Number : ";
cout << cnum << endl;

break; //terminate loop if sn is matching with request
} //close if while 1
} //close while
if(infile.eof() && sn != requestsn)
{//open if while 2
cout << "No such Student number " << endl;
} //close if while 2


infile.close();
cout << "Please press enter to continues... " << endl;
getch();

} //close if 2
}while (choice!=3);

if (choice == 3)
{
exit(1);
}


getch();
return 0;
}
Topic archived. No new replies allowed.