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

Answer to Question #3421 in C++ for Shikha Sharma

Question #3421
Write a program to swap 2 numers using class
Expert's answer
#include <iostream>
using std::cout;
using std::cin;
using std::endl;

class Numbers
{
public:
& Numbers ():
X(0), Y(0) {}
& Numbers (int x, int y):
X(x), Y(y) {}
& void ShowNumbers ();
& void Swap ();
private:
& int X;
& int Y;
};

void Numbers::ShowNumbers ()
{
cout<< "X =\t"<< X<< endl;
cout<< "Y =\t"<< Y<< endl;
}

void Numbers::Swap ()
{
int temp;
temp = X;
X = Y;
Y = temp;
}


int main ()
{
int x, y;
cout<< "Enter two numbers separated by space (X Y)\n> ";
cin >> x >> y;
Numbers num(x, y);
cout<< "\nBefore swap:"<< endl;
num.ShowNumbers ();
num.Swap ();
cout<< "\nAfter swap:"<< endl;
num.ShowNumbers();
system("pause");
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