C++ Programing in Lab
C++ Programing in Lab
FUNCTION OVERLOADING
#include<iostream.h>
#include<conio.h>;
float pi=3.14;
void volume(int r);
void volume(int r,int h);
void area(int r);
void area(int l,int w);
void main()
{
int r,h,w,l;
clrscr();
cout<<"\n\t\t\t FUNCTION OVERLOADING\n";
cout<<"\n\t INPUT:\n";
cout<<"\n\t ENTER THE RADIUS AND HEIGHT:";
cin>>r>>h;
cout<<"\n\t ENTER THE LENGTH AND WIDTH:";
cin>>l>>w;
cout<<"\n\t OUTPUT:\n";
volume(r);
volume(r,h);
area(r);
area(l,w);
getch();
}
void volume(int r)
{
float f;
f=1.33*pi*r*r*r;
cout<<"\n\t The Volume of the Sphere is:"<<f;
}
void volume(int r,int h)
{
float f;
f=pi*r*r*h;
cout<<"\n\t The Volume of the Cylinder is:"<<f;
}
void area(int r)
{
float a;
a=pi*r*r;
cout<<"\n\t The volume of the Circle is:"<<a;
}
void area(int l,int w)
{
float a;
a=(l*w);
cout<<"\n\t The Volume of the Rectangle is:"<<a;
}
OUTPUT
INLINE FUNCTION
#include <iostream>
#include<conio>
int sum(float a,int b){
cout<<"using functions with 2 arguments"<<endl;
return a+b;
}
int sum(int a,int b,int c){
cout<<"using unctions with 3 arguments"<<endl;
return a+b+c;
}
int volume(double r,int h){
return(3.14*r*r*h);
}
int volume(int a){
return(a*a*a);
}
int volume(int l,int b,int h){
return(l*b*h);
}
int main(){
cout<<"the sm of 1 and 2 is"<<sum(1,2)<<endl;
cout<<"the sum of 1,2 and 5 is"<<sum(1,2,5)<<endl;
cout<<"the volume of cuboid of 1,2 and 5 is"<<volume(1,2,5)<<endl;
cout<<"the volume of clinder of radius 1 and height 5
is"<<volume(1,5)<<endl;
cout<<"the volume o cube o side 1 is"<<volume(1)<<endl;
return 0;
}
2.IMPLEMENTING CLASS AND OBJECTS
#include <iostream>
#include<conio>
class Room
{
public:
double length;
double breadth;
double height;
double calculateArea() {
return length * breadth;
}
double calculateVolume() {
return length * breadth * height;
}
};
int main() {
Room room1;
room1.length = 42.5;
room1.breadth = 30.8;
room1.height = 19.2;
return 0;
}