Professional Documents
Culture Documents
-------------------------------------------------------
EXPERIMENT - 1
PROGRAM :
1. WAP to swap two integers without using a third variable. The
#include <iostream>
class c1{
int val1;
friend void exchange(c1 &,c2 &);
public:
void intdata(int a){
val1 = a;
}
void display(void){
cout<< val1 <<endl;
}
};
class c2{
int val2;
friend void exchange(c1 &,c2 &);
public:
void intdata(int a){
val2 = a;
}
void display(void){
cout<< val2 <<endl;
}
};
/*trick to swap 2 number a and b;
temp = a;
a = b;
b = temp;
*/
}
int main()
{
c1 oc1;
c2 oc2;
oc1.intdata(48);
oc2.intdata(978);
exchange(oc1,oc2);
return 0;
}
OUTPUT:
PROGRAM:
#include <iostream>
class Box {
public:
double length;
double breadth;
double height;
double getVolume(void);
void setLength( double len );
void setBreadth( double bre );
void setHeight( double hei );
};
int main() {
Box Box1;
Box Box2;
double volume = 0.0;
Box1.setLength(32.0);
Box1.setBreadth(5.0);
Box1.setHeight(5.0);
Box2.setLength(12.0);
Box2.setBreadth(78.0);
Box2.setHeight(10.0);
volume = Box1.getVolume();
cout << "Volume of Box1 : " << volume <<endl;
volume = Box2.getVolume();
cout << "Volume of Box2 : " << volume <<endl;
return 0;
}
OUTPUT:
Volume of Box1 : 800
Volume of Box2 : 9360
—------------------------------------------------------------------------------------------
------------------------
EXPERIMENT - 3
PROGRAM:
#include <iostream>
using namespace std;
class y;
class x{
int data;
public:
void setvalue(int value){
data = value;
}
friend void add(x,y);
};
class y{
int num;
public:
void setvalue(int value){
num = value;
}
friend void add(x,y);
};
void add(x o1,y o2){
cout<<"suming data of x and y objects gives
me "<<o1.data + o2.num;
}
int main(){
x a1;
a1.setvalue(14);
y b1;
b1.setvalue(95);
add(a1,b1);
return 0;
}
OUTPUT:
—---------------------------------------------------------------
EXPERIMENT - 4
PROGRAM:
#include <iostream>
#include <cmath>
#include <iomanip>
int main()
{
Sphere sphere(9.0);
OUTPUT:
Sphere :
Radius = 9
Area of Sphere = 1017.36
Volume of Sphere = 3052.08
Cone :
Radius = 7, Height = 7
Area of Cone = 371.451
Volume of Cone = 17591.3
—----------------------------------------
---------------------------------
EXPERIMENT - 5
Program:
#include<iostream>
using namespace std;
class LIST{
public:
virtual void store(int) = 0;
virtual int retrieve() = 0;
};
OUTPUT:
3
2
1
1
2
3
—------------------------------------------------------------
--------------------------------------------------------
EXPERIMENT - 7
PROGRAM:
#include<iostream>
using namespace std;
class bank
{
private:
string name;
long int accno;
string acc_type ;
long int balance;
public:
bank(){};
bank(string n,long int ano ,long int
bal,string sa)
{
name=n;
accno=ano;
balance=bal;
acc_type = sa;
}
void setdata()
{
acc_type = "saving";
cout<<"enter the name of account
holder : "<<endl;
cin>>name;
cout<<"enter the account number
of candidate : "<<endl;
cin>>accno;
cout<<"enter the balance :
"<<endl;
cin>>balance;
}
void check();
void deposit();
void display();
};
int main()
{
bank candidate;
candidate.setdata();
candidate.deposit();
candidate.check();
candidate.display();
}
OUTPUT:
—-------------------------------------------------------
----------------------------------------------------------
EXPERIMENT - 8
PROGRAM: