Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C + + Create a counter. The default constructor should set the count to zero. The overloaded constructor should initialize to any integer. Provide

In C++ Create a counter. The default constructor should set the count to zero. The overloaded constructor should initialize to any integer. Provide a display(), inc() and dec() method. Inc does ++ dec does on the private count variable. Use private: and public: where they should be used.Chapter 7
Create a counter. The default constructor should set the count to zero. The overloaded constructor should
initialize to any integer. Provide a display(), inc() and dec() method. Inc does ++ dec does -- on the private
count variable. Use private: and public: where they should be used.
Write a demo program that initializes one counter to 0 and the other to 200. Increment the first counter by
85 and decrement the second counter by 242. Use a for loop to increment and decrement.
Use a static variable to keep track of the total number of incs and decs. Keep in mind that after you declare a
static variable in a class, you must declare it outside the class and use the scope resolution operator.
Example:
Current state of C1(created with the default constructor)
Current count: 0
total increments and decrements 0
Current state of C2(created as C2(200))
Current count: 200
total increments and decrements 0
Current state of C1 after 85 inc()
Current count: 85
total increments and decrements 85
Current state of C2 after
Current count: -42
total increments and decrements 327
Press any key to continue. .
Write a demo program that initializes one counter to 0 and the other to 200. Increment the first counter by
85 and decrement the second counter by 242. Use a for loop to increment and decrement.
Use a static variable to keep track of the total number of incs and decs. Keep in mind that after you declare a static variable in a class, you must declare it outside the class and use the scope resolution operator.
Example:
Current state of C1(created with the default constructor)
Current count: 0
total increments and decrements 0
Current state of C2(created as C2(200))
Current count: 200
total increments and decrements 0
Current state of C1 after 85 inc()
Current count: 85
total increments and decrements 85
Current state of C2 after 242 dec()
Current count: -42
total increments and decrements 327
Press any key to continue ...
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

How to reverse a Armstrong number by using double linked list ?

Answered: 1 week ago

Question

General Purpose of Your Speech Analyzing Your Audience

Answered: 1 week ago

Question

Ethical Speaking: Taking Responsibility for Your Speech?

Answered: 1 week ago