Question
C++
FanClass.cpp Design a class named Fan to represent a fan. The class contains: Private section: An integer data field name spe
0 0
Add a comment Improve this question Transcribed image text
Answer #1

code:

#include<iostream>
#include<string>

using namespace std;
class FanClass
{
   private:
       int speed;
       bool on;
       double radius;
       string color;
  
   public:
       FanClass()        //constructor
       {
           speed=1;
           on=true;
           radius=3;
           color="white";
       }
       int getFanSpeed()
       {
           return speed;
       }
       void setFanSpeed(int x)
       {
           speed=x;
       }
       int getFanStatus()
       {
           if(on)         //if true
           {
               return 1;
           }
           else
           {
               return 0;
           }
       }
       void setFanStatus(bool x)
       {
           if(x==true)
           {
               on=true;
           }
           else
           {
               on=false;
           }
       }
       int getFanRadius()
       {
           return radius;
       }
       void setFanRadius(int x)
       {
           radius=x;
       }
       char* getFancolor()
       {
           char *c=&*color.begin();   //conversion from string to char*
           return c;
       }
       void setFanColor(char *x)       
       {
           color=x;
       }
       void displayFan()
       {
           cout<<"Fan Speed: "<<getFanSpeed()<<endl;
           cout<<"Fan Radius: "<<getFanRadius()<<endl;
           if(getFanStatus())
           {
               cout<<"Fan on by default: 1"<<endl;
           }
           else
           {
               cout<<"Fan off by default: 0"<<endl;
           }
           cout<<"fan color: "<<getFancolor()<<endl;
           cout<<endl;
   }
};

int main()
{
   FanClass f1,f2,f3;         //object declaration
   f1.displayFan();
   f2.setFanSpeed(2);
   f2.setFanRadius(5);
   f2.setFanStatus(false);
   f2.setFanColor("yellow");
   f2.displayFan();
   return 0;
}

Output:

Fan Speed: 1 Fan Radius: 3 Fan on by default: 1 fan color: white Fan Speed: 2 Fan Radius: 5 Fan off by default: 0 fan color:

Add a comment
Know the answer?
Add Answer to:
C++ FanClass.cpp Design a class named Fan to represent a fan. The class contains: Private section:...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Lab # 8      The Fan class (Chapter 9:Programming Exercise 9.8)         CSCI 1302 Design a class...

    Lab # 8      The Fan class (Chapter 9:Programming Exercise 9.8)         CSCI 1302 Design a class named Fan to represent a fan. The class contains: ■ Three constants named SLOW, MEDIUM, and FAST with the values 1, 2, and 3 to denote the fan speed. ■ A private int data field named speed that specifies the speed of the fan (the default is SLOW). ■ A private boolean data field named on that specifies whether the fan is on (the...

  • please write in Java and include the two classes Design a class named Fan (Fan.java) to...

    please write in Java and include the two classes Design a class named Fan (Fan.java) to represent a fan. The class contains: An int field named speed that specifies the speed of the fan. A boolean field named fanStatus that specifies whether the fan is on (default false). A double field named radius that specifies the radius of the fan (default 5). A string field named color that specifies the color of the fan (default blue). A no-arg (default) constructor...

  • 1. Please write the following program in Python 3. Also, please create a UML and write...

    1. Please write the following program in Python 3. Also, please create a UML and write the test program. Please show all outputs. (The Fan class) Design a class named Fan to represent a fan. The class contains: Three constants named SLOW, MEDIUM, and FAST with the values 1, 2, and 3 to denote the fan speed. A private int data field named speed that specifies the speed of the fan. A private bool data field named on that specifies...

  • (The Account class) Design a class named Account that contains: A private int data field named...

    (The Account class) Design a class named Account that contains: A private int data field named id for the account (default 0). A private double data field named balance for the account (default 0). A private double data field named annualInterestRate that stores the current interest rate (default 0). Assume all accounts have the same interest rate. A private Date data field named dateCreated that stores the date when the account was created. A no-arg constructor that creates a default...

  • Design a JAVA program with the class named Computer that creates a computer object that stores...

    Design a JAVA program with the class named Computer that creates a computer object that stores the computer's brand, model, memory (in GB) and storage (in GB). The class must contain the following instance variables and methods. All variable and method names must match the specifications listed below exactly. Instance Variables: - a String variable named brand - a String variable named model - an int variable named memory - an int variable named storage Methods: The accessor and mutator...

  • THE FOLLOWING PROGRAM IS NEEDED IN JAVA LANGUAGE Design a class torepresent account, include the following...

    THE FOLLOWING PROGRAM IS NEEDED IN JAVA LANGUAGE Design a class torepresent account, include the following members: -Data Members a)Name of depositor-Stringb)Account Number –intc)Type of account –Boolean d)Balance amount -doublee)AnnualInterestrate -double Methods: -(a)To assign initial values (use constructor)(b)To deposit an amount.(c)TO withdraw amount with the restriction the minimum balance is 50 rs. Ifyouwithdraw amount reduced the balance below 50 then print the error message.(d)Display the name and balance of the account.(e)Get_Monthly_intrestRate() -Return the monthly interestrate whichis nothing but Annualintrestrate/12. Annualinterestrate...

  • Design a class named Account that contains: A private int datafield named id(default 0) A private...

    Design a class named Account that contains: A private int datafield named id(default 0) A private double datafield named balance(default 0) A no-arg constructor that creates default account A constructor that creates an account with specified id & balance The getter and setter methods for id and balance. Create an object of account class using default constructor and update the balance to 2000$ .

  • 9.7 (The Account class) Design a class named Account that contains: • A private int data...

    9.7 (The Account class) Design a class named Account that contains: • A private int data field named id for the account (default o). • A private double data field named balance for the account (default o). • A private double data field named annualInterestRate that stores the current interest rate (default o). Assume that all accounts have the same interest rate. • A private Date data field named dateCreated that stores the date when the account was created. •...

  • Design a class named BankAccount that contains: 1. A private int data field named accountId for...

    Design a class named BankAccount that contains: 1. A private int data field named accountId for the account. 2. A private double data field named accountBalance for the account (default 0). 3. A private double data field named annualInterestRate that stores the current interest rate (default 0). Assume all accounts have the same interest rate. 4. A private Date data field named dateCreated that stores the date when the account was created. 5. A private int data field named numberOfDeposits...

  • Problem 2 (36 pts): You are going to design a class named Computer. The class contains:...

    Problem 2 (36 pts): You are going to design a class named Computer. The class contains: A string field named manufacturer. A string field named serialNumber. A double field named speed (measured in Gigahertz). A constructor that has a parameter for each data field and sets the data fields with these values. A no-arg constructor that sets string fieldsto and numeric fields to 0. Mutator and Accessor methods for each data field. A method toString) that returns each field value...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT