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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started