#include<iostream.h>
#include<conio.h>
class sample
{
private:
int x,y;
public:
void setdata(int a,int b)
{
x=a;
y=b;
}
void showdata()
{
cout<<"x="<<x<<"\ny="<<y;
}
friend void swap(sample &s);
};
void swap(sample &s)
{
int temp;
temp=s.x;
s.x=s.y;
s.y=temp;
}
void main()
{
sample s;
int x1,x2;
clrscr();
cout<<"\nInput 2 Numbers:";
cin>>x1>>x2;
s.setdata(x1,x2);
cout<<"\nBefore Swapping\n";
s.showdata();
cout<<"\nAfter Swapping\n";
s.showdata();
getch();
}
#include<conio.h>
class sample
{
private:
int x,y;
public:
void setdata(int a,int b)
{
x=a;
y=b;
}
void showdata()
{
cout<<"x="<<x<<"\ny="<<y;
}
friend void swap(sample &s);
};
void swap(sample &s)
{
int temp;
temp=s.x;
s.x=s.y;
s.y=temp;
}
void main()
{
sample s;
int x1,x2;
clrscr();
cout<<"\nInput 2 Numbers:";
cin>>x1>>x2;
s.setdata(x1,x2);
cout<<"\nBefore Swapping\n";
s.showdata();
cout<<"\nAfter Swapping\n";
s.showdata();
getch();
}
bro there no swaping ,,,,,,u didnt call swap function..
ReplyDeleteits useless this program does not swap the nos
ReplyDeletesimply waste our time rubbish if you don"t know how write program y you publish it
ReplyDelete#include
ReplyDeleteusing namespace std;
class second;
class first{
int x;
public:void get(){
cout<<"x is:";
cin>>x;
}
void display(){
cout<<"result x"<>y;
}
void display(){
cout<<"result y"<<y<<endl;
}friend void swap(first &,second &);
};void swap(first &a,second &b){
int c;
c=a.x;
a.x=b.y;
b.y=c;
}
main(){
first a1;
second b1;
a1.get();
b1.get();
a1.display();
b1.display();
swap(a1,b1);
a1.display();
b1.display();
}
sami colon missing after void swap function line no.15.
ReplyDelete#include
ReplyDelete#include
class sample
{
private:
int x,y;
public:
void setdata(int a,int b)
{
x=a;
y=b;
}
void showdata()
{
cout<<"x="<>x1>>x2;
s.setdata(x1,x2);
cout<<"\nBefore Swapping\n";
s.showdata();
swap(s);
cout<<"\nAfter Swapping\n";
s.showdata();
getch();
}
Guys this is the correct program you'll surely get the output