Answer to Question #245218 in C++ for Yasir

Question #245218
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-01T16:53:09-0400
#include<iostream>
using namespace std;
class subtraction{
	private:
		int first;
		int second;
	public:
		subtraction(){
			first  = 0;
			second  = 0 ;
		}
		void get_numbers(int a, int b){
			cout<<"Enter the first number:\n";
			cin>>a;
			cout<<"Enter the second number:\n";
			cin>>b;
			first = a;
			second = b;
			
			
		}
		void display(){
			cout<<"The difference is:  "<<first  -  second<<endl;
		}
};


int main(){
	int a,  b;
	subtraction c;
	c.get_numbers(a,b);
	c.display();
}

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