C++ programming problem The class Chimney represents a smoke ventilation system.
ID: 640668 • Letter: C
Question
C++ programming problem
The class Chimney represents a smoke ventilation system. Consider the class diagram shown below.
Each instance of a Chimney has a height, a shape and can be either opened or closed. Here is the class definition (.h)
Chimney( );
void open();
void close();
bool isOpen() const;
void setHeight( double height );
double getHeight() const;
bool isOpen;
double myHeight;
Based on the information shown here, a possible implementation (.cpp) for Chimney is shown below.
isOpen = false;
myHeight = 0;
isOpen = true;
isOpen = false;
return( isOpen );
myHeight = height;
return( myHeight );
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
void open();
void close();
bool isOpen() const;
void setHeight( double height );
double getHeight() const; bool isOpen;
double myHeight; // in feet class Chimney {
public:
Chimney( );
void open();
void close();
bool isOpen() const;
void setHeight( double height );
double getHeight() const;
bool isOpen;
double myHeight;
Explanation / Answer
//Chimney.h
class Chimney {
public:
Chimney( );
void open();
void close();
bool isOpen() const;
void setHeight( double height );
double getHeight() const;
private:
bool myOpen;
double myHeight;
};
//Chimney.cpp
#include "Chimney.h"
Chimney::Chimney( ) {
myOpen = false;
myHeight = 0;
}
void Chimney::open() {
myOpen = true;
}
void Chimney::close() {
myOpen = false;
}
bool Chimney::isOpen() const {
return(myOpen);
}
void Chimney::setHeight( double height ){
myHeight = height;
}
double Chimney::getHeight() const {
return( myHeight );
}
//Fireplace.h
#include "Chimney.h"
class Fireplace
{
private:
bool is_Lit;
Chimney my_Chimney;
public:
Fireplace();
Fireplace(int h, bool val);
void light();
void extinguish();
};
// Fireplace.cpp
#include "Fireplace.h"
Fireplace::Fireplace(){
is_Lit = true;
my_Chimney.setHeight(10);
my_Chimney.open();
}
Fireplace::Fireplace(int h, bool val){
is_Lit = false;
my_Chimney.setHeight(20);
}
void Fireplace::light(){
if(is_Lit)
my_Chimney.open();
}
void Fireplace::extinguish(){
if(!is_Lit)
my_Chimney.close();
}
// Main.cpp
#include<iostream>
using namespace std;
#include "Fireplace.h"
int main(){
Fireplace warmFire; // By default, a lighted fireplace with an open chimneystack that has a height 10 feet
Fireplace noFire( 20, false );// An unlit fireplace with a closed chimneystack that has a height of 20 feet
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.