Design and implement a class called Buzzer with the followin
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

