C++ Program to check number is even or odd using class
In this program, You will learn how to check number is even or odd using class and object in C++.
class Test {
//statement
};
Example: How to check number is even or odd using class in C++.
#include<iostream>
using namespace std;
class Test {
int num;
public:
void input() {
cout << "Enter a number:";
cin>>num;
}
void check() {
if (num % 2 == 0) {
cout << "Number is even:" << num;
} else {
cout << "Number is odd:" << num;
}
}
};
int main() {
Test tt;
tt.input();
tt.check();
return 0;
}
Output:
Enter a number:14
Number is even:14