119k views
5 votes
Define the EvenNumber class for representing an even number. The class contains:

A data field value of the int type that represents the integer value stored in the object.
A no-arg constructor that creates an EvenNumber object for the value 0.
A constructor that constructs an EvenNumber object with the specified value.
A function named getValue() to return an int value for this object.
A function named getNext() to return an EvenNumber object that represents the next even number after the current even number in this object.
A function named getPrevious() to return an EvenNumber object that represents the previous even number before the current even number in this object.
Draw the UML diagram for the class. Implement the class. Write a test program that creates an EvenNumber object for value 16 and invokes the getNext() and getPrevious() functions to obtain and displays these numbers.
A. (The EvenNumber class) Define the EvenNumber class for representing an even number. The class contains:  A data field value of the int type that represents the integer value stored in the object.  A no-arg constructor that creates an EvenNumber object for the value 0.  A constructor that constructs an EvenNumber object with the specified value.  A function named getValue() to return an int value for this object.  A function named getNext() to return an EvenNumber object that represents the next even number after the current even number in this object.  A function named getPrevious() to return an EvenNumber object that represents the previous even number before the current even number in this object. Draw the UML diagram for the class. Implement the class. Write a test program that creates an EvenNumber object for value 16 and invokes the getNext() and getPrevious() functions to obtain and displays these numbers. B. Revise the EvenNumber class in Programming Exercise 2A to implement the preincrement, predecrement, postincrement, and postdecrement operators for getNext() and getPrevious() functions. Write a test program that creates an EvenNumber object for value 16 and invokes the ++ and -- operators to obtain next and previous even numbers.
B.Revise the EvenNumber class in Programming Exercise 2A to implement the preincrement, predecrement, postincrement, and postdecrement operators for getNext() and getPrevious() functions. Write a test program that creates an EvenNumber object for value 16 and invokes the ++ and -- operators to obtain next and previous even numbers.

User Krish
by
7.8k points

1 Answer

6 votes

Answer:

#include <iostream>

using namespace std;

class EvenNumber

{

private:

int integrer;

public:

EvenNumber ()

{

integrer=0;

}

EvenNumber (int number)

{

integrer=number;

}

int getvalue ()

{

return integrer;

}

int getnext ()

{

return integrer+2;

}

int getprevious ()

{

return integrer-2;

}

};

int main () {

EvenNumber sixteen(16);

cout<<"The value is: "<<sixteen.getvalue()

<<" the next even number is: "<<sixteen.getnext()<<

" and the previous number is: "<<sixteen.getprevious();

return 0;

}

Step-by-step explanation:

User Anthony Persaud
by
8.1k points