Question

So on this assignment... I have the main.cpp file, the fan.cpp file, and the fan.h file created and open in Dev C++. However, every time I try to compile I get a series of undefined reference to errors. Any advice is much appreciated!!!(45 pts) Work Programming Exercise 9.2 (class Fan) in the textbook on page 367. Additional specifications: • Use separate hea

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1. Create Fan.h header file with class declaration in it.

2. Create Fan.cpp implementation file with class definition in it.

3. Include Fan.h directive in main.cpp file.

______________________________________________________________________________________________________________________

C++ Program:

File: Fan.h

class Fan
{
//Data Members
private:
int speed;
bool on;
float radius;
  
//Member functions
public:
//Setter methods
void setSpeed(int val);
void setOn(bool val);
void setRadius(float val);
  
//Getter methods
int getSpeed();
bool getOn();
float getRadius();
};

File: Fan.cpp

#include "Fan.h"

//Setter methods
void Fan::setSpeed(int val)
{
speed = val;
}
  
void Fan::setOn(bool val)
{
on = val;
}
  
void Fan::setRadius(float val)
{
radius = val;
}
  
//Getter methods
int Fan::getSpeed()
{
return speed;
}
  
bool Fan::getOn()
{
return on;
}
  
float Fan::getRadius()
{
return radius;
}

File: main.cpp

#include <iostream>
#include "Fan.h"

using namespace std;

int main(int argc, char **argv)
{
//Creating object
Fan f1;
  
//Setting values
f1.setSpeed(3);
f1.setOn(true);
f1.setRadius(3.5);
  
//Printing values
cout << "\n Speed: " << f1.getSpeed() << "\n On: " << f1.getOn() << "\n Radius: " << f1.getRadius() << "\n";
return 0;
}

_____________________________________________________________________________________________________________________

Sample Run:

A. C:\Windows\SYSTEM32\cmd.exe Speed: 3 On: 1 Radius: 3.5 Press any key to continue ...

Add a comment
Know the answer?
Add Answer to:
So on this assignment... I have the main.cpp file, the fan.cpp file, and the fan.h file...
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
  • C++ Class and Operator Overloading part 1 The source file contains a C++ program that declares...

    C++ Class and Operator Overloading part 1 The source file contains a C++ program that declares and initializes an array of Circles. The program is using a for loop statement to find the largest circle in the array and display it on the output screen. However, the program is currently not working. The problem is the program uses logical operator ' > ' for comparison of circles and it is not working unless we overload such operator for the class...

  • PLEASE help! There should be three files a (.h file), a (main.cpp file), and a (test.cpp...

    PLEASE help! There should be three files a (.h file), a (main.cpp file), and a (test.cpp file) please do not miss any of the questions!! I'm going to try this myself too thanks for any and all help Write a class called array2x2 which includes the following members: Private members: o A two dimensional array to store the data: double data[2][2]; Public members: o A default constructor which initializes data to having entries all 0. [i.e., data[i][j]=0.0 for all i...

  • IN C++ MUST INCLUDE HEADER FILE, IMPLEMENTATION FILE, AND DRIVER FILE. IN C++ Create a header...

    IN C++ MUST INCLUDE HEADER FILE, IMPLEMENTATION FILE, AND DRIVER FILE. IN C++ Create a header and implementation file to define an apartment class. Create a driver program to test the class, and create a make file to compile the driver program. Create two files called apartment.h and appartmentImp.cpp along with creating a driver program named testApartment.cpp containing the main function. Program Requirements: • Class attributes should include integers for number of rooms, monthly rent, and square feet, as well...

  • How do I format this into C++? This the prompt: Design a class named Password that...

    How do I format this into C++? This the prompt: Design a class named Password that stores a password in a c-string and has member functions to test if the password complies with certain requirements as follows: The password should be between 6 and 20 characters long. The password should contain at least one uppercase and at least one lowercase letter. The password should have at least one digit. The password should have at least one punctuation character. Define a...

  • Create a class named Game using the following UML class diagram. GAME -gameName : string +Game()...

    Create a class named Game using the following UML class diagram. GAME -gameName : string +Game() +setGameName(in name : string) : void +getGameName() : string +displayMessage() : void This class has 2 member variables namely playerName and playerScore. The class contain following member functions: Constructor, set function, get functions, display function. Code write in 3 files: Game.h header file, funtion.cpp file and main.cpp file. The output should be: Player John has scored 50 points.

  • Using C++ Create a header file that defines a class called Building. The variables: the width,...

    Using C++ Create a header file that defines a class called Building. The variables: the width, the length, and the height. There should be functions to set the width and height, to get the width and height, and to get the volume of the building. Note: each floor of the building is ten feet high. So, also get the number of floors in the building. Call the header file in a program, also called building. Do not accept invalid input....

  • Type up the GeometricObject class (code given on the back of the paper). Name this file Geometric...

    Python only please, thanks in advance. Type up the GeometricObject class (code given on the back of the paper). Name this file GeometricObjectClass and store it in the folder you made (xxlab14) 1. Design a class named Rectangle as a subclass of the GeometricObject class. Name the file RectangleClass and place it in the folder. 2. The Rectangle class contains Two float data fields named length and width A constructor that creates a rectangle with the specified fields with default...

  • lab 11 Do not change main.cpp, i need c++ code for queue.h and queue.cpp Given the...

    lab 11 Do not change main.cpp, i need c++ code for queue.h and queue.cpp Given the complete main() function, partial queue class header queue.h, and queue.cpp, you will complete the class declaration and class implementation. The following member functions are required: constructor enqueue() dequeue() You may elect to create the following helper functions: isFull() isEmpty() A description of these ADT operations are available in this Zybook and in the textbook's chapter 17. Example: If the input is: 3 Led Zepplin...

  • (i) Create a class square with attribute (integer) length which defaults to 5. Provide member functions...

    (i) Create a class square with attribute (integer) length which defaults to 5. Provide member functions that calculate the perimeter (4 * length) and the area (length*length) of the triangle. Also provide set and get functions for the length attribute. The set function should verify that length is between 0.0 to 100. Your class should also provide a display function that draws the aquare using * character. For example, if length = 5, the display function should draw             *****...

  • COSC 1437 C++2 Project Assignment 3 Description: Computer Science Department is evaluating its professors to see...

    COSC 1437 C++2 Project Assignment 3 Description: Computer Science Department is evaluating its professors to see which professor has the highest rating according to student input. You will create a ProfessorRating class consisting of professor Name and three ratings. The three ratings are used to evaluate easiness, helpfulness, and clarity. The value for each rating is in the range of 1 to 5, with 1 being the lowest and 5 being the highest. Your program should contain the following functionalities:...

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