Write a C++ program in which youare required to define a class named Account . T
ID: 3614983 • Letter: W
Question
Write a C++ program in which youare required to define a class named Account. Theclass must include the following two data members.
// data member for accountholder’s name
1: Account_Holder
//data member for amount in the account
2:Amount
Your Program should definethree constructors for the class Account
1: a constructor with noparameter
2: a constructor with twoparameters (Account_Holder, Amount)
3: a copyconstructor
All of these threeconstructors are meant to initialize their respective objects.Incase of copy constructor, you are required to assign a separatespace for the data members of the new object while copying thevalues of previously existed object.
Declare three objects (1for each type of constructor) in main.
Write a function in classAccount to display the initialized data members for eachobject.
Also write destructor for the class Account. Display amessage that says “destructor called” in the destructorbody.
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
help me
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.