63 046
Assignments Done
99,1%
Successfully Done
In July 2018

Answer to Question #34060 in C++ for Harshit Garg

Question #34060
write a program to swap two numbers by using classes?
Expert's answer
#include <iostream>


using namespace std;


class numbers{
public:
//method for swa[]
void swap(){
int c = a;
a = b;
b = c;
}


//method for input information
void getNumbers(){
cout << "Input two numbers: ";
cin >> a >> b;
}


//method for print numbers
void printNumbers(){
cout << "Number a is " << a << endl << "Number b is " << b << endl;
}


private:
int a, b;
};


int main(){
//object of class
numbers myNum;


myNum.getNumbers();
myNum.printNumbers();
myNum.swap();
cout << "After swap" << endl;
myNum.printNumbers();


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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions