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
Chapter11: Inheritance And Composition
Section: Chapter Questions
Problem 1PE: In Chapter 10, the class clockType was designed to implement the time of day in a program. Certain...
icon
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
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
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;
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
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Function Arguments
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.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT