Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Design a class named Fan to represent a fan. The class contains: - An int da

ID: 3769986 • Letter: C

Question

C++

Design a class named Fan to represent a fan. The class contains:

- An int data field named speed that specifies the speed of the fan. A fan has three speeds indicated with a value 1, 2, or 3.

- A bool data field named on that specifies whether the fan is on.

- A double data field named radius that specifies the radius of the fan.

- A no-arg constructor that creates a default fan with speed 1, on false, and radius 5.

- The accessor and mutator functions for all the data fields.

Additional specifications:

- Use separate header and implementation files.

- The main program (not the functions) should display the values of Speed, On, and Radius after calling the functions.

The problem refers to accessor (get) and mutator (set) functions for all the data fields (Speed, On, and Radius). This means the following functions should be included:

- getSpeed( );

- getOn( );

- getRadius( );

- setSpeed( );

- setOn( );

- setRadius( );

Run the program for the test case for two fan objects. Assign speed 3, radius 10, and turn it on for the first object. Assign speed 2, radius 5, and turn it off for the second object. Additionally, add a 3rd fan object that uses the default values assigned by the constructor. The program should use the accessor functions to display Speed, On, and Radius for all 3 fan objects.

Explanation / Answer

Fan.h

#include <iostream>
using namespace std;
class Fan
{
int speed;
bool on;
double radius;
public:
Fan();
int getSpeed();
bool getOn();
double getRadius();
void setSpeed(int s);
void setOn(bool o);
void setRadius(double r);
void showFan();
};

Fan.cpp

#include <iostream>
#include <iomanip>
#include "Fan.h"
using namespace std;
Fan::Fan()
{
speed = 1;
on = false;
radius = 5;
}
int Fan::getSpeed()
{
return speed;
}
bool Fan::getOn()
{
return on;
}
double Fan::getRadius()
{
return radius;
}
void Fan::setSpeed(int s)
{
speed = s;
}
void Fan::setOn(bool o)
{
on = o;
}
void Fan::setRadius(double r)
{
radius = r;
}
void Fan::showFan()
{
cout<<"This fan has a radius of "<<fixed<<setprecision(2)<<radius<<" at it rotates at a speed of "<<speed<<" and it is switched ";
cout<<(on?"ON":"OFF")<<endl;
}

FanDemo.cpp

#include <iostream>
#include "Fan.cpp"
int main()
{
Fan f1;
f1.setSpeed(3);
f1.setRadius(10);
f1.setOn(true);
Fan f2;
f2.setSpeed(2);
f2.setRadius(5);
f2.setOn(false);
Fan f3;
f1.showFan();
f2.showFan();
f3.showFan();
}

If you have any further queries, just get back to me.....