in C++ Define a class bank account with proper constructors, accessors, mutators, and other member functions. The class will be store money expressed in dollars and cents. The class should have following data members (fname, lname, accountNum, balance, dollars, cents).Write A function to print out the object bank account info.The class should implement two member functions for deposit and withdrawal. Overload the + operator, so that adding two objects of this class works. please respond quickly and clearly, thank you.
Code:
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
class bank
{
int acno;
char nm[100];
char lnm[100];
float bal;
double doller, cent;
public:
bank(int acc_no, char *fname, char *lname, float balance, double
dollers,double cents) //Parameterized Constructor
{
acno=acc_no;
strcpy(nm, fname);
strcpy(lnm, lname);
bal=balance;
doller=dollers;
cent=cents;
};
void deposit();
void withdraw();
void display();
};
void bank::deposit() //depositing an amount
{
int D1;
cout<<"\n Enter Deposit Amount = ";
cin>>D1;
bal+=D1;
}
void bank::withdraw() //withdrawing an amount
{
int W1;
cout<<"\n Enter Withdraw Amount = ";
cin>>W1;
if(W1>bal)
cout<<"\n Cannot Withdraw Amount";
bal-=W1;
}
void bank::display() //displaying the details
{
cout<<"\n ----------------------";
cout<<"\n Accout No. : "<<acno;
cout<<"\n First Name : "<<nm;
cout<<"\n Last Name : "<<lnm;
cout<<"\n Balance : "<<bal;
cout<<"\n Dollers : "<<int(bal);
cout<<"\n Cents : "<<bal*100;
}
int main()
{
int acc_no;
char fname[100];
char lname[100];
float balance;
double dollers ,cents;
cout<<"\n Enter Details: \n";
cout<<"-----------------------";
cout<<"\n Accout No. ";
cin>>acc_no;
cout<<"\n First Name : ";
cin>>fname;
cout<<"\n Last Name : ";
cin>>lname;
cout<<"\n Balance : ";
cin>>balance;
cout<<"\n Dollers : "<<int(balance);
cout<<"\n\n Cents : "<<balance*100;
cout<<"\n";
bank b1(acc_no, fname, lname, balance, dollers, cents); //object is
created
b1.deposit(); //
b1.withdraw(); // calling member functions
b1.display(); //
return 0;
}
Output:
Thank You!! Hope you like it.
If any doubt comes up, please let me know.
Get Answers For Free
Most questions answered within 1 hours.