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.

Expert's answer

#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();
}
LATEST TUTORIALS
APPROVED BY CLIENTS