//Program : Part A-1
//write a c++ program to calculate the volume of cube, cylinder and rectangle using //function overloading.
//Name : LDK E-NOTES Reg.Number : **********
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
class cube
{
private:
float v;
public:
void display()
{
cout<<"\n Volume = "<<v<<endl;
}
int volume(int s)
{
v=s*s*s;
return v;
}
int volume(int r,int ht)
{
v=3.14*r*r*ht;
return v;
}
int volume(int l,int b,int h)
{
v=l*b*h;
return v;
}
};
void main()
{
cube c;
clrscr();
int s;
cout<<"\n Enter side of cube : ";
cin>>s;
c.volume(s);
c.display();
int r,ht;
cout<<"\n Enter radius and height of cylinder : ";
cin>>r>>ht;
c.volume(r,ht);
c.display();
int l,b,h;
cout<<"\n Enter lenght,breadth,height of rectangle : ";
cin>>l>>b>>h;
c.volume(l,b,h);
c.display();
getch();
}
Output 1 :
Enter side of cube : 6
Volume = 216
Enter radius and height of cylinder : 3 4
Volume = 113.040001
Enter lenght,breadth,height of rectangle : 2 3 7
Volume = 42
Output 2 :
Enter side of cube : 3
Volume = 27
Enter radius and height of cylinder : 4 3
Volume = 150.720001
Enter lenght,breadth,height of rectangle : 4 2 8
Volume = 64
No comments:
Post a Comment