Inheritance Problem

I have an assignment I am having trouble with.

Here is the assignment question:
The class Chimney represents a smoke ventilation system.
Each instance of a Chimney has a height, a shape and can be either opened or closed.
Based on this implementation of Chimney, define and implement the class Fireplace (a .h file and a .cpp
file). A Fireplace can be lit or extinguished and always has a Chimney to ventilate the smoke away.

Make sure your definition of Fireplace supports the following kinds of constructors:

By default, a lighted fireplace with an open chimneystack that has a height 10 feet.
Fireplace warmFire;

An unlit fireplace with a closed chimneystack that has a height of 20 feet
Fireplace noFire( 20, false );


In addition, create these two operations on Fireplace :

(1)void Fireplace::light();
(2)void Fireplace::extinguish();

These operations should adjust the Fireplace by manipulating the Chimney, opening the chimneystack
before the Fireplace’s fire is lit and closing the chimneystack after the fire is extinguished.

As currently defined, can any of the member operations you defined on the class Fireplace be marked const?



Here is my code so far;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 #ifndef CHIMNEY_H
#include <iostream>

namespace cs52 {

	
class Chimney {

public:

		Chimney( );
		Chimney(double height,bool oporcl);
		virtual void open();
		virtual void close();
		bool isOpen() const;
		void setHeight( double height );
		double getHeight() const;


private:
		bool isitOpen;
		double myHeight;


};//Chimney

}//cs52

#endif 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "Chimney.h"
#include <iostream>


namespace cs52{
Chimney::Chimney( ) { 
isitOpen=false;
myHeight = 0;
}

Chimney::Chimney(double height,bool oporcl) {
	myHeight=height;
	isitOpen=oporcl;
}

void Chimney::open() { 
isitOpen=true;
}

void Chimney::close() { 
isitOpen=false;
}

bool Chimney::isOpen() const { 
return( isitOpen );
}

void Chimney::setHeight( double height ){ 
myHeight=height;
}

double Chimney::getHeight() const { 
return( myHeight );
}
}//cs52 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#ifndef FIREPLACE_H
#include "Chimney.h"
#include <iostream>

namespace cs52{


class FirePlace: public Chimney {

public:

		FirePlace( );

		void light();
		void extunguish();
		virtual void open();
		virtual void close();
		/*bool isOpen() const;
		void setHeight( double height );
		double getHeight() const;
		*/

private:
		bool isLit;


};//FirePlace

}//cs52

#endif 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "FirePlace.h"
#include "Chimney.h"


namespace cs52{

FirePlace::FirePlace(){
	isLit=false;
}

void FirePlace::light() {
	isLit=true;
}
void FirePlace::extunguish() {
	isLit=false;
}
void FirePlace::open() {

	if(isLit==true){
			isitOpen=true;  //VS tells me that I can't acces isitOpen
		}
}

}//cs52 


How can I manipulate the Chimney class variables inside the FirePlace class implementation?
I am not even sure if I have to inherit something from Chimney class, is it possible for those two class to work together without inheriting from each other?

Here is the diagram drawn by me perfectly:)

FirePlace__________________Chimney
___^___<-------my_Chimney---->
__isLit__
Last edited on
> A Fireplace can be lit or extinguished and always has a Chimney to ventilate the smoke away.
has suggest composition
1
2
3
class Fireplace{
   Chimney meaningful_name;
};


> is it possible for those two class to work together
¿do you understand the difference between an object and a class?
¿do you realize that you can have several chimneys?

You may communicate with an object that you:
1) receive it as a parameter in the method
void Match::Fire( Paper &important_document )
a) own an instance or have a reference
1
2
3
4
5
6
class Car{
   Human *driver;
   void crash(){
      this->driver->die();
   }
};

alpha) create it
1
2
3
4
class Programmer::Foo(){
   Weapon gun;
   gun.shoot( this->right_foot );
}



> VS tells me that I can't acces isitOpen
you took the time to code an interface, use it
Topic archived. No new replies allowed.