Question: I need help with my C + + program. Program below is a a class called MotorStatus and you may only modify the turnOff function
I need help with my C program. Program below is a a class called MotorStatus and you may only modify the turnOff function and main function.
The turnOff function should turn off the guessed motor if it is over heating and return true if the correct motors are turned off. not working
If the motor is not overheating it leave it in is original state onoff respectively.not working
If the user guesses wrong the overheating motor will get so hot another motor will overheat. working updateOverheating
I need help with how to debug the code and fix turnOff to correctly shut down the correct motors according to the user input.The program is listed below:
#include
#include
#include
#include
class MotorStatus
private:
uintt motorState; Each bit represents the status of a motor onoff
uintt overheatingMotors; Motors that are overheating
int turnCount;
Function to randomly initialize motors onoff and overheat one motor
void initialize
srandtime;
motorState rand; Randomly turn motors onoff
updateOverheating; Randomly overheat one motor
turnCount ;
displayStatus;
Incrementally overheat motors with each turn, ensuring the motor is ON and
not already overheating
void updateOverheating
int newMotor;
do
newMotor rand; Randomly select a motor
while newMotor & motorState Ensure the motor is ON
newMotor & overheatingMotors; Ensure the motor
is not already overheating
overheatingMotors newMotor; Set the selected motor to
overheat
turnCount;
void displayStatus
std::cout "Motor State ONOFF: std::bitsetmotorState
std::endl;
std::cout "Overheating Motors: std::bitsetoverheatingMotors
std::endl;
std::cout "Turn Count: turnCount std::endl;
public:
MotorStatus
initialize;
Simulate a guess attempt
bool turnOffuintt guess
turn off the motors that are associated with the guess
motorState overheatingMotors & guess;
if guess motorState
Motors that are not overheating and were turned off are restored to ON
updateOverheating; Each incorect guess makes another motor overheat
displayStatus;
return false;
Display current motor status for debugging purposes
;
int main
MotorStatus motorStatus;
uintt guess b; Start with all motors off
Loop until all motors are turned off
while motorStatus.turnOffguess
The student can use bitwise ANDORXOR here to adjust the guess based on
the feedback
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
