class bank_record {
int customer_no;
char customer_name[10];
float balance;
public :
void input_record();
void write_to_file(bank_record*);
int read_from_file(bank_record*,int);
/*------------------------------------------------------------------------------------------------------------------*/
int bank_record::read_from_file(bank_record *b2,int num){
int acct_num= num ;
ifstream for_output("bank_customer_record.txt",ios::binary);
for_output.seekg(0);
if ( ! for_output) {
cout << " Where is the file ??? Not getting it Bro \n ";
return -1;
}
else {
if ( acct_num == 0){
long position ;
cout <<" Here are the contents of the File";
while(for_output.read((char *) &b2,sizeof(class bank_record))) {
cout << " \n Customer Details";
position=for_output.tellg();
cout << " \n Position is " << position ;
cout << "\n Customer Number :"<< b2->customer_no << endl;
cout << "\n Customer Name :";
puts( b2->customer_name );
cout << endl;
cout << "\n Customer Balance :"<< b2->balance << endl;
}
for_output.close();
return 0;
}
else if ( acct_num == -1) {
while(for_output.read((char *) &b2,sizeof(class bank_record))) {
cout << "\n Customer Number :"<< b2->customer_no << endl;
cout << "\n Customer Name :";
puts( b2->customer_name );
cout << endl;
}
return 1 ;
}
else {
int flag=0;
while(for_output.read((char *) &b2,sizeof(class bank_record))) {
if (b2->customer_no == acct_num ) {
cout << "\n Customer Details";
cout << "\n Customer Account Number :"<< b2->customer_no << endl;
cout << "\n Customer Name :";
puts( b2->customer_name );
cout << endl;
cout << "\n Customer Balance :"<< b2->balance << endl;
for_output.close();
flag=1;
return 0;
}
}
for_output.close();
if ( flag==0) {
cout << " Wrong Account Number Entered \n ";
return -1;
}
}
}
void main () {
clrscr();
int choice,acct_num=0;
char cont_for_more[] ="y";
while ( strcmp(cont_for_more,"n")) {
cout << "Enter you choice 1. Add new account 2. Display All Account 3.Display Specific Account";
cout<< " 4. Modify the Record Deatils";
cin >> choice ;
switch(choice) {
case 1:
bank_record *bank_obj_ptr1=new bank_record;
bank_obj_ptr1->input_record();
bank_obj_ptr1->write_to_file(bank_obj_ptr1);
delete bank_obj_ptr1;
break;
case 2:
bank_record *bank_obj_ptr2=new bank_record;
bank_obj_ptr2->read_from_file(bank_obj_ptr2,0);
delete bank_obj_ptr2;
break;
case 3:
bank_record *bank_obj_ptr3=new bank_record;
if(! ( bank_obj_ptr3->read_from_file(bank_obj_ptr3, -1) == -1)) {
cout<< " Now Enter the account number whose info you want \n ";
cin >> acct_num ;
bank_obj_ptr3->read_from_file(bank_obj_ptr3, acct_num);
}
delete bank_obj_ptr3;
break;
case 4:
bank_record *bank_obj_ptr4=new bank_record;
if(! ( bank_obj_ptr4->read_from_file(bank_obj_ptr4, 0) == -1)) {
cout<< " Now Enter the account number whose info you want to modify \n";
cin >> acct_num ;
bank_obj_ptr4->modify_in_file(bank_obj_ptr4, acct_num);
}
delete bank_obj_ptr4;
break;