Answer to Question #244774 in C++ for Asim

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.
1
Expert's answer
2021-10-02T01:36:51-0400

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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS