Question #181766


Write a c++ program that uses a simple parametrized constructor to find whether the number entered by the user is Even, Odd or Zero. Copy the same value in another object using copy constructor and show the result separately in a user-defined function named Display().


Expert's answer

#include <stdio.h>
using namespace std;


// Write a c++ program that uses a simple parametrized constructor to find 
// whether the number entered by the user is Even, Odd or Zero. 
// Copy the same value in another object using copy constructor and 
// show the result separately in a user-defined function named Display().

class construct
{
public:
    int a, b;
    // Default Constructor
    int CheckNum(int Num)
    {
        int Flag=0;
		if(Num==0)		Flag=0;
		if(Num%2==0)	Flag=2;
		if(Num/2==1)	Flag=1;
        return(Flag);
    }
	void Display(int Flag)
	{
		if(Flag==0) cout<<"\n\nThe  entered number is ZERO.";
		if(Flag==1) cout<<"\n\nThe  entered number is ODD.";
		if(Flag==2) cout<<"\n\nThe  entered number is EVEN.";
	}
};
 
int main()
{
    int n,a;
	// Default constructor called automatically
    // when the object is created
	construct c;
	cout<<"\nEnter a number: "; cin>>n;    
    a = c.CheckNum(n);
    c.Display(a);
    return (0);
}
LATEST TUTORIALS
APPROVED BY CLIENTS