Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Define and test a class for a type called CounterType. An object of this type is used to count things, so it records a count

Define and test a class for a type called CounterType. An object of this type is used to count things, so it records a count that is a non-negative whole number.

Include member functions to increase the count by one and to decrease the count by one. Be sure that no member function allows the value of the counter to become negative.

Also include a member function that returns the current count value and one that outputs the count

Embed your class definition in a test program.

Using the code:

CounterType.h

#ifndef COUNTERTYPE_H

#define COUNTERTYPE_H

#include

using namespace std;

class CounterType {

public:

// prototype of setCount method

// prototype of increase method

// prototype of decrease method

// prototype of getCount method, returns count value

// prototype of output method, use ostream object

private:

int count;

};

#endif

CounterType.cpp

#include "CounterType.h" // implementation of the setCount method:

// implementation of the increase method:

// implementation of the decrease method:

// implementation of the getCount method:

// implementation of the output method:

Source.cpp:

#include "CounterType.h"

void main(){

// create a CounterType Object

// set the object count variable to a positive value

// test the increase method 5 times. you can use for loop here

// test the output method

// print on the screen the value of count using a simple cout operation, make sure to use the getCount method

// test the decrease method 7 times, also you can use a for loop

// test the output method

system("pause");

}

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

Recommended Textbook for

Concepts of Database Management

Authors: Philip J. Pratt, Mary Z. Last

8th edition

1285427106, 978-1285427102

More Books

Students also viewed these Databases questions

Question

Is having a positive self-concept really all that important?

Answered: 1 week ago