Image

Imagetimv wrote in Imagecpp

Class Inheritance Demo

I am working with a professor to test out of a C++ class. One of the things he wants to see is a demo of inheritance. Can you tell me what you think of this?

The LJ cut tag does not seem to be working!!!



class material
{
public:
	virtual void rubbed(){ cout << "rubbed." };
	virtual void hit(){ cout << "knocked." };
	virtual void sat_on(){ cout << "sat on." };
}

class vinyl : public material
{
public:
	void rubbed() { cout << "sqeak!" };
	void hit() { cout << "pop!" };
	void sat_on(){ cout << "squish!" };
}

class leather : public material
{
public:
	void rubbed() { cout << "brrrip!" };
	void hit() { cout << "poof!" };
	void sat_on(){ cout << "squish!" };
}

class wood : public material
{
public:
	void rubbed() { cout << "*little squeak*" };
	void hit() { cout << "thud!" };
	void sat_on(){ cout << "*relative silence*" };
}

class plush : public material
{
public:
	void rubbed() { cout << "*relative silence*" };
	void hit() { cout << "poof!" };
	void hit() { cout << "*relative silence*" };
}

class part
{
public:
	void make_from(material stuff){ made_of(stuff) };
	material made_from(){ return made_of };
	void attach(part item); //need code to "attach" part using a linked list or something
private:
	material made_of;
}

class leg : public part
{
public:
	leg();
	leg(material stuff);
	~leg();
}

class seat : public part
{
public:
	seat();
	seat(material stuff);
	~seat();
}

class back : public part
{
public:
	back();
	back(material stuff);
	~back();
}

class footrest : public part
{
public:
	footrest();
	footrest(material stuff);
	~footrest();
}

class arm : public part
{
public:
	arm();
	arm(material stuff);
	~arm();
}

class chair
{
public:
	leg leg_FL, leg_FR, leg_BL, leg_BR; //legs for front left, front right, back left, back right
	seat the_seat;
	arm arm_left, arm_right;
	back the_back;

	void sat_on(){ the_seat.rubbed };

}

class sofa
{
	leg leg_FL, leg_FM, leg_FR, leg_BL, leg_BM, leg_BR;
	seat seat_L, seat_R;
	arm arm_left, arm_right;
	back back_L, back_R;
}

class big_sofa : public sofa
{
	leg leg_FM, leg_BM; //adding legs for the middle
	seat seat_M;  //adding a middle seat
	back back_M;  //adding a middle back
}

class recliner : public chair
{
public:
	footrest the_footrest;
	
	void extend( extended = true );
	void retract( extended = false );

private:
	bool extened;

}