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 / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the main feature of oop?

620


Prepare me a program for the animation of train

2000


Can we override main method?

607


What does I oop mean?

618


write a code for this:trailer recordId contains a value other than 99, then the file must error with the reason ‘Invalid RECORD_ID’(User Defined Exception).

1642






What is encapsulation process?

582


What is ambiguity in inheritance?

625


What causes polymorphism?

577


What is new keyword in oops?

593


Why we use classes in oop?

583


write a program to find 2 power of a 5digit number with out using big int and exponent ?

1895


What is overriding in oop?

550


What is static modifier?

632


What is meant by oops concept?

612


What is oops and why we use oops?

573