Copy this class declaration below into the top of your main.cpp file. The Button
ID: 440714 • Letter: C
Question
Copy this class declaration below into the top of your main.cpp file. The Button class represents a physical button. All it does is keep track of the number of times it has been pressed. class Button { private: int pressCount; // starts at 0 public : // CONSTRUCTOR Button(); // MUTATOR void Press(); // increments the pressCount // ACCESSOR int timesPressed(); }; Then do each of these steps: Write the definitions of the three member functions. Place this code below main(). Inside main(), create a single new variable of type Button. Then, add code that calls its mutator and accessor functions to demonstrate that it works as expected.Explanation / Answer
#include #include using namespace std; class Button{ private: //not really necessary here since it is private by default for classes in Cpp pressCount;//starts at 0 public: //CONSTRUCTOR Button(); //MUTATOR void Press();//increments the pressCount //ACCESSOR int TimesPressed(); }; int main(){ Button test; coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.