Advertisement

Object Oriented Programming second assignment fall 2009 Solution

Write a C++ program in which you are required to define a class named Account. The class must include the following two data members.

// data member for account holder’s name
1: Account_Holder

//data member for amount in the account
2: Amount

Your Program should define three constructors for the class 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 initialize their respective objects. Incase of copy constructor, you are required to assign a separate space for the data members of the new object while copying the values of previously existed object.

Declare three objects (1 for each type of constructor) in main.

Write a function in class Account to display the initialized data members for each object.

Also write destructor for the class Account. Display a message that says “destructor called” in the destructor body.


Note: you can do better by making your variable names more meaningful. Adding proper comments and indenting your code properly.

OUTPUT

Your output should be similar to the following

Ahsan
15000
_________________
Umar
70000
_________________
Qasim
19000
************************************

I have googled and worked a lil bit , below is my code snippet but it gives error . Prompt help will be highly appreciated.

Solution

"# include"
"# include "
class Account
{
protected:
char* Account_Holder;
int Amount;
public:
Account();
Account( char* Holder, int Num );

Account( const Account& );
};
Account::Account()
{
Account_Holder = NULL;
Amount = 0;
}
Account::Account( char* Holder, int Num )
{
Account_Holder = Holder;
Amount = Num;
}
Account::Account( const Account& )
{
Account_Holder = obj.Account_Holder;
Amount = obj.Amount;
}
}; //end of fn
0 Responses