Answer to Question #220661 in C++ for Chirag

Question #220661

Accept one number and find out if its positive or negative number using class


1
Expert's answer
2021-07-27T07:43:43-0400
/******************************************************************************
Accept one number and find out if its positive or negative number using class


*******************************************************************************/


#include <iostream>


using namespace std;
class PosNeg{
    private:
        int num;
    public:
        void checkPosNeg(int n){
            num=n;
            if (num>0)
                cout<<num<<" is positive.";
            else if (num<0)
                cout<<num<<" is negative.";
            else
                cout<<num<<" is zero";
        }
};
int main()
{
    PosNeg p;
    int x;
    cout<<"Enter a number: ";
    cin>>x;
    p.checkPosNeg(x);


    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