Design and implement a class called Buzzer with the followin

Design and implement a class called Buzzer with the following features (no main function). The buzzer has two buttons: green and red each of which can be configured to print a customized string. Here is a list of words that the buttons cannot be configured with: \"hate\", \"fail\" and \"dislike\". Once configured, the user can press either button and the corresponding string should be displayed. If the user presses a button before successfully configuring it, \"Configure me!\" should be displayed.

Solution

#include<iostream>
using namespace std;

class Buzzer
{
private:
string red,green;

public:
Buzzer()
{
red = \"Configure Me!\";
green = \"Configure Me!\";
}

void configureRed()
{
string str;
cout << \"Enter the string for Red button : \";
cin >> str;

while(str.compare(\"hate\")==0 || str.compare(\"dislike\")==0 || str.compare(\"fail\")==0)
{
cout << \"Please enter a valid string.It cannot be in (hate,dislike,fail) : \";
cin >> str;
}

red = str;
}

void configureGreen()
{
string str;
cout << \"Enter the string for Green button : \";
cin >> str;

while(str.compare(\"hate\")==0 || str.compare(\"dislike\")==0 || str.compare(\"fail\")==0)
{
cout << \"Please enter a valid string.It cannot be in (hate,dislike,fail) : \";
cin >> str;
}

green = str;
}

void pressRedButton()
{
cout << red << endl;
}

void pressGreenButton()
{
cout << green << endl;
}
};
int main()
{
Buzzer b;
b.pressRedButton();
b.configureRed();
b.pressRedButton();
return 0;
}

OUTPUT:

Configue Me!
Enter the string for Red button : dislike
Please enter a valid string.It cannot be in (hate,dislike,fail) : happy
happy

 Design and implement a class called Buzzer with the following features (no main function). The buzzer has two buttons: green and red each of which can be confi
 Design and implement a class called Buzzer with the following features (no main function). The buzzer has two buttons: green and red each of which can be confi

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site