Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CS 241: Advanced Object-Oriented Programming using C++ Spring 2021 Homework 6 To practice the OOP concepts discussed in the lecture, define a C++ class that

image text in transcribedimage text in transcribedimage text in transcribed

CS 241: Advanced Object-Oriented Programming using C++ Spring 2021 Homework 6 To practice the OOP concepts discussed in the lecture, define a C++ class that simulates an air fan. The class should be called AirFan and it should have the following components: Data Members: An integer that store the number of blades the fan has. A string to store the color of the fan. o A variable that stores the connection status of the fan (connection to electricity). It can be either plugged in a power outlet or not plugged. You are free to choose any appropriate data type for this variable. o A variable to store the speed of the fan. It can be one of the following speeds: not spinning, slow, medium, or fast. You are free to choose any appropriate data type for this variable. O A variable that stores the power status of the fan. It can be either turned on or turned off. You are free to choose any appropriate data type for this variable. Member Functions: A function to initialize the data members of the AirFan object. It should take two arguments, the number of blades of the fan and its color. The other data members should be initialized as follows: Connection status: not plugged in a power outlet. Speed: not spinning. Power status: turned off. A function to plug the fan into the power outlet. This function will change the connection status data member to "plugged in power. O A function to unplug the fan from the power outlet. This function will change the connection status data member to "not plugged in power. This will also tum the fan "off" and will make its speed "not spinning". O A function to turn the fan on. This function will change the power status data member to On. Please note that the fan can't be turned on unless it is plugged in a power outlet. A function to turn the fan off. This function will change the power status data member to Off. Please note that once the fan is turned off, it will stop spinning, i.e. speed status data member should be updated as well. A function to increase the speed of the fan. It should change the speed data member as follows: If the current speed is not spinning", the new speed will be "slow" . If the current speed is slow, the new speed will medium If the current speed is medium, the new speed will be fast. If the current speed is fast, then it won't change. O A function to decrease the speed of the fan. It should change the speed data member as follows: If the current speed is fast, the new speed will be medium. . If the current speed is medium, the new speed will be slow. If the current speed is slow, the new speed will be not spinning" . If the current speed is not spinning, it won't change A function to display the status of the fan. It should display the values of all the data members of the AirFan object. Once you complete the definition of the AirFan class, write the main() function that does the following: Create two AirFan objects. Initialize the first object to have 4 blades and a black color Initialize the second object to have 5 blades and a gray color Display the following menu options: 1- Plug a fan in power 2- Unplug a fan from power 3- Turn a fan on 4- Turn a fan off 5- Increase the speed of a fan 6- Decrease the speed of a fan 7- Display the status of a fan 0-Exit the program For options 1 to 7, the program should ask the user to select which fan will be used for the selected choice. For example, if the user selects 3 for "Turn a fan on, the program should ask the user if they want to turn on the black fan or re gray fan then turn on the selected fan. Programming Guidelines: After completing the selected operation, the program should display the menu again and ask the user to enter a new choice. The program should end only if the user selects 0. If the user enters a selection that is not in the menu, the program should display "Invalid Selection. Please try again...."and waits for a valid selection. In the above menu example, only 1, 2, 3, 4, 5, 6, 7, and 0 are the valid selections. Anything other than that is invalid and should be rejected by the program. Use the switch - case statement to implement the processing of the meu selection. Part of your grade will be for the programming style used. Here are some guidelines: o Each program should begin with a comment section giving the name of the file, the author's name, the date the file was last modified, and a description of its purpose. In addition, it is also considered good programming practice to include any assumptions you have made and any error-checking that has been provided. For example, /* Filename: make change.cpp Author: L. Stauffer Date last modified: 2/10/2021 This program accepts a dollar amount specified by the user and displays the minimum number of $10, $5, and $1 bills required to make up the amount. */ o Use meaningful and descriptive identifiers for variable names. This can make a program easier to understand. Add comments in your program to provide clarity for the reader. o Use consistent and reasonable indentation conventions throughout your program to improve program readability. Avoid using several spaces for an indent - instead use a tab. If there are several levels of indentation, each level should be indented the same additional amount of space. When you are finished, submit your source code file in Blackboard by the due date. Your source code file is the file that has the C++ code (the .cpp file). Don't submit the Visual Studio solution file (the .sln file). The only file you need to submit is the C++ source code file for your program. No picture or screen captures of your program is needed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Students also viewed these Databases questions

Question

How does selection differ from recruitment ?

Answered: 1 week ago

Question

What are Measures in OLAP Cubes?

Answered: 1 week ago

Question

How do OLAP Databases provide for Drilling Down into data?

Answered: 1 week ago

Question

How are OLAP Cubes different from Production Relational Databases?

Answered: 1 week ago