Q:

Write a C++ program to Swap two numbers using class

0

Write a C++ program to Swap two numbers using class

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include<iostream>

using namespace std;

class swap
{
int a,b;
public:
void getdata();
void swapv();
void display();
};

void swap::getdata()
{
cout<<“Enter two numbers:”;
cin>>a>>b;
}

void swap::swapv()
{
a=a+b;
b=a-b;
a=a-b;
}

void swap::display()
{
cout<<“a=”<<a<<“tb=”<<b;
}

int main()
{

swap s;

s.getdata();
cout<<“\nBefore swap: \n”;
s.display();

s.swapv();
cout<<“nnAfter swap:n”;
s.display();

return 0;
}
 
 

OUTPUT :: 

swap two numbers using class

 

 

 

 

swap two numbers using class

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C++ Classes and Objects Solved Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Write a C++ program for various Mathematical Opera... >>
<< Write a C++ program to find Largest among 2 number...