Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
VolAreObject
//g++ 7.4.0 //Perimeter, Area and Volume of an Object //code is created by Rezaul Hoque on April 26, 2021 //please contact at jewelmrh@yahoo.com #include <iostream> #include <cmath> using namespace std; class object { public: virtual float area() { return length * breadth;} virtual float volume() { return length *breadth *height;} virtual float perimeter(){return 2*(length +breadth);} protected: float length, breadth, radius, height; }; class circle: public object{ public: circle(float r=0): radius (r) {} float perimeter() { return 2*M_PI*radius;} float area() { return M_PI*radius*radius;} protected: float radius; }; class rectangle: public object { public: rectangle(float l, float b): length (l), breadth (b) {} float perimeter(){ return 2*(length +breadth);} float area(){ return (length*breadth);} protected: float length, breadth; }; class triangle : public object { public: triangle (float x, float y, float z) : side1(x),side2(y), side3(z) {} float area () { float s; s= (side1+side2+side3)/2; return sqrt(s*(s-side1)*(s-side2)*(s-side3)); } protected: float side1, side2, side3; }; class cylinder: public object { public: cylinder(float r, float h): radius (r), height (h){} float area(){ return 2*M_PI*radius*(height + radius);} float volume(){ return M_PI*radius *radius * height;} protected: float radius, height; }; class sphere : public object { public: sphere (float r): radius (r) {} float area (){ return 4*M_PI*radius*radius;} float volume (){return 4*1/3*M_PI*radius*radius*radius;} protected: float radius; }; class cube: public object { public: cube(float l, float b, float h): length (l), breadth (b), height (h){} float area(){ return 2*(length *breadth + length *height + height *length);} float volume(){ return length * breadth * height;} protected: float length, breadth, height; }; int main () { circle ci(2); rectangle rect(5,2); triangle tri(2,3,4); cylinder cyl(2,4); sphere sp(2); cube cub(4,3,2); cout<<"Circle's perimeter is "<<ci.perimeter()<<" unit.\n"; cout<<"Circle's area is "<<ci.area()<<" square unit.\n"; cout<<"Rectangle's perimeter is "<<rect.perimeter()<<" unit.\n"; cout<<"Rectangle's area is "<<rect.area()<<" square unit.\n"; cout<<"Triangle's area is "<<tri.area()<<" square unit.\n"; cout<<"Cylinder's area is "<<cyl.area()<<" square unit.\n"; cout<<"Cylinder's volume is "<<cyl.volume()<<" cube unit.\n"; cout<<"Sphere's area is "<<sp.area()<<" square unit.\n"; cout<<"Sphere's volume is "<<sp.volume()<<" cube unit.\n"; cout<<"Cube's area is "<<cub.area()<<" square unit.\n"; cout<<"Cube's volume is "<<cub.volume()<<" cube unit.\n"; return 0; }
run
|
edit
|
history
|
help
0
inversion of array using merge sort
GRAPH DFS & BFS
shuffle_example
tasks
Binary tree balanced or not
Barnicle
Boggle Game
codechef
2015(M2)Simulare
Biggest even palindrom