Define a class for a type called Counter An object of this type is used to count things. Include a default constructor that sets the counter to zero and a constructor with one argument that sets the counter to the value specified by its argument. Write member functions to increase the value by one (called increment) and decrease the value by one (called decrement ), don't let the value go below 0. Write a member function (print) that prints out the value of the counter. Here's a driver program that you should include to test your class. 39 Bint main() 40 Counter cl; Counter c2(10); 41 42 43 cout « "Ci starts at "; cl.print(); cout < end1; 44 45 46 47 cl.increment(); c1.increment(); 48 49 50 cout << "ci now at ": cl. print(); cout « endl; 51 52 53 54 55 cl - c2; 56 c1.decrement(); 57 58 cout << "ci now at ", cl. print(); cout << endl: return e
Define a class for a type called Counter An object of this type is used to count things. Include a default constructor that sets the counter to zero and a constructor with one argument that sets the counter to the value specified by its argument. Write member functions to increase the value by one (called increment) and decrease the value by one (called decrement ), don't let the value go below 0. Write a member function (print) that prints out the value of the counter. Here's a driver program that you should include to test your class. 39 Bint main() 40 Counter cl; Counter c2(10); 41 42 43 cout « "Ci starts at "; cl.print(); cout < end1; 44 45 46 47 cl.increment(); c1.increment(); 48 49 50 cout << "ci now at ": cl. print(); cout « endl; 51 52 53 54 55 cl - c2; 56 c1.decrement(); 57 58 cout << "ci now at ", cl. print(); cout << endl: return e
C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter13: Overloading And Templates
Section: Chapter Questions
Problem 23SA
Related questions
Question
In C++
![An example run of the program is shown below:
IS ./labl2
Ci starts at 0
Ci now at 2
Cl now at 9
(mingli@polaris:~/TA]S
sing the followings](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fd8bfd76a-eb00-40a9-ae7f-379c707f8f2f%2Fd597615d-b6d6-4491-b5e1-f101a76302f0%2Fz8hfkho_processed.jpeg&w=3840&q=75)
Transcribed Image Text:An example run of the program is shown below:
IS ./labl2
Ci starts at 0
Ci now at 2
Cl now at 9
(mingli@polaris:~/TA]S
sing the followings

Transcribed Image Text:Define a class for a type called Counter
An object of this type is used to count things. Include a default
constructor that sets the counter to zero and a constructor with one argument that sets the counter to the value
specified by its argument. Write member functions to increase the value by one (called increment) and decrease
the value by one (called decrement ), don't let the value go below 0. Write a member function (print) that prints
out the value of the counter.
Here's a driver program that you should include to test your class.
39
Bint main()
40
Counter cl;
Counter c2(10);
41
42
43
cout << "ci starts at ":
cl.print();
cout « endl3;
44
45
46
47
cl.increment();
c1.increment();
48
49
cout << "ci now at ":
cl. print();
cout « end1;
51
52
53
54
55
cl - c2;
56
cl.decrement();
57
58
cout << "ci now at ,
cl. print();
cout < end1;
return 0;
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you

C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning

Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,

EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT

C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning

Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,

EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT

C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr

Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage