C++ Saved Program: placid-af

facebook share

Here's the online compiler accompanied with IDE at your service. This is a saved code by one of our users. Try it out or save your own from the IDE page and don't forget to leave a feedback. You can find that at the bottom of the page.


#include <iostream>
using namespace std;



class ACCOUNT
{
int Acno;float Balance;
char Name[20];

public:
	void Init()
	{
	cout<<"Enter number\n ";cin>>Acno;
	cout<<"Enter Name\n ";gets(Name);
	cout<<"Enter balance\n ";cin>>Balance;
	}

void Show()
	{
	cout<<"Number: "<<Acno<<endl;
	cout<<"Name: ";puts(Name);
	cout<<"balance: "<<Balance<<endl;
	}

void Deposit(int Amt)
	{
	Balance+=Amt;
	}
void Withdraw(int Amt)	{ Balance-=Amt;}
float RBalance(){ return Balance;}
int ra(){return Acno;}
};

void Register()
{
  fstream A("Accounts.dat",ios::binary|ios::out);
  ACCOUNT D;char ch;
 do
	{
	cout<<"Enter the details of accounts :"<<endl;
	D.Init();
	A.write((char*)&D,sizeof(D));
	cout<<"More ? y\n";cin>>ch;
	}while(ch=='y');
   A.close();
}

void Transact()
{
        fstream b;
      int a;   int choice; float g; int I=0,N;
cout<<"Enter Account no."<<endl;
cin>>a;
b.open("Accounts.dat",ios::binary|ios::in|ios::out);
ACCOUNT t;
while(b.read((char*)&t,sizeof(t)))
{               I++;
   if(t.ra()==a)
	{
	   N=I;
	    if(t.RBalance()>500)
		{
			cout<<"1.Deposit\n";
			cout<<"2.Withdraw\n";
			cin>>choice;
			   switch(choice)
			  {
			  case 1:  cout<<"Enter amount to be deposited";
				   cin>>g;
				   t.Deposit(g);
				   break;
			  case 2:  cout<<"Enter amount to be withdrawn";
				   cin>>g;
				   if (g<t.RBalance())
					cout<<"Not enough balance"<<endl;
				   t.Withdraw(g);
				   break;
			  default : cout<<"incorrect choice";
			  }
		     }
		       else
		       {
		       cout<<"Not enough balance";
		       cout<<endl;
		       }

     }
}
b.write((char*)&t,sizeof(t));
b.close();

}


void Displayall()
{
	ACCOUNT t;
	fstream A ("Accounts.dat",ios::binary|ios::in);
	   while(A.read((char*)&t,sizeof(t)))
		{   
             t.Show();
		}
  A.close();

}

void main()
{
                      clrscr();
	Register();
	Transact();
	Displayall();

getch();
}

	
	std::cout << "This is online C/C++ compiler" << std::endl;

}
Execute

Output

Press the execute button or CTRL + enter to run code.

Inputs