Tuesday, April 24, 2012

MENSURATION PROJECT

No comments


bANNER
Made By Gaurav Gupta 
Lovely Professional University

  • MENSURATION PROJECT
  • Project On MENSURATION.
  • Project Based on MATHEMATHICES.
  • Project based on Abstract class.





    bANNER






    Source Code

    //PROJECT ON MENSURATION

    //*******************************HEADER FILES********************************
    #include<iostream.h>
    #include<process.h>
    #include<conio.h>
    #include<math.h>

    #define Pi 22/7.0

    //**************************CLASS FOR 2-D OBJECTS****************************
    class shape2d
    { public:
    virtual float area()=0;
    virtual float perimeter()=0;
    };


    //**************************CLASS FOR 3-D OBJECTS****************************
    class shape3d
    { public:
    virtual float csa()=0;
    virtual float tsa()=0;
    virtual float volume()=0;
    };

    class circle:public shape2d
    { float r;
    public:
    void get()
    { cin>>r;
    }
    float area();
    float perimeter();
    };

    class rectangle:public shape2d
    { int l,b;
    public:
    void get()
    { cin>>l>>b;
    }
    float area();
    float perimeter();
    };

    class square:public shape2d
    { int s;
    public:
    void get()
    { cin>>s;
    }
    float area();
    float perimeter();
    };

    class triangle:public shape2d
    { int a,b,c;
    public:
    void get()
    { cin>>a>>b>>c;
    }
    float area();
    float perimeter();
    };

    class cube:public shape3d
    { int s;
    public:
    void get()
    { cin>>s;
    }
    float csa();
    float tsa();
    float volume();
    };

    class cuboid:public shape3d
    { int l,b,h;
    public:
    void get()
    { cin>>l>>b>>h;
    }
    float csa();
    float tsa();
    float volume();
    };

    class cone:public shape3d
    { int r,h;
    public:
    void get()
    { cin>>r>>h;
    }
    float slant();
    float csa();
    float tsa();
    float volume();
    };

    class cylinder:public shape3d
    { int r,h;
    public:
    void get()
    { cin>>r>>h;
    }
    float csa();
    float tsa();
    float volume();
    };

    class hemisphere:public shape3d
    { int r;
    public:
    void get()
    { cin>>r;
    }
    float csa();
    float tsa();
    float volume();
    };

    class sphere
    { int r;
    public:
    void get()
    { cin>>r;
    }
    float sa();
    float volume();
    };

    float circle::perimeter()
    { return 2*Pi*r;
    }

    float circle::area()
    { return Pi*r*r;
    }

    float rectangle::perimeter()
    { return 2*(l+b);
    }

    float rectangle::area()
    { return l*b;
    }

    float square::perimeter()
    { return 4*s;
    }

    float square::area()
    { return s*s;
    }

    float triangle::perimeter()
    { return a+b+c;
    }

    float triangle::area()
    { float S,ar;
    S=(a+b+c)/2;
    ar=sqrt(S*(S-a)*(S-b)*(S-c));
    return ar;
    }

    float cube::csa()
    {       return 4*s*s;
    }

    float cube::tsa()
    { return 6*s*s;
    }

    float cube::volume()
    { return s*s*s;
    }

    float cuboid::csa()
    {       return 2*(l+b)*h;
    }

    float cuboid::tsa()
    { return 2*((l*b)+(b*h)+(h*l));
    }

    float cuboid::volume()
    { return l*b*h;
    }

    float cone::slant()
    { return sqrt((r*r)+(h*h));
    }

    float cone::csa()
    { float l;
    l=slant();
    return Pi*r*l;
    }

    float cone::tsa()
    { float l;
    l=slant();
    return Pi*r*(r+l);
    }

    float cone::volume()
    { return (Pi*r*r*h)/3;
    }

    float cylinder::csa()
    {       return 2*Pi*r*h;
    }

    float cylinder::tsa()
    { return 2*Pi*r*(r+h);
    }

    float cylinder::volume()
    { return Pi*r*r*h;
    }

    float hemisphere::csa()
    { return 2*Pi*r*r;
    }

    float hemisphere::tsa()
    { return 3*Pi*r*r;
    }

    float hemisphere::volume()
    { return (2*Pi*r*r*r)/3;
    }

    float sphere::sa()
    { return 4*Pi*r*r;
    }

    float sphere::volume()
    { return (4*Pi*r*r*r)/3;
    }
    //******************************MAIN FUNCTION********************************
    void main()
    { clrscr();
    char ch,ans;
    shape2d *s1;
    shape3d *s2;
    circle c;
    rectangle r;
    square sq;
    triangle t;
    cube c1;
    cuboid c2;
    cone c3;
    cylinder c4;
    hemisphere h;
    sphere s;
    do
    {       clrscr();
    cout<<"\n\n\t\t\t\t MENU ";
    cout<<"\n\n\t\t\t\t======";
    cout<<"\n\n\t\t\t 1. PERIMETER ";
    cout<<"\n\n\t\t\t 2. AREA ";
    cout<<"\n\n\t\t\t 3. CURVED SURFACE AREA ";
    cout<<"\n\n\t\t\t 4. TOTAL SURFACE AREA ";
    cout<<"\n\n\t\t\t 5. VOLUME ";
    cout<<"\n\n\t\t\t 6. EXIT ";
    cout<<"\n\n\t\t\t Enter your choice ";
    ch=getche();
    switch(ch)
    { case'1':clrscr();
    cout<<"\n\n\t\t\t\t PERIMETER ";
    cout<<"\n\n\t\t\t\t===========";
    cout<<"\n\n\t\t\t 1. CIRCLE ";
    cout<<"\n\n\t\t\t 2. RECTANGLE ";
    cout<<"\n\n\t\t\t 3. SQUARE ";
    cout<<"\n\n\t\t\t 4. TRIANGLE ";
    cout<<"\n\n\t\t\t 5. EXIT ";
    cout<<"\n\n\t\t\t Enter your Choice ";
    ch=getche();
    clrscr();
    if (ch=='1')
    {
    cout<<"\n Enter the RADIUS of CIRCLE : ";
    c.get();
    s1=&c;
    cout<<"\n CIRCUMFERENCE of CIRCLE : ";
    cout<<s1->perimeter()<<" m";
    }
    else if (ch=='2')
    {
    cout<<"\n\n Enter the LENGTH & BREADTH : ";
    r.get();
    s1=&r;
    cout<<"\n PERIMETER of RECTANGLE : ";
    cout<<s1->perimeter()<<" m";
    }
    else if (ch=='3')
    {
    cout<<"\n\n Enter the SIDE of SQUARE : ";
    sq.get();
    s1=&sq;
    cout<<"\n PERIMETER of SQUARE : ";
    cout<<s1->perimeter()<<" m";
    }
    else if (ch=='4')
    {
    cout<<"\n\n Enter the SIDES of TRIANGLE : ";
    t.get();
    s1=&t;
    cout<<"\n PERIMETER of TRIANGLE : ";
    cout<<s1->perimeter()<<" m";
    }
    else
    exit(0);
    break;
    case'2':clrscr();
    cout<<"\n\n\t\t\t\t AREA ";
    cout<<"\n\n\t\t\t\t======";
    cout<<"\n\n 1. CIRCLE ";
    cout<<"\n\n 2. RECTANGLE ";
    cout<<"\n\n 3. SQUARE ";
    cout<<"\n\n 4. TRIANGLE ";
    cout<<"\n\n 5. EXIT ";
    cout<<"\n\n Enter your choice ";
    ch=getche();
    clrscr();
    if (ch=='1')
    {
    cout<<"\n\n Enter the RADIUS of CIRCLE ";
    c.get();
    s1=&c;
    cout<<"\n\n AREA of CIRCLE is : ";
    cout<<s1->area()<<" sq. m.";
    }
    else if (ch=='2')
    {
    cout<<"\n\n Enter the LENGTH & BREADTH ";
    r.get();
    s1=&r;
    cout<<"\n\n AREA of RECTANGLE is : ";
    cout<<s1->area()<<" sq. m.";
    }
    else if (ch=='3')
    {
    cout<<"\n\n Enter the SIDE of SQUARE ";
    sq.get();
    s1=&sq;
    cout<<"\n\n AREA of SQUARE is : ";
    cout<<s1->area()<<" sq. m.";
    }
    else if (ch=='4')
    {
    cout<<"\n\n Enter SIDES of TRIANGLE ";
    t.get();
    s1=&t;
    cout<<"\n\n AREA of TRIANGLE is : ";
    cout<<s1->area()<<" sq. m.";
    }
    else
    exit(0);
    break;
    case'3':clrscr();
    cout<<"\n\n\t\t\t CURVED SURFACE AREA ";
    cout<<"\n\n\t\t\t=====================";
    cout<<"\n\n 1. CUBE ";
    cout<<"\n\n 2. CUBOID ";
    cout<<"\n\n 3. CONE ";
    cout<<"\n\n 4. CYLINDER ";
    cout<<"\n\n 5. HEMISPHERE ";
    cout<<"\n\n 6. EXIT ";
    cout<<"\n\n Enter your choice : ";
    ch=getche();
    clrscr();
    if (ch=='1')
    {
    cout<<"\n\n Enter the SIDE of CUBE : ";
    c1.get();
    s2=&c1;
    cout<<"\n\n C.S.A. of CUBE is : ";
    cout<<s2->csa()<<" sq. m. ";
    }
    else if (ch=='2')
    {
    cout<<"\n\n Enter the SIDES of CUBOID : ";
    c2.get();
    s2=&c2;
    cout<<"\n\n C.S.A.(AREA of WALLS) is : ";
    cout<<s2->csa()<<" sq. m. ";
    }
    else if (ch=='3')
    {
    cout<<"\n\n Enter the RADIUS & HEIGHT : ";
    c3.get();
    s2=&c3;
    cout<<"\n\n C.S.A. of CONE is : ";
    cout<<s2->csa()<<" sq. m. ";
    }
    else if (ch=='4')
    {
    cout<<"\n\n Enter the RADIUS & HEIGHT : ";
    c4.get();
    s2=&c4;
    cout<<"\n\n C.S.A. of CYLINDER is : ";
    cout<<s2->csa()<<" sq. m. ";
    }
    else if (ch=='5')
    {
    cout<<"\n\n Enter the RADIUS of HEMISPHERE : ";
    h.get();
    s2=&h;
    cout<<"\n\n C.S.A. of HEMISPHERE is : ";
    cout<<s2->csa()<<" sq. m. ";
    }
    else
    exit(0);
    break;
    case'4':clrscr();
    cout<<"\n\n\t\t\t TOTAL SURFACE AREA ";
    cout<<"\n\n\t\t\t====================";
    cout<<"\n\n 1. CUBE ";
    cout<<"\n\n 2. CUBOID ";
    cout<<"\n\n 3. CONE ";
    cout<<"\n\n 4. CYLINDER ";
    cout<<"\n\n 5. SPHERE ";
    cout<<"\n\n 6. HEMISPHERE ";
    cout<<"\n\n 7. EXIT ";
    cout<<"\n\n Enter your choice : ";
    ch=getche();
    clrscr();
    if (ch=='1')
    {
    cout<<"\n\n Enter the SIDE of CUBE ";
    c1.get();
    s2=&c1;
    cout<<"\n\n T.S.A. of CUBE is : ";
    cout<<s2->tsa()<<" sq. m. ";
    }
    else if (ch=='2')
    {
    cout<<"\n\n Enter the SIDES of CUBOID ";
    c2.get();
    s2=&c2;
    cout<<"\n\n T.S.A. of CUBOID is : ";
    cout<<s2->tsa()<<" sq. m. ";
    }
    else if (ch=='3')
    {
    cout<<"\n\n Enter the RADIUS & HEIGHT : ";
    c3.get();
    s2=&c3;
    cout<<"\n\n T.S.A. of CONE is : ";
    cout<<s2->tsa()<<" sq. m. ";
    }
    else if (ch=='4')
    {
    cout<<"\n\n Enter the RADIUS & HEIGHT : ";
    c4.get();
    s2=&c4;
    cout<<"\n\n T.S.A. of CYLINDER is : ";
    cout<<s2->tsa()<<" sq. m. ";
    }
    else if (ch=='5')
    {
    cout<<"\n\n Enter the RADIUS of SPHERE : ";
    s.get();
    cout<<"\n\n S.A. of SPHERE is : ";
    cout<<s.sa()<<" sq. m. ";
    }
    else if (ch=='6')
    {
    cout<<"\n\n Enter the RADIUS of HEMISPHERE : ";
    h.get();
    s2=&h;
    cout<<"\n\n T.S.A. of HEMISPHERE is : ";
    cout<<s2->tsa()<<" sq. m. ";
    }
    else
    exit(0);
    break;
    case'5':clrscr();
    cout<<"\n\n\t\t\t\t VOLUME ";
    cout<<"\n\n\t\t\t\t========";
    cout<<"\n\n 1. CUBE ";
    cout<<"\n\n 2. CUBOID ";
    cout<<"\n\n 3. CONE ";
    cout<<"\n\n 4. CYLINDER ";
    cout<<"\n\n 5. SPHERE ";
    cout<<"\n\n 6. HEMISPHERE ";
    cout<<"\n\n 7. EXIT ";
    cout<<"\n\n Enter your choice : ";
    ch=getche();
    clrscr();
    if (ch=='1')
    {
    cout<<"\n\n Enter the SIDE of CUBE ";
    c1.get();
    s2=&c1;
    cout<<"\n\n VOLUME of CUBE is : ";
    cout<<s2->volume()<<" cu. m. ";
    }
    else if (ch=='2')
    {
    cout<<"\n\n Enter the SIDES of CUBOID ";
    c2.get();
    s2=&c2;
    cout<<"\n\n VOLUME of CUBOID is : ";
    cout<<s2->volume()<<" cu. m. ";
    }
    else if (ch=='3')
    {
    cout<<"\n\n Enter the RADIUS & HEIGHT : ";
    c3.get();
    s2=&c3;
    cout<<"\n\n VOLUME of CONE is : ";
    cout<<s2->volume()<<" cu. m. ";
    }
    else if (ch=='4')
    {
    cout<<"\n\n Enter the RADIUS & HEIGHT : ";
    c4.get();
    s2=&c4;
    cout<<"\n\n VOLUME of CYLINDER is : ";
    cout<<s2->volume()<<" cu. m. ";
    }
    else if (ch=='5')
    {
    cout<<"\n\n Enter the RADIUS of SPHERE : ";
    s.get();
    cout<<"\n\n VOLUME of SPHERE is : ";
    cout<<s.volume()<<" cu. m. ";
    }
    else if (ch=='6')
    {
    cout<<"\n\n Enter the RADIUS of HEMISPHERE : ";
    h.get();
    s2=&h;
    cout<<"\n\n VOLUME of HEMISPHERE is : ";
    cout<<s2->volume()<<" cu. m. ";
    }
    else
    exit(0);
    break;
    case'6':exit(0);
    break;
    default:cout<<"\n\n Choice is incorrect ";
    break;
    }
    cout<<"\n\n ------------------------------------ ";
    cout<<"\n\n Do you want to continue ? Enter y/n: ";
    ans=getche();
    }
    while (ans=='y'||ans=='Y');
    if(ans=='n'||ans=='N')
    exit(0);
    getch();
    }












    0 comments:

    Post a Comment

    Entries RSS Comments RSS

    Sample Text

    Pages


    Copyright © Lovely Codes
    Powered by Blogger
    Distributed By Free Blogger Templates | Design by N.Design Studio
    Blogger Theme by Lasantha - PremiumBloggerTemplates.com