Different parity
Description
defines the class Integer, including:
1. An attribute data of type int.
2. Constructor.
3. The bool judge() method: Find the sum of the digits of data, if the sum is even, it returns false, otherwise it returns true.
Input
Enter several positive integers, each on a line.
Output
Each line of input corresponds to a line of output, which is the output result of calling the judge() method on the object corresponding to each line of input.
Sample Input
123
456
1
33
Sample Output
NO
YES
YES
NO
Title given code
int main()
{
int i;
while (cin >> i)
{
Integer INT(i);
if (INT.judge())
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}
code:
#include<iostream>
using namespace std;
class Integer{
int data;
public:
Integer(int i){
data=i;
}
bool judge(){
int num=data;
if(num<0)num=-num;
int sum=0;
while(num){
sum+=num%10;
num/=10;
}
if(sum%2==0)return false;
else return true;
}
};
int main()
{
int i;
while (cin >> i)
{
Integer INT(i);
if (INT.judge())
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}