Answer to Question #224827 in C++ for snr

Question #224827

Create an Account class (acctNumber, acctName, branch, balance). Write constructors – default

constructor, constructor(acctNumber). Create an object of Account using constructor(acctNumber)

assign the other values using separate functions of each property. Display account number and

balance in the main.


1
Expert's answer
2021-08-11T03:26:47-0400
#include<iostream>
#include<stdio.h>
#include<string.h>

using namespace std;

class Account
{
        int acctNumber;
        char accName[100], branch[100];
        float bal;
   public:
        Account(int acc_no, char *name, char *acc_branch, float balance)  //Parameterized Constructor
        {
                acctNumber=acc_no;
                strcpy(accName, name);
                strcpy(branch, acc_branch);
                bal=balance;
        }
        void deposit();
        void withdraw();
        void display();
};
void Account::deposit()   //depositing an amount
{
        int damt1;
        cout<<"\n Enter Deposit Amount = ";
        cin>>damt1;
        bal+=damt1;
}
void Account::withdraw()  //withdrawing an amount
{
        int wamt1;
        cout<<"\n Enter Amount you wish to withdraw = ";
        cin>>wamt1;
        if(wamt1>bal)
                cout<<"\n Cannot Withdraw Amount";
        bal-=wamt1;
}
void Account::display()  //displaying the details
{
        cout<<"\n ****************************";
        cout<<"\n Account Number. : "<<acctNumber;
       // cout<<"\n Account Name : "<<accName;
      //cout<<"\n Account Branch : "<<branch;
        cout<<"\n Balance : "<<bal;
}
int main()
{
        int acc_no;
        char name[100], acc_branch[100];
        float balance;
        cout<<"\n Enter Your Details: \n";
        cout<<"******************************";
        cout<<"\n Account Number. ";
        cin>>acc_no;
        cout<<"\n Account Name : ";
        cin>>name;
        cout<<"\n The Branch of your Account : ";
        cin>>acc_branch;
        cout<<"\n Balance : ";
        cin>>balance;

        Account acctNumber(acc_no, name, acc_branch, balance);  //object is created
        acctNumber.deposit(); //
        acctNumber.withdraw(); // calling member functions
        acctNumber.display(); //
        return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS