Practical 7
Practical 7
PROGRAM: 1
#include<iostream.h>
#include<conio.h>
class abc{
public:
int a,b,i;
public:friend void xyz();};
void xyz(){
abc swap;
swap.a=10;
swap.b=20;
cout<<"before swapping:"<<endl;
cout<<"value of a:"<<swap.a<<endl;
cout<<"value of b:"<<swap.b<<endl;
swap.i=swap.a;
swap.a=swap.b;
swap.b=swap.i;
cout<<"after swapping:"<<endl;
cout<<"exchanged value of a:"<<swap.a<<endl;
cout<<"exchanged value of b:"<<swap.b<<endl;
}
void main(){
clrscr();
xyz();
getch();
}
OUTPUT:
PROGRAM: 2
#include<iostream.h>
#include<conio.h>
class test1{
int mr1;
public: void getdata(){
cout<<"enter marks 1:"<<endl;
cin>>mr1;
}
friend class test2;};
class test2{
int mr2;
public: void getdata1(){
cout<<"enter marks 2:"<<endl;
cin>>mr2;
}
void display(test1 &t)
{
cout<<"avg of two marks="<<(t.mr1+mr2)/2<<endl;
}
};
void main(){
test1 t1;
test2 t2;
clrscr();
t1.getdata();
t2.getdata1();
t2.display(t1);
getch();
}
OUTPUT: