Question #244774

Create a class of subtraction having two private data members. Create class methods
to get data from users and for subtraction of data members. Use appropriate access
modifiers for class methods.

Expert's answer

Source code



#include <iostream>


using namespace std;
class subtraction{
    private:
        int x;
        int y;
    public:
        void getData(){
            cout<<"\nEnter first number: ";
            cin>>x;
            cout<<"\nEnter second number: ";
            cin>>y;
        }
        void subtract(){
            int sub=x-y;
            cout<<"\n"<<x<<" - "<<y<<" = "<<sub;
        }
};
int main()
{
    subtraction s1;
    s1.getData();
    s1.subtract();


    return 0;
}


Output





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!

LATEST TUTORIALS
APPROVED BY CLIENTS