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.
Answer Posted / 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 |
Post New Answer View All Answers
What is object and example?
What is protected in oop?
What is a class oop?
Why do we need polymorphism in c#?
What is the example of polymorphism?
What is data binding in oops?
Which is better struts or spring?
What is the difference between procedural programming and oops?
What does and I oop mean?
Why is polymorphism important in oop?
What is super in oop?
What is polymorphism used for?
INSTANCE FIELDS DECLARED private ARE ACCESSIBLE BY THE METHODS ONLY.CAN WE CHANGE THE private FIELD OF AN OBJECT IN A METHOD OF SOME OTHER OBJECT OF THE SAME CLASS?
What is interface? When and where is it used?
class CTest { public: void someMethod() { int nCount = 0; cout << "This is some method --> " << nCount; } }; int main() { CTest *pctest; pctest->someMethod(); return 0; } It will executes the someMethod() and displays the value too. how is it possible with our creating memory for the class . i think iam not creating object for the class. Thanks in Advance... Prakash