0% found this document useful (0 votes)
258 views

Atm Code

This C++ program defines account and login structures to store bank account and user login information. It creates sample account objects, opens a file called "login.txt" for writing, and writes the account objects to the file. It then reopens the file for reading, seeks to the third record, reads it into a new account object, and prints out some of its fields and the size to verify the read. The program allows storing multiple account records in a binary file.

Uploaded by

Anika Sadiq
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
258 views

Atm Code

This C++ program defines account and login structures to store bank account and user login information. It creates sample account objects, opens a file called "login.txt" for writing, and writes the account objects to the file. It then reopens the file for reading, seeks to the third record, reads it into a new account object, and prints out some of its fields and the size to verify the read. The program allows storing multiple account records in a binary file.

Uploaded by

Anika Sadiq
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <iostream>

#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
////////////////////////////////////////////////////////
struct account
{
int acct_no;
char holder_name[25];
char status[9];
char acct_type[8];
double balance;
};
////////////////////////////////////////////////////////
struct login
{
char login_id[11];
char holder_name[25];
char pin_code[6];
int a;
};
////////////////////////////////////////////////////////
void create_new_file(fstream&,login&);
int main()
{string s1;
account holder_2={20,"sana","active","current",10000};
account
account
account
account
fstream

holder_1={23,"sana","active","current",100};
holder_4={2055,"ssba","active","current",4222};
holder_3={20,"nida","active","current",150000};
holder_5={20,"amina","active","savings",100800};
create_file("login.txt",ios::out);

if(create_file.is_open())
{
create_file.write(reinterpret_cast<const char*>(&holder_2),sizeof(account));
create_file.write(reinterpret_cast<const char*>(&holder_1),sizeof(account));
create_file.write(reinterpret_cast<const char*>(&holder_3),sizeof(account));
create_file.write(reinterpret_cast<const char*>(&holder_4),sizeof(account));
create_file.write(reinterpret_cast<const char*>(&holder_5),sizeof(account));
create_file.write(reinterpret_cast<const char*>(&holder_1),sizeof(account));
create_file.write(reinterpret_cast<const char*>(&holder_2),sizeof(account));
create_file.write(reinterpret_cast<const char*>(&holder_5),sizeof(account));
}
else
{

cerr<<"file could not be opened.\n";


exit(1);}
create_file.close();
ifstream create_fil("login.txt",ios::in);
create_fil.seekg((sizeof(account))*2,ios::beg);
account holder_6;
create_fil.read(reinterpret_cast<char*>(&holder_6),sizeof(account));
cout<<holder_6.acct_no<<holder_6.acct_type<<holder_6.balance;
cout<<endl<<sizeof(holder_6);
create_fil.close();
return 0;}
//---------------------------------------------------

You might also like