Write a C++ program in which you are required to define a classnamed Account . T
ID: 3615079 • Letter: W
Question
Write a C++ program in which you are required to define a classnamed Account. The class must include thefollowing two data members.
// data member for account holder’sname
1: Account_Holder
//data member for amount in the account
2: Amount
Your Program should define three constructors for theclass Account
1: a constructor with no parameter
2: a constructor with two parameters (Account_Holder,Amount)
3: a copy constructor
All of these three constructors are meant to initializetheir respective objects. Incase of copy constructor, you arerequired to assign a separate space for the data members of the newobject while copying the values of previously existedobject.
Declare three objects (1 for each type of constructor)in main.
Write a function in class Account to display theinitialized data members for each object.
Also write destructor for the class Account. Display amessage that says “destructor called” in the destructorbody.
Explanation / Answer
PLZ RATE: #include<iostream.h>#include<conio.h>
class Account
{
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()
{
Account acc1;
Account acc2("Umar", "70000");
Account acc3("Qasim", "19000");
//print function calls
acc1.print();
acc2.print();
acc3.print();
getch();
return 0;
}
#include<iostream.h>
#include<conio.h>
class Account
{
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()
{
Account acc1;
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.