Write a C++ program in which you arerequired to define a class named Account . T
ID: 3614978 • Letter: W
Question
Write a C++ program in which you arerequired to define a class named Account. The class mustinclude the following two data members.
//data member foramount in the account
2: Amount
Your Program should define threeconstructors for the class Account
1: a constructor with noparameter
2: a constructor with two parameters(Account_Holder, Amount)
Declare three objects (1 for eachtype of constructor) in main.
Also write destructor for the classAccount. Display a message that says “destructorcalled” in the destructor body.
OUTPUT
Ahsan
15000
_________________
Umar
70000
_________________
Qasim
19000
Explanation / Answer
//header files
#include<iostream.h>
#include<conio.h>
classAccount
{
private:
char*Account_holder;
char*Amount;
public:
Account()
{
Account_holder = "Ahsan" ;
Amount = "15000";
}
Account(char* Account_holder1,char* Amount1)
{
Account_holder = Account_holder1;
Amount = Amount1;
}
Account(const Account&other)
{
int length1, length2;
length1 =strlen(other. Account_holder);
length2 =strlen(other. Amount);
Account_holder = new char[length1 + 1];
Amount =new char[length2 + 1];
strcpy( Account_holder, other.Account_holder );
strcpy( Amount,other.Amount );
}
void print()
{
cout<<Account_holder<<endl<<Amount<<endl;
cout<<"_________________"<<endl;
}
~Account(){}
};
int main()
{
Accountacc1;
Account acc2("Umar", "70000");
Account acc3("Qasim","19000");
//print function calls
acc1.print();
acc2.print();
acc3.print();
getch();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.