u

Wednesday 6 June 2012

C++ Program to compute surface area of cone, cylinder, vol. of cone etc

C++ Program to compute surface area of cone, cylinder, vol. of cone etc


#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
void SAofcone();
void SAofCylinder();
void Volumeofcone();
void beginning();
void SAofCone()
     {
    clrscr();
    cout<<"This program calculates the SA of a cone. it uses 3.14 for pi."<<endl;
    float pi;
    pi= 3.14;
    float r;
    cout<< "Enter the radius of the base of the cone?"<<endl;
    cin>> r;
    float basearea;
    basearea= (r*r*pi);
    float height;
    cout<<"Enter the height of the cone?"<<endl;
    cin>> height;
    float SA;
    SA= (basearea)+(pi*r*height);
    cout<<endl;
    cout<<"The answer is:";
    cout<< SA;
    system("pause");
    beginning();
}
void SAofCylinder()


    {
    cout<<"This program calculates the surface area of a cylinder,"<<endl;
    cout<<"it uses 3.14 for pi."<<endl;
    float r;
    cout<<"Enter the radius of the base?"<<endl;
    cin>> r;
    float pi;
    pi= 3.14;
    float height;
    cout<<"Enter the height of the circle?"<<endl;
    cin>>height;
    float circumfrence;
    circumfrence= r*2*pi;
    float SA;
    SA= 2*(3.14)*(r*r)+2*(3.14)*(r)*(height);
    cout<<"The compute result is approximately:";
    cout<< SA;
    cout<<""<<endl;
    system("pause");
    beginning();
}
void Volumeofcone()


    {
    cout<<"This program calculates the volume of a cone. it used 3.14 for pi."<<endl;
    cout<<""<<endl;
    float r;
    cout<<" Enter the radius of the base?"<<endl;
    cin>> r;
    float pi;
    pi= 3.14;
    float height;
    cout<<"Enter the height of the cone?"<<endl;
    cin>> height;
    float pirsq;
    pirsq= pi*r;
    float volume;
    volume= (.333333)*(pi)*(r*r)*(height);
    cout<<"Enter the volume of the cone is approxmately:";
    cout<< volume;
    cout<<""<<endl;
    system("pause");
    beginning();
}
int main(void)


    {
    clrscr();
    beginning();
}
void beginning()
    {
    cout<<"Press any key to continue"<<endl;
    getch();
    clrscr();
    cout<<"------------------------------------\n";
    cout<<"----**OPTIONS** --------------------\n";
    cout<<"------1. find the SA of a cone------\n";
    cout<<"------2. find the SA of a cylinder--\n";
    cout<<"------3. find the volume of a cone--\n";
    cout<<"------------------------------------\n";
    cout<<"----- 4. Exit-----------------------"<<endl;
    int choice = 0;
    cin>> choice;
    if (choice == 1)
    SAofCylinder();
    if (choice == 2)
    SAofCone();
    if (choice == 3)
    Volumeofcone();
    if (choice == 4)
    exit(0);
}

0 comments:

Post a Comment

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More