Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Graph Databases In Action

Authors: Dave Bechberger, Josh Perryman

1st Edition

1617296376, 978-1617296376

More Books

Students also viewed these Databases questions

Question

How is a depositary receipt issued and how does it get cancelled?

Answered: 1 week ago