View Single Post
Old 02-09-2007, 05:30 PM   #9 (permalink)
QwertyManiac
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Default Re: Post ur C/C++ Programs Here

Quote:
Originally Posted by Yamaraj
Your code doesn't conform to either ISO C or C++ standards.
Don't be so hard on him He doesn't know TC++'s evils

Anyway, here's xbonez's program in proper code

Code:
#include<iostream>
#include<math.h>

using namespace std;

void line(void);
void cuboid(void);
void cube(void);
void cylinder(void);
void cone(void);
void sphere(void);
void hemisphere(void);
void triangle(void);
void rectangle(void);
void square(void);
void circle(void);
void parallelogram(void);

int main()
{ 
    int o1,o2;
    do{
         
        cout<<"\n\n1. 3-D Figures"
            <<"\n\n2. Plane Figures"
            <<"\n\n3. Exit"
            <<"\n\nEnter your choice -->\t";
        cin>>o1;

        switch(o1)
        {
            case 1:         cout<<"\n\n";
                    line();
                    cout<<"\n\t\t\t\t3-D Figures\n\n";
                    line();
                    cout<<"\n\n1. Cuboid"
                        <<"\n\n2. Cube"
                        <<"\n\n3. Cylinder"
                        <<"\n\n4. Cone"
                        <<"\n\n5. Sphere"
                        <<"\n\n6. Hemisphere"
                        <<"\n\n7. Main Menu"
                        <<"\n\nEnter your choice -->\t";
                        cin>>o2;
                        switch(o2)
                        {
                        case 1:        cout<<"\n\n";
                                line();
                                cout<<"\n\t\t\t\tCuboid\n\n";
                                line();
                                cuboid();
                                
                                break;

                        case 2:        cout<<"\n\n";
                                line();
                                cout<<"\n\t\t\t\tCube\n\n";
                                line();
                                cube();
                                
                                break;

                        case 3:        cout<<"\n\n";
                                line();
                                cout<<"\n\t\t\t\tCylinder\n\n";
                                line();
                                cylinder();
                                
                                break;

                        case 4:        cout<<"\n\n";
                                line();
                                cout<<"\n\t\t\t\tCone\n\n";
                                line();
                                cone();
                                break;

                        case 5:        cout<<"\n\n";
                                line();
                                cout<<"\n\t\t\t\tSphere\n\n";
                                line();
                                sphere();
                                break;

                        case 6:        cout<<"\n\n";
                                line();
                                cout<<"\n\t\t\t\tHemisphere\n\n";
                                line();
                                hemisphere();
                                break;

                        case 7:        break;


                        default:    cout<<"\n\nInvalid Input\a\a\a";
                        }
                        
                        break;

            case 2:            
                        cout<<"\n\n";
                        line();
                        cout<<"\n\t\t\t\tPlane Figures\n\n";
                        line();
                        cout<<"\n\n1. Traingle"
                        <<"\n\n2. Rectangle"
                        <<"\n\n3. Sqaure"
                        <<"\n\n4. Circle"
                        <<"\n\n5. Parallelogram"
                        <<"\n\n6. Main Menu"
                        <<"\n\nEnter your choice -->\t";
                        cin>>o2;

                        switch(o2)
                        {
                            case 1:        cout<<"\n\n";
                                    line();
                                    cout<<"\n\t\t\t\tTraingle\n\n";
                                    line();
                                    triangle();
                                    
                                    break;

                            case 2:        cout<<"\n\n";
                                    line();
                                    cout<<"\n\t\t\t\tRectangle\n\n";
                                    line();
                                    rectangle();
                                    
                                    break;

                            case 3:         cout<<"\n\n";
                                    line();
                                    cout<<"\n\t\t\t\tSquare\n\n";
                                    line();
                                    square();
                                    
                                    break;

                            case 4:        cout<<"\n\n";
                                    line();
                                    cout<<"\n\t\t\t\tCircle\n\n";
                                    line();
                                    circle();
                                    break;

                            case 5:        cout<<"\n\n";
                                    line();
                                    cout<<"\n\t\t\t\tParallelogram\n\n";
                                    line();
                                    parallelogram();
                                    break;

                            case 6:        break;


                            default:    cout<<"\n\nInvalid Input\a\a\a";
                        }

                        break;

            case 3:             cout<<"\n\nPress any key to exit...\a";
                        break;

            default:        cout<<"\n\nInvalid Input\a\a\a\a";



        }

    }while(o1!=3);
return 0;
}


void line()
{
    int i;
    for (i=0;i<80;i++)
        cout<<"*";
}

void cuboid()
{
    float l,b,h,a,v;
    cout<<"\n\nEnter length of cuboid -->\t";
    cin>>l;
    cout<<"\n\nEnter breadth of cuboid -->\t";
    cin>>b;
    cout<<"\n\nEnter height of cuboid -->\t";
    cin>>h;
    v=l*b*h;
    a=2*(l*b+b*h+l*h);
    cout<<"\n\nVolume of cuboid is "<<v;
    cout<<"\n\nSurface area of cuboid is "<<a;
}

void cube()
{
    float l,a,v;
    cout<<"\n\nEnter length of side of cube -->\t";
    cin>>l;
    v=l*l*l;
    a=6*l*l;
    cout<<"\n\nVolume of cube is "<<v;
    cout<<"\n\nSurface area of cube is "<<a;
}

void cylinder()
{
    float r,h,v,c,t;
    cout<<"\n\nEnter radius of cylinder -->\t";
    cin>>r;
    cout<<"\n\nEnter height of cylinder -->\t";
    cin>>h;
    v=3.14*r*r*h;
    c=2*3.14*r*h;
    t=3.14*r*(2*h+r);
    cout<<"\n\nVolume of cylinder is "<<v;
    cout<<"\n\nCurved Surface Area of cylinder is "<<c;
    cout<<"\n\nTotal Surface Area of cylinder is "<<t;
}

void cone()
{
    float r,h,l,v,c,t;
    cout<<"\n\nEnter radius of cone -->\t";
    cin>>r;
    cout<<"\n\nEnter height of cone -->\t";
    cin>>h;
    l=sqrt(r*r+h*h);
    v=(3.14*r*r*h)/3;
    c=3.14*r*l;
    t=3.14*r*(l+r);
    cout<<"\n\nSlant height of cone is "<<l;
    cout<<"\n\nVolume of cone is "<<v;
    cout<<"\n\nCurved Surface Area of cone is "<<c;
    cout<<"\n\nTotal Surface Area of cone is "<<t;
}

void sphere()
{
    float r,v,a;
    cout<<"\n\nEnter radius of sphere -->\t";
    cin>>r;
    v=(4*3.14*r*r*r)/3;
    a=4+3.14*r*r;
    cout<<"\n\nVolume of sphere is "<<v;
    cout<<"\n\nSurface Area of sphere is "<<a;
}

void hemisphere()
{
    float r,v,c,t;
    cout<<"\n\nEnter radius of hemisphere -->\t";
    cin>>r;
    v=(2*3.14*r*r*r)/3;
    c=2*3.14*r*r;
    t=3*3.14*r*r;
    cout<<"\n\nVolume of hemisphere is "<<v;
    cout<<"\n\nCurved Surface Area of hemisphere is "<<c;
    cout<<"\n\nTotal Surface Area of hemisphere is "<<t;
}

void triangle()
{
    float b,h,a;

    cout<<"\n\nEnter base of triangle -->\t";
    cin>>b;
    cout<<"\n\nEnter height of triangle -->\t";
    cin>>h;

    a=(b*h)/2;
    cout<<"\n\nArea of the triangle is "<<a;

}

void rectangle()
{
    float l,b,a,p;
    cout<<"\n\nEnter length of rectangle -->\t";
    cin>>l;
    cout<<"\n\nEnter breadth of rectangle -->\t";
    cin>>b;
    a=l*b;
    p=2*(l+b);
    cout<<"\n\nArea of rectangle is "<<a;
    cout<<"\n\nPerimeter of rectangle is "<<p;
}

void square()
{
    float s,a,p;
    cout<<"\n\nEnter length of side of square -->\t";
    cin>>s;
    a=s*s;
    p=4*s;
    cout<<"\n\nArea of square is "<<a;
    cout<<"\n\nPerimeter of square is "<<p;
}

void circle()
{
    float r,a,c;
    cout<<"\n\nEnter radius of circle -->\t";
    cin>>r;
    a=3.14*r*r;
    c=2*3.14*r;
    cout<<"\n\nArea of circle is "<<a;
    cout<<"\n\nCircumference of circle is "<<c;
}

void parallelogram()
{
    float b,h,a,p;
    cout<<"\n\nEnter base of parallelogram -->\t";
    cin>>b;
    cout<<"\n\nEnter height of parallelogram -->\t";
    cin>>h;
    a=b*h;
    p=2*(b+h);
    cout<<"\n\nArea of parallelogram is "<<a;
    cout<<"\n\nPerimeter of parallelogram is "<<p;
}
__________________
Harsh J
www.harshj.com
QwertyManiac is offline