Question: C++ Question: Implement an even number class. This class will only ever be even numbers. Make sure that you protect against odd numbers showing up

C++ Question:

Implement an even number class. This class will only ever be even numbers. Make sure that you protect against odd numbers showing up in this class. This is a precursor to overloading functions which we will talk about later in the course.

This class must implement:

  • EvenNumber() and EvenNumber(int num) two constructors, one that initializes the starting number at zero and another that allows the calling function to set the starting number.
  • getValue() interface method that returns the current value of the number
  • getNext() a method that will return the next even number and set the value represented by EvenNumber to the next even number
  • getPrevious() similar to getNext() but in reverse, returning and setting the previous even number.

The test program will contain two EvenNumbers, one will be set to zero, the other will be set by the user. Then, using a while loop and your two EvenNumber classes, count from one number to the next. You are not allowed to use any other int or floats in your main. The only numbers you can use are EvenNumbers.

If you implement PrimeNumber following a similar pattern, but instead of EvenNumbers, you are representing PrimeNumbers.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!