Question: Create a C++ console program that defines a class named EvenNumber that represents an even number. Create the class inside a separate header file (.h)

Create a C++ console program that defines a class named EvenNumber that represents an even number. Create the class inside a separate header file (.h) and then include this header in your main source code file.

The class should have one private integer data field to store the even number. The default constructor should initialize the data field to 0. Also define a 1-arg constructor that initializes the object with the specified value.

Define a public getter method named getValue that should return the even number stored in the data field.

Define 2 public setter methods. setNext should set the data field to the next greater even number (+2) and setPrevious should set it to the next lesser even number (-2).

From main, prompt the user to input an even number, validate it, and then create an EvenNumber object supplying the user's value to the constructor. Use the object's methods and a loop(s) to display the 3 even numbers on both sides of the user's number.

input: "6"; output: "0 2 4 6 8 10 12"

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!