Skip to main content

Write a C++ program to calculate area of circle,sphere and cylinder using base class round-shape

Create a base class round-shape(radius). define three different
shapes as circle, sphere and cylinder(height) from round-shape.
class round-shape
{
protected :float radius;
public:static float pi;
round-shape(float)//default argument
virtual float area()=0;
}
Write a C++ program to calculate area of circle,sphere and cylinder



#include<iostream.h>
#include<conio.h>
class round
{
protected:float radius;
public:static float pi;
       round(float r=0)
       {
       cout<<"\n Enter the radius:-";
       cin>>r;
       radius=r;
       }
       virtual float area()=0;
       };
class circle:public round
{
public:float circle;
       float area()
       {
       circle=pi*radius*radius;
       cout<<"\n Area of circle:-"<<circle;
       return 0;
       }
       };
class sphere:public round
{
public:float sph;
       float area()
       {
       sph=4*pi*radius*radius;
       cout<<"\n Area of sphere:-"<<sph;
       return 0;
       }
};
class cylinder:public round
{
public:float ac;
       float h;
public:cylinder(float height=0)
       {
       cout<<"\n Enter height:-";
       cin>>height;
       h=height;
       }
       float area()
       {
       float tsac,csac,vc,acbc;
       tsac=2*pi*radius*(h+radius);
       csac=2*pi*radius*h;
       vc=pi*radius*radius*h;
       acbc=pi*radius*radius;
       ac=tsac+csac+vc+acbc;
       cout<<"Area of cylinder is:-"<<ac;
       return 0;
       }
};
float round::pi=3.14;
int main()
{
int height;
clrscr();
cout<<"\n\t\t To calculate area of circle\n\n";
circle c;
c.area();
cout<<"\n\t\t To calculate area of sphere\n\n";
sphere s;
s.area();
cout<<"\n\t\t To calculate area of cylinder\n\n";
cylinder cl;
cl.area();
getch();
return 0;
}






============================================
OUTPUT

                To calculate area of circle                                    
                                                                               
                                                                               
Enter the radius:-1                                                           
                                                                               
Area of circle:-3.14         
                                                 
                To calculate area of sphere                                    
                                                                               
                                                                               
Enter the radius:-1                                                           
                                                                               
Area of sphere:-12.56  
                                                       
                To calculate area of cylinder                                  
                                                                               
                                                                               
Enter the radius:-1                                                           
                                                                               
Enter height:-1
Area of cylinder is:-25.120001

Popular posts from this blog

Solve

Directions: In each Q1 to Q3 of the following questions, there are five letter groups or words in each question. Four of these letter groups or words are alike in some way, while one is different. Find the one which is different. Q.1.    (1) black    (2) red    (3) green    (4) paint    (5) yellow Answer:- (4) paint Q.2.    (1) BC    (2) MN    (3) PQ    (4) XZ    (5) ST Answer :-(4)XZ Q.3.    (1) Mango    (2)Apple    (3) Orange    (4) Guava    (5) Rose Answer :- (5) Rose Directions : In each of the following questions, there is a question mark in which only one of the five alternatives given under the question satisfies the same relationship as is found between the two terms to the left of the sign :: given in the question. Find the correct answer ...

Solved practical slips of 12th Computer Science journal

Program 1:- Write a function in C++ that exchanges data (passing by references )using swap function to interchange the given two numbers.*/ # include<iostream.h> # include<conio.h> void swap(float &x ,float &y) { float t=x; x=y; y=t; } void main() { void swap(float &,float &); float a,b; cin>>a>>b; cout<<” a := ” << a <<” b := ”<< b<< endl; swap(a,b); cout<< ”a:= ”<< a<< ” b := ”<< b<< endl; } Output : 2 4 a := 2 b:= 4 a:= 4 b: =2   Program 2:- Write a program in C++ with a ratio class using member functions like assign () function to initialize its member data integer numerator and denominator ,convert() function to convert the ratio into double, invert() to get the inverse of the ratio and print() function to print the ratio and its reciprocal.*/ ...

SOLVE QUESTION ANSWERS ON OPERATING SYSTEM .

1.One can interface with operating system by means of ------- A) Operating system call in a program B) Operating system commands C) Operating system process D) Both by operating system call and operating system commands Answer :-  D) Both by operating system call and operating system commands 2. Which of the following is not type of processing ? A) Serial B) Network C) Batch D) Multiprogramming Answer :- B) Network 3. Kernel is _____ A) A part of operating system B) An operating system C) A hardware D) A register Answer :-  A) A part of operating system 4. UNIX operating system is based on ______ A) Language structure B) Kernel approach C) Virtual machine D) Time sharing Answer :-   B) Kernel approach 5. A transition between two memory resident process in a memory resident process in amultiprograming system is called ______ A) Process switch B) Mode switch C) Transition switch D) None of these Answer :-    A) Process ...