1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
#include<conio.h>
#include<fstream.h>
#include<iostream.h>
#include<limits.h>
class customer
{
char city[21];
char state[21];
char name[51];
char email[81];
char username[13];
char password[13];
char question[51];
char answer[51];
public :
void getdetails();
void showdetails();
};
void customer::getdetails()
{
cout<<" Enter Your Full Name (Max 50 chars): ";
cin.getline(name,51);
cout<<"\n\n Enter e-mail (Max 80 chars): ";
cin.getline(email,81);
cout<<"\n\n Enter City (Max 20 chars ): ";
cin.getline(city,21);
cout<<"\n\n Enter State (Max 20 Chars): ";
cin.getline(state,21);
cout<<"\n\n Enter Username (Max 12 chars) : ";
cin.getline(username , 13);
cout<<"\n\n Password : ";
cin.getline(password , 13);
cout<<"\n\n Enter Secret question : ";
cin.getline(question,51);
cout<<"\n\n Enter Answer : ";
cin.getline(answer, 51);
cout<<"\n\n\t\t\t\t Thank You ";
cout<<"\n\n\t\t\t PRESS ANY KEY TO CONTINUE ";
getch();
}
void customer::showdetails()
{
cout<<"\nName : "; puts(name);
cout<<"E-mail : "; puts(email);
cout<<"City : "; puts(city);
cout<<"State : "; puts(state);
cout<<"Username : "; puts(username);
cout<<"Password : "; puts(password);
cout<<"Question : "; puts(question);
cout<<"Answer : "; puts(answer);
}
void main()
{
clrscr();
customer obj;
int ch;
cout<<" 1. Enter details ";
cout<<" 2. View Details ";
cin>>ch;
cin.ignore( std::numeric_limits<std::streamsize>::max() , '\n');
if(ch==1)
{
clrscr();
obj.getdetails();
clrscr();
cout<<"Here is what you entered "<<endl<<endl;
obj.showdetails();
getch();
ofstream abc;
abc.open("customer.txt" , ios::app);
abc.write( (char*)&obj , sizeof(obj) );
}
if(ch==2)
{
ifstream abc;
abc.open("customer.txt" , ios::in);
abc.seekg(0); // to go to beggining of the file
while(abc) // to read the whole file
{
abc.read( (char*)&obj , sizeof(obj) );
cout<<"\n\nDetails of object";
obj.showdetails();
}
abc.close();
}
getch();
}
|