Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem 1 (10 points) Design an ADT \"Buzzer\" The Buzzer is a device with two b

ID: 3600767 • Letter: P

Question

Problem 1 (10 points) Design an ADT "Buzzer" The Buzzer is a device with two buttons, green and red, that can be configured with respective "shout" strings. Imagine the Buzzer being used in a game by the audience to "Buzz" for or against a team. When a person pushes the green button on the Buzzer, it can shout (i.e. display), for example, "go spurs"; when the red button is pushed, it can shout "boooo". What it shouts should be configurable. Support the following operations on the buzzer: (1) a default constructor to "initialize" the buzzer to some safe shout strings for the red and green buttons (e.g. "configure me before using!"), (2) a parameterized constructor that initializes the red and green buttons to user-specified strings, (3) a destructor, (4) a copy constructor, (5) a config_red function to configure the string for the red button, (6) a config green function to configure the string for the green button, (7) a push_red button functiorn that displays the string configured for the red button, (8) a push_green button function that display the string configured for the green button, (9) use the keyword "const" to label const functions and const object inputs, (10) a static function to display the number of buzzer objects currently alive in memory Demonstrate that your code works using a main function.

Explanation / Answer


The class Buzzer is an ADT for Buzzer. The Default Constructor, Copy Constructor, Parameterized Constructor and Destructor have been implemented.
The methods for getting the buttonbutton values and setting the button values are also implemented.
Kindly go through the code. Comments have been provided.
The Destructor is called at the end of the program automatically. Here three times it has been called.
The number of objects alive has also been displayed. Here it is 3 objects. If uou have further queries. Kindly comment below.
The outputs have also been provided.
*******************************************************************
#include <iostream>

using namespace std;


class Buzzer {
   public:
      static int objectCount;
      string redButton;
      string greenButton;
      // Default Constructor definition
      Buzzer() {
         redButton="configure me before using!";
         greenButton="configure me before using!";
         // Increase every time object is created
         objectCount++;
      }
      //Parameterized Constructor definition
      Buzzer(string red, string green) {
         redButton=red;
         greenButton=green;
         // Increase every time object is created
         objectCount++;
      }
      //Destructor definition
      ~Buzzer() {
         cout << "Destructor called" << endl;
         objectCount--;
      }
      //Copy Constructor definition
      Buzzer(const Buzzer &b) {
         redButton=b.redButton;
         greenButton=b.greenButton;
         objectCount++;
      }
      //Function to config red button
      string config_redButton(string red){
        redButton=red;
     }
     //Function to config green button
     string config_greenButton(string green){
        return green;
     }
     //Function to show red button
     string push_redButton(){
        return redButton;
     }
     //Function to show green button
     string push_greenButton(){
        return greenButton;
     }

     static int getCount() {
         return objectCount;
     }

};

// Initialize static member of class Buzzer
int Buzzer::objectCount = 0;

int main(void) {
   // Print total number of objects before creating object.
   Buzzer buzzer1;
   cout << "Buzzer 1" << endl;
   cout << "The red buzzer value: " << buzzer1.push_redButton() << endl;
   cout << "The green buzzer value: " << buzzer1.push_greenButton() << endl;
   cout << "**********************" << endl;
   cout << "Buzzer 2" << endl;
   cout << "Enter user defined red button value:" << endl;
   string red;
   std::getline(std::cin,red);
   cout << "Enter user defined green button value:" << endl;
   string green;
   std::getline(std::cin,green);
   Buzzer buzzer2(red,green);

   cout << "The red buzzer value: " << buzzer2.push_redButton() << endl;
   cout << "The green buzzer value: " << buzzer2.push_greenButton() << endl;
   cout << "**********************" << endl;
   cout << "Buzzer 3" << endl;
   Buzzer buzzer3 = Buzzer(buzzer2);
   cout << "The red buzzer value: " << buzzer3.push_redButton() << endl;
   cout << "The green buzzer value: " << buzzer3.push_greenButton() << endl;
   // Print total number of objects after creating object.
   cout << "Buzzer objects alive in memory: " << Buzzer::getCount() << endl;

   return 0;
}

****************************************************************************
Sample output:
Buzzer 1
The red buzzer value: configure me before using!
The green buzzer value: configure me before using!
**********************
Buzzer 2
Enter user defined red button value:
booo
Enter user defined green button value:
go spurs
The red buzzer value: booo
The green buzzer value: go spurs
**********************
Buzzer 3
The red buzzer value: booo
The green buzzer value: go spurs
Buzzer objects alive in memory: 3
Destructor called
Destructor called
Destructor called

Process returned 0 (0x0)   execution time : 13.916 s
Press any key to continue.


****************************************************************************
I hope this helps you.
If you find my answer helpful,
Kindly rate the answer.
All the best :)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote