C++ program Calculate the volume of a CUBE,CUBOID, CYLINDER, SPHERE ,CONE |C++ Exercises| TechWithCode.com

Calculate the volume of a CUBE,CUBOID, CYLINDER, SPHERE ,CONE using C++:-

 Today I will explain to you that how to write a c program that calculates the volume of any shapes like CUBE, CUBOID, CYLINDER, SPHERE, CONE. In order to doing this we will use the concept of Class and Onjectsin c++ as well as user-defined Methods or Functions.

Knowledge required to understand the C++ program of Calculating the volume of a CUBE, CUBOID, CYLINDER, SPHERE, CONE:-

To understand the code of volume calculation in C, you must have knowledge about basic mathematics formulas and the Switch Case of C++ programming, Class and Objects, Functions.


Before the explanation of the source code of volume calculation program, I want to share important information that At TechWithCode, we are doing something which will motivate you to do more programming. In his, you have to solve questions[chose from our website or make questions on your own] in any programming language and share your code with us, we will publish your code with your name on our website.    For more Details ClickHere

                             ✽Send Solution and Get Credit✽

Let's come to our main topic, So here is the Source code of C++ program to calculate the volume of CUBE, CUBOID, CYLINDER, SPHERE, CONE

Source Code of  Calculating the volume of a CUBE, CUBOID, CYLINDER, SPHERE, CONE:-

using namespace std;
class Volume
 float V;
 void cube()
  float a;
  cout<<"Enter value of side"<<endl;
 void cuboid()
  float l,b,h;
  cout<<"Enter length,breadth & hight of cuboid"<<endl;
 void cylender()
  float r,h;
  cout<<"Enter radius & hight of cylender"<<endl;
 void sphere()
  float r;
  cout<<"Enter radius of sphere"<<endl;
 void cone()
  float r,h;
  cout<<"Enter radius & hight of cone"<<endl;
 void display()
  cout<<"Volume is = "<<V<<endl;
int main()
  int ch,q;
  Volume ob;
  cout<<"Select the shape for calculate volume"<<endl<<endl;
  cout<<"Press 1 for select CUBE"<<endl;
  cout<<"Press 2 for select CUBOID"<<endl;
  cout<<"Press 3 for select CYLINDER"<<endl;
  cout<<"Press 4 for select SPHERE"<<endl;
  cout<<"Press 5 for select CONE"<<endl<<endl;
         case 1: ob.cube();break;
         case 2: ob.cuboid();break;
         case 3: ob.cylender();break;
         case 4: ob.sphere();break;
         case 5: ob.cone();break;
         default: cout<<"Wrong input";
  if(ch>=1 && ch<=5)
  cout<<"press any key to countinue... / press 0 to EXIT"<<endl<<endl;
   return 0;

Output of above code:-

Explanation of above code:-
                                                 In this Code, I have use the Switch case, function, class, object and many concepts of c++ programming. First, I ask to select the option from the user that the volume of which shapes the user wants to calculate then I pass the user choice in the switch case and call the appropriate function. that functions return the calculated value of volume in the main function after that I pass that value in the Display function.

I put all my code in a while loop which is always true so it will repeatedly be asking for calculations the volume one after other.
To stop the program you have to enter ZERO ("0").

Thanks You..@author Deepak Kumar.

Do you want to become a good programmer, Click Here

✽Send Solution and Get Credit✽

Must Read:-

4. Java Programming
5. C programs With source code

Final Word:-

In this article, We have explained to you how to write a C program that will calculate the volume of any shapes. We hope you like it

If This post helps you a little bit then please share this post with your friends. For more Computer and programming Related Tips and tricks, please

Follow us on Facebook
Subscribe us on Youtube
Follow us on Instagram
Follow us on Pinterest

Don't forget to share how you like this Content in the comment below. If you have any doubt or suggestion then please write in the comment section below, we will love to hear from you.

                               Thank you.

                                        ( नमस्ते )


No comments:

Do not add any link in the comments.
For backlink, contact us.

Powered by Blogger.