Answer to Question #181766 in C++ for sohaib

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().


1
Expert's answer
2021-04-16T01:14:42-0400
#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);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS