Define a class to represent a bank account. Include the
following
members:
Data Members:
Name of the Depositor
Account Number
Type of Account
Balance amount in the account

Member Functions:
To assign the initial values.
To deposit an account.
To withdraw an amount after checking the balance.

Write a C++ main program to display account number,
name and
balance.

Answers were Sorted based on User's Feedback



Define a class to represent a bank account. Include the following members: ..

Answer / arun

#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<process.h>


// statement of customer detail....

struct acc_inf
{
char c_name[25];
int acc_no;
float balance;
char acc_type[7];

};

//statement of Class....

class bank
{
struct acc_inf x;
public:
void input();
void withdrawal(int,float);
void deposit(int,float);
void display(int);

};

// Statement of customer information...

void bank:: input()
{
cout<<endl<<" Enter the name of customer:- ";
gets(x.c_name);
cout<<" Enter account no:- ";
cin>>x.acc_no;
cout<<" Enter opening balance:- ";
cin>>x.balance;
cout<<" Enter acc_type (SAVING/CURRENT):- ";
gets(x.acc_type);
}

//Statement of Withdrawal function...

void bank::withdrawal(int ac,float money)
{
if(x.acc_no==ac)
{
if(x.balance-1000>=money)
x.balance -= money;
else
cout<<"Sorry, Insufficient Balance";
}
else
cout<<"** Sorry, Account no. is not found ** ";
}

// Statement of deposite function...

void bank::deposit(int ac,float money)
{
if(ac==x.acc_no)
x.balance += money;
else
cout<<"Sorry, Account no. is not found...";
}

// Statement of display Funtion...

void bank::display(int ac)
{
if(ac==x.acc_no)
{
cout<<"\nYour acc_no is: "<<x.acc_no;
cout<<"\nYour name is: ";
puts(x.c_name);
cout<<"\nYour current balance is: "<<x.balance;
cout<<"\nYour type of account is: "<<x.acc_type;
}
}

// statement of main Function....

main()
{

bank obj; //creating object for class bank
int ac;
float money;
int c;
clrscr();
do
{
clrscr();
cout<<endl<<"Welcome to Banking System";
cout<<"\n_________________________";
cout<<endl<<endl<<"1:Open New Account of the customer.";
cout<<endl<<"2:Withdrawal the money.";
cout<<endl<<"3:Deposit the money.";
cout<<endl<<"4:Display information about customer.";
cout<<endl<<"5:quit";
cout<<endl<<"what is your choice: ";
cin>>c;

switch(c)
{
case 1:
obj.input();
break;
case 2:
cout<<"Enter account no: ";
cin>>ac;
cout<<"enter the money to withdrawal: ";
cin>>money;
obj.withdrawal(ac,money);
break;
case 3:

cout<<"enter acc no: ";
cin>>ac;
cout<<"enter the money to deposit: ";
cin>>money;
obj.deposit(ac,money);
break;
case 4:
cout<<"enter acc no: ";
cin>>ac;
obj.display(ac);
break;
case 5:
exit(0);
default:
cout<<"Sorry, unable to process.. Try again later";
}
cout<<"Press Enter to continue...";
getch();

}while(c!=5);

return 0;
}

Is This Answer Correct ?    55 Yes 25 No

Define a class to represent a bank account. Include the following members: ..

Answer / mayur

#include <iostream.h>
#include <iomanip.h>
#include <conio.h>
class bank
{
char name[20];
int acno;
char actype[20];
int bal;
public :
void opbal(void);
void deposit(void);
void withdraw(void);
void display(void);
};

void bank :: opbal(void)
{
cout<<endl<<endl;
cout<<"Enter Name :-";
cin>>name;
cout<<"Enter A/c no. :-";
cin>>acno;
cout<<"Enter A/c Type :-";
cin>>actype;
cout<<"Enter Opening Balance:-";
cin>>bal;
}







void bank :: deposit(void)
{
cout<<"Enter Deposit amount :-";
int deposit=0;
cin>>deposit;
deposit=deposit+bal;
cout<<"\nDeposit Balance = "<<deposit;
bal=deposit;
}
void bank :: withdraw(void)
{
int withdraw;
cout<<"\nBalance Amount = "<<bal;
cout<<"\nEnter Withdraw Amount :-";
cin>>withdraw;
bal=bal-withdraw;
cout<<"After Withdraw Balance is "<<bal;
}

void bank :: display(void)
{
cout<<endl<<endl<<endl;
cout<<setw(50)<<"DETAILS"<<endl;
cout<<setw(50)<<"name "<<name<<endl;
cout<<setw(50)<<"A/c. No. "<<acno<<endl;
cout<<setw(50)<<"A/c Type "<<actype<<endl;
cout<<setw(50)<<"Balance "<<bal<<endl;
}

void main()
{
clrscr();
bank o1;
int choice;
do
{
cout<<"\n\nChoice List\n\n";
cout<<"1) To assign Initial Value\n";
cout<<"2) To Deposit\n";
cout<<"3) To Withdraw\n";
cout<<"4) To Display All Details\n";
cout<<"5) EXIT\n";
cout<<"Enter your choice :-";
cin>>choice;






switch(choice)
{
case 1: o1.opbal();
break;
case 2: o1.deposit();
break;
case 3: o1.withdraw();
break;
case 4: o1.display();
break;
case 5: goto end;
}
}while(1);
end:
}

Is This Answer Correct ?    40 Yes 32 No

Define a class to represent a bank account. Include the following members: ..

Answer / akash jadhav

#include<iostream.h>
#include<conio.h>
#include<string.h>
class bank
{
char name[20];
int ano;
char atype[20];
float bal;
public:
void get(int no,char *n,char *t,float b)
{
strcpy(name,n);
ano=no;
strcpy(atype,t);
bal=b;
}
float deposit()
{
float amt;
cout<<“
Enter amount: “;
cin>>amt;
bal=bal+amt;
return bal;
}
float withdrw()
{
float amt;
cout<<“
How many Rupees withdraw: “;
cin>>amt;
bal=bal-amt;
return bal;
}
void disp()
{
cout<<“

Account number: “<<ano;
cout<<“

Name: “<<name;
cout<<“

Account type: “<<atype;
cout<<“

Deposit Amount: “<<deposit();
cout<<“

After Withdraw Amount balnace: “<<withdrw();
}
};
void main()
{
int n;
char nm[20],t[20];
float a;
bank bk;
clrscr();
cout<<“
Enter Account no.: “; cin>>n;
cout<<“
Enter Name: “; cin>>nm;
cout<<“
Enter account type: “; cin>>t;
cout<<“
Enter balance amount: “;cin>>a;
bk.get(n,nm,t,a);
bk.disp();
getch();
}

Is This Answer Correct ?    6 Yes 2 No

Define a class to represent a bank account. Include the following members: ..

Answer / prashant kumar

#include<iostream>
#include<stdio.h>
#include<string.h>

using namespace std;

class bank
{
int acno;
char nm[100], acctype[100];
float bal;
public:
bank(int acc_no, char *name, char *acc_type, float balance) //Parameterized Constructor
{
acno=acc_no;
strcpy(nm, name);
strcpy(acctype, acc_type);
bal=balance;
}
void deposit();
void withdraw();
void display();
};
void bank::deposit() //depositing an amount
{
int damt1;
cout<<"
Enter Deposit Amount = ";
cin>>damt1;
bal+=damt1;
}
void bank::withdraw() //withdrawing an amount
{
int wamt1;
cout<<"
Enter Withdraw Amount = ";
cin>>wamt1;
if(wamt1>bal)
cout<<"
Cannot Withdraw Amount";
bal-=wamt1;
}
void bank::display() //displaying the details
{
cout<<"
----------------------";
cout<<"
Accout No. : "<<acno;
cout<<"
Name : "<<nm;
cout<<"
Account Type : "<<acctype;
cout<<"
Balance : "<<bal;
}
int main()
{
int acc_no;
char name[100], acc_type[100];
float balance;
cout<<"
Enter Details:
";
cout<<"-----------------------";
cout<<"
Accout No. ";
cin>>acc_no;
cout<<"
Name : ";
cin>>name;
cout<<"
Account Type : ";
cin>>acc_type;
cout<<"
Balance : ";
cin>>balance;

bank b1(acc_no, name, acc_type, balance); //object is created
b1.deposit(); //
b1.withdraw(); // calling member functions
b1.display(); //
return 0;
}

Is This Answer Correct ?    0 Yes 0 No

Define a class to represent a bank account. Include the following members: ..

Answer / pranay pushp

#include<iostream.h>
#include<conio.h>
#include<string.h>
class bank
{
char name[20];
int ano;
char atype[20];
float bal;
public:
void get(int no,char *n,char *t,float b)
{
strcpy(name,n);
ano=no;
strcpy(atype,t);
bal=b;
}
float deposit()
{
float amt;
cout<<“
Enter amount: “;
cin>>amt;
bal=bal+amt;
return bal;
}
float withdrw()
{
float amt;
cout<<“
How many Rupees withdraw: “;
cin>>amt;
bal=bal-amt;
return bal;
}
void disp()
{
cout<<“

Account number: “<<ano;
cout<<“

Name: “<<name;
cout<<“

Account type: “<<atype;
cout<<“

Deposit Amount: “<<deposit();
cout<<“

After Withdraw Amount balnace: “<<withdrw();
}
};
void main()
{
int n;
char nm[20],t[20];
float a;
bank bk;
clrscr();
cout<<“
Enter Account no.: “; cin>>n;
cout<<“
Enter Name: “; cin>>nm;
cout<<“
Enter account type: “; cin>>t;
cout<<“
Enter balance amount: “;cin>>a;
bk.get(n,nm,t,a);
bk.disp();
getch();
}

Is This Answer Correct ?    2 Yes 3 No

Define a class to represent a bank account. Include the following members: ..

Answer / opender shekhawat

include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
#include<stdlib.h>

class Bank
{
private:
int acc_id;
char name[20];
float balance;
public:
Bank();
Bank(int,char[20],float);
Bank(Bank&);
~Bank();
void read();
void deposit(float);
void withdraw(float);
void show();
int getid();
};

Bank::Bank()
{
acc_id = 0;
strcpy(name,'\0');
balance = 0.0;
}

Bank::~Bank()
{
cout<<"DESTRUCTOR!\n";
getch();
}

Bank::Bank(int id,char nm[],float bal)
{
acc_id = id;
strcpy(name,nm);
balance = bal;
}

Bank::Bank(Bank &b)
{
acc_id = b.acc_id;
strcpy(name,b.name);
balance = b.balance;
}

void Bank::read()
{
cout<<"\nenter the account-id : ";
cin>>acc_id;
cout<<"enter name of depositor : ";
fflush(stdin);
cin>>name;
cout<<"enter the balance amount : ";
cin>>balance;
cout<<"---------------------------------\n";
}

void Bank::deposit(float amt)
{
balance = balance + amt;
}

void Bank::withdraw(float amt)
{
balance = balance - amt;
}

void Bank::show()
{
cout<<"\naccount-id = "<<acc_id<<endl;
cout<<"name = "<<name<<endl;
cout<<"balance = "<<balance<<endl;
cout<<"-----------------------------------\n";
}

int Bank::getid()
{
return(acc_id);
}

int search(Bank *b,int tid,int n)
{
int flag, i=0;
while((i<n)&&(!flag))
{
int x;
x = b[i].getid();
if(x==tid)
flag = 1;
else
i++;
}
if(!flag)
return(-1);
else
return(i);
}

void main()
{
clrscr();
Bank cust[10];
int n;
cout<<"enter no.of customers : ";
cin>>n;
for(int i=0;i<n;i++)
cust[i].read();
cout<<"enter the account-id on which u want transactions : ";
fflush(stdin);
int tid;
cin>>tid;
int index=0;
index = search(cust,tid,n);
if (index==-1)
{
cout<<"account-id does not exist!\n";
cout<<"PROGRAM TERMINATION\n";
}
else
{
cout<<"what transaction do u want?\n";
cout<<" 1. DEPOSIT\n 2. WITHDRAW\n";
cout<<"enter ur choice : ";
int ch;
do
{
cin>>ch;
cout<<"ur present balance is :\n";
cust[index].show();
switch(ch)
{
case 1:
float amt;
cout<<"enter the amount u want to deposit : ";
cin>>amt;
cust[index].deposit(amt);
cout<<"ur new balance is :\n";
cust[index].show();
break;
case 2:
cout<<"enter the amount u want to withdraw : ";
cin>>amt;
cust[index].withdraw(amt);
cout<<"ur new balance is :\n";
cust[index].show();
break;
default:
cout<<"PROGRAM TERMINATION\n";
//exit(1);
}
cout<<"enter ur choice again : \n";
}
while((ch==1)||(ch==2));
}
getch();

}

Is This Answer Correct ?    15 Yes 18 No

Post New Answer

More OOPS Interview Questions

What is the real life example of polymorphism?

0 Answers  


What is the difference between pass by value,pass by pointer,pass by reference in the catch block in the exception handling in c++

1 Answers   TCS,


how can we design a magic square in c++?or suggest me the basic idea of it.

3 Answers  


What are the types of abstraction?

0 Answers  


Why u change company?

12 Answers   BOB Technologies,






Can you explain polymorphism?

0 Answers  


What is encapsulation?

17 Answers   TCS,


I hv a same function name,arguments in both base class and dervied class, but the return type is different. Can we call this as a function overloading? Explain?

3 Answers  


What is cohesion in oop?

0 Answers  


What are functions in oop?

0 Answers  


What are constructors in oop?

0 Answers  


WHAT IS THE ACTUAL DEFINATION OF OBJECT AND THE CLASS IN ONE SINGLE LINE WHICH THE INTERVIEWER WANT TO LISTEN.

11 Answers  


Categories