class CRealEstate
{
public:
// constructor
CRealEstate(int num_of_rooms , const string & address)throw(string*)
{
	try
	{
		m_num_of_rooms=num_of_rooms;
		if(address=="\n")
			throw "Wronge Address..\n";
		m_address=address;	
	}
	catch(const char *str)
	{
		cout<<str<<endl;
	}
}
virtual void Print()const =0;
virtual unsigned Profit()const =0;
	friend ostream&  operator<<(ostream& os , const CRealEstate &p)
	{		
		p.Print();
		return os;
	}	
protected:
int m_num_of_rooms;
string m_address;
};

class CRent : public CRealEstate
{
public:
	CRent(int monthlyrent,int periodyears,int room,string place):CRealEstate(room,place),m_monthly_rent(monthlyrent),m_period_years(periodyears){}
protected:
int m_monthly_rent;
int m_period_years;
};

class CSale : public CRealEstate
{
public:
	CSale(int room,string place,int sellprice):CRealEstate(room,place),m_sell_price(sellprice){}
	void Print()const 
	{
		cout<<"\n\nFor SALE: "<<m_address<<", "<<m_sell_price<<endl;	
	}	
	unsigned Profit()const
	{
		return m_sell_price;
	}
private:
int m_sell_price;
};

class CRentAHouse:public CRent
{
public:
	CRentAHouse(int room,string place,int monthlyRent,int periodYears,int gardenArea):CRent(monthlyRent,periodYears,room,place),m_garden_area(gardenArea){}
	void Print()const
	{
		cout<<"\n\nHouse for RENT: "<<m_address<<",\n"<<"monthly rent: "<<m_monthly_rent<<"The garden area is: "<<m_garden_area<<endl;		
	}
	unsigned Profit()const
	{
		return m_monthly_rent;
	}
private:
int m_garden_area;
};




unsigned sumProfit(const CRealEstate* p[], unsigned n)
{
unsigned i;
unsigned sumPro=0;
for(i=0;i<n;i++)
{
// cumulative profit
sumPro += *p[i]; ////////????i need to get the cumlative profit from the classes.
cout<<sumPro<<endl;
}
return sumPro;
}
unsigned &operator+=(unsigned value,const CRealEstate & p)
{
	value+=p.Profit();
	return value;
}

i dont know why it doesn't work..

maybe you can help me.

And could you explain how it doesn't work? Not compile? Run time error? How do you produce the error or "not work"? I don't have C++ compiler on hand, so can't just do it for you. Sorry.

This article has been dead for over six months. Start a new discussion instead.