Answer to Question #77728 in C++ for Britt

Question #77728
A microwave control panel has four buttons: one for increasing the time by 30 seconds, one for switching between power levels 1 and 2, a reset button, and a start button. Implement a class that simulates the microwave, with a member function for each button. The member function for the start button should print a message “Cooking for ... seconds at level ...”.
1
Expert's answer
2018-06-01T04:55:18-0400
#include<iostream>
using namespace std;
class Microwave
{
int seconds;
int power_level;
public:
Microwave();
void switch_level();
void start();
void reset();
};
Microwave::Microwave()
{
//default values;
seconds = 30;
power_level = 1;
}
void Microwave::switch_level(){
if(power_level == 1){
power_level = 2;
}
else{
power_level = 1;
}
}
void Microwave::start(){
cout << "Cooking for " << seconds << " seconds at level " << power_level;
}
void Microwave::reset(){
//setting values to default;
seconds = 30;
power_level = 1;
}

int main(){
Microwave microwave;
microwave.start();
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS