Write a C++ program in which you are required to define aclass named Account . T
ID: 3614985 • Letter: W
Question
Write a C++ program in which you are required to define aclass named Account. The class must include thefollowing two data members.
// data member for account holder’sname
1: Account_Holder
//data member for amount in theaccount
2: Amount
Your Program should define three constructors forthe class Account
1: a constructor with noparameter
2: a constructor with two parameters(Account_Holder, Amount)
3: a copy constructor
All of these three constructors are meant toinitialize their respective objects. Incase of copy constructor,you are required to assign a separate space for the data members ofthe new object while copying the values of previously existedobject.
Declare three objects (1 for each type ofconstructor) in main.
Write a function in class Account to display theinitialized data members for each object.
Also write destructor for the class Account.Display a message that says “destructor called” in thedestructor body.
Note: you can do better by making your variable names moremeaningful. Adding proper comments and indenting your codeproperly.
OUTPUT
Your output should be similar to thefollowing
Ahsan
15000
_________________
Umar
70000
_________________
Qasim
19000
Explanation / Answer
#include #include class Account { char* Account_Holder; int Amount; public: Account(); Account( char* _Name, int_Amount) ; // Constructor Account(const Account&obj); ~Account(){ printf("destructorcalled");} ; // Destructor // Prototypes for Getters Setters void SetAccountHolder( char*Account_Holder) ; char* GetAccountHolder( void ); void SetAmount(int_Amount); int GetAmount(void); void displayInfo(); }; voidAccount::displayInfo(){ // provide code here fordisplay account information } // No parameter Constructor Account::Account(){ Account_Holder= NULL; Amount=0; } // Constructor with 2 Parameters Account::Account( char*_Account_Holder, int _Amount) { Account_Holder=_Account_Holder; Amount= _Amount; } //Copy constructor Account::Account(constAccount& obj) { Account_Holder=obj.Account_Holder; Amount= obj.Amount; } // Defination of Getters/ Setters void Account::SetAccountHolder( char* _Account_Holder) { Account_Holder = _Account_Holder; } char* Account::GetAccountHolder( void ) { return Account_Holder; } void Account::SetAmount( int _Amount) { Amount= _Amount; } int Account::GetAmount( void ) { return Amount; } int main() { Account a; // parameterless constructor called at this point a.displayInfo(); Account AAccount("Tahir",10000) ; // Two parameter constructorcalled at this point AAccount.displayInfo(); a=AAccount; // Copy Constructor called at this point system("PAUSE"); }Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.