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
  • 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.

  • 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:...

  • Consider the class hierarchy on the last page of this assignment. It is a class hierarchy...

    Consider the class hierarchy on the last page of this assignment. It is a class hierarchy of food products, including FreshVegetable and CannedItem. A Package is also a product and is a container of multiple products. • We wish to use the visitor pattern to implement two operations on the product hierarchy. • The first operation is to find the cheapest item in a product, which we implement using the CheapestVisitor. • The second operation is to reduce the price...

  • Overview: file you have to complete is WordTree.h, WordTree.cpp, main.cpp Write a program in C++ that...

    Overview: file you have to complete is WordTree.h, WordTree.cpp, main.cpp Write a program in C++ that reads an input text file and counts the occurrence of individual words in the file. You will see a binary tree to keep track of words and their counts. Project description: The program should open and read an input file (named input.txt) in turn, and build a binary search tree of the words and their counts. The words will be stored in alphabetical order...

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
Active Questions
ADVERTISEMENT