Monday, November 4, 2013

Geometry codding

PSEUDOCODE:

START: Main
Call Process Loop
END

ENTER: Process Loop
Call Display Main Menu
Loop While choice not = 10
IF
                        Call Display Rectangle
else IF choice = 2
            Call Display Triangle
else IF choice = 3
                        Call Display Circle
else IF choice = 4
                        Call Display Cylinder
else IF choice = 5
                        Call Display Cones
else IF choice = 6
                        Call Display Pyramid
else IF choice = 7
                        Call Display Sphere
else IF choice = 8
                        Call Display Trapezoid
else
                        Call Display Parallelogram
END IF
                        Call Display Main Menu
END LOOP
RETURN

ENTER: Display Main Menu
Clear Screen
Print 8 screen title lines
Print Geometry Calculation choices:
            choice 1:  Calculate  the Rectangle
            choice 2:  Calculate  the Triangle
            choice 3:  Calculate  the Circle
            choice 4:  Calculate  the Cylinder
           


choice 5:  Calculate  the Cones
            choice 6:  Calculate  the Pyramid
            choice 7:  Calculate  the Sphere
            choice 8:  Calculate  the Trapezoid
            choice 9:  Calculate  the Parallelogram
            choice 10: Quit
Prompt and enter choice
Clear keyboard buffer
LOOP while choice not = 1 to 10
            Print error – invalid choice
            Prompt and enter choice
            Clear keyboard buffer
END LOOP
RETURN

ENTER: Display Calculate  the Rectangle
Clear screen
Print 8 screen title lines
Display geometry calculate result
Hold screen

RETURN



CODDING :


/* NOR SHUHADAH NOORDIN DX125086DPCJ04 */

#include <iostream>
using namespace std;
 int main()
{
                int pilihan;
                double width,height,length,base,top,bottom;
                double area,primeter,primeter_circle,volume;
                double side1,side2,side3;
                double radius1,radius2;
    const double pi = 3.14;
    int terus;



do
    {
        //Fenin kepala aku masa 1st nak starting buat codding ni ;p
                                cout<<"1 : Rectangle\n";
                                cout<<"2 : Triange\n";
                                cout<<"3 : Circle\n";
                                cout<<"4 : Cylinders\n";
                                cout<<"5 : Cones\n";
                                cout<<"6 : Piramid\n";
                                cout<<"7 : Spehere\n";
                                cout<<"8 : Trapezoid\n";
                                cout<<"9 : Parallelogram\n";
                                cout<<"10 : Quit\n\n";

        //prompt user to enter value 1-10
        cout<<"Please choose one of the list above to calculate area also for primeter:\n";
        cin>>pilihan;


        if(pilihan==1)
        {
            cout<<"You choose number "<<pilihan<<" for rectangle\n";
            cout<<"Please enter the height:\n";
            cin>>height;
            cout<<"Please enter the width:\n";
            cin>>width;

            area = height * width;
            primeter=(height + width)*2;

            cout<<"The area for rectangle is : "<<area<<"\n";
            cout<<"The perimeter for rectangle is : "<<primeter<<"\n";
        }
        else if(pilihan==2)
        {
            cout<<"You choose number "<<pilihan<<" for triangle\n";
            cout<<"Please enter the base:\n";
            cin>>base;
            cout<<"Please enter the height:\n";
            cin>>height;
            cout<<"Please enter the side1:\n";
            cin>>side1;
            cout<<"Please enter the side2:\n";
            cin>>side2;
            cout<<"Please enter the side3:\n";
            cin>>side3;

            area = base*height/2;
            primeter = side1+side2+side3;

            cout<<"The area for triangle is : "<<area<<"\n";
            cout<<"The perimeter for rectangle is : "<<primeter<<"\n";
        }
        else if(pilihan==3)
        {
            cout<<"You choose number "<<pilihan<<" for circle\n";
            cout<<"Please enter the radius:\n";
            cin>>radius1;


            area = pi * (radius1*radius1);
            primeter = 2 * pi * radius1;

            cout<<"The area for circle is : "<<area<<"\n";
            cout<<"The perimeter for circle is : "<<primeter<<"\n";
        }
        else if(pilihan==4)
        {
            cout<<"You choose number "<<pilihan<<" for cyclinder\n";
            cout<<"Please enter the perimeter of circle:\n";
            cin>>primeter_circle;
            cout<<"Please enter the height:\n";
            cin>>height;
            cout<<"Please enter the radius:\n";
            cin>>radius1;


            area = primeter_circle * height * 2 * pi * radius1 * height;
            volume = pi * (radius1*radius1) * height;

            cout<<"The area for cyclinder is : "<<area<<"\n";
            cout<<"The volume for cyclinder is : "<<volume<<"\n";
        }
        else if(pilihan==5)
        {
            cout<<"You choose number "<<pilihan<<" for cones\n";
            cout<<"Please enter the radius:\n";
            cin>>radius1;
            cout<<"Please enter the height:\n";
            cin>>height;
            cout<<"Please enter the side:\n";
            cin>>side1;


            area = pi * radius1 * side1;
            volume = 0.33 * pi * (radius1*radius1) * height;

            cout<<"The area for cones is : "<<area<<"\n";
            cout<<"The volume for cones is : "<<volume<<"\n";
        }

        else if(pilihan==6)
        {
            cout<<"You choose number "<<pilihan<<" for pyramid\n";
            cout<<"Please enter the base area\n";
            cin>>base;
            cout<<"Please enter the height\n";
            cin>>height;


            //area = 4 * pi * (radius1*radius1);
            volume = 1.33 *base*height;


          // cout<<"The area for pyramid is : "<<area<<"\n";
            cout<<"The volume for pyramid is : "<<volume<<"\n";
        }
        else if(pilihan==7)
        {
            cout<<"You choose number "<<pilihan<<" for sphere\n";
            cout<<"Please enter the radius\n";
            cin>>radius1;


            area = 4 * pi * (radius1*radius1);
            volume = 1.33 *pi*(radius1*radius1*radius1);


           cout<<"The area for sphere is : "<<area<<"\n";
            cout<<"The volume for sphere is : "<<volume<<"\n";
        }
        else if(pilihan==8)
        {
            cout<<"You choose number "<<pilihan<<" for trapezoid\n";
            cout<<"Please enter the top length\n";
            cin>>top;
             cout<<"Please enter the bottom length\n";
            cin>>bottom;
             cout<<"Please enter the side left length\n";
            cin>>side1;
             cout<<"Please enter the side right length\n";
            cin>>side2;
             cout<<"Please enter the height\n";
            cin>>height;


            area = 0.5 *(top+bottom)*height;
            primeter = top + bottom + side1 + side2;


           cout<<"The area for sphere is : "<<area<<"\n";
           cout<<"The volume for sphere is : "<<primeter<<"\n";
        }
        else if(pilihan==9)
        {
            cout<<"You choose number "<<pilihan<<" for parallelogram\n";
            cout<<"Please enter the base length\n";
            cin>>base;

             cout<<"Please enter the side 1 length\n";
            cin>>side1;
             cout<<"Please enter the side 2 length\n";
            cin>>side2;
             cout<<"Please enter the height\n";
            cin>>height;


            area = base*height;
            primeter = 2*( side1 + side2);


           cout<<"The area for parallelogram is : "<<area<<"\n";
           cout<<"The volume for parallelogram is : "<<primeter<<"\n";
        }
        else if(pilihan==10)
        {
             cout<<"Thank You guys.\n";
        }
        else
        {
            cout<<"===============================================================================\n";
            cout<<"Sorry, the number entered are not valid, please choose the number only exist in menus.\n";
            cout<<"===============================================================================\n\n";

        }

    //prompt user to continue or discard process
    cout<<"******************************************************************************\n";
    cout<<"Are you sure,if you want to continue,if yes choose number other than 10 and if no choose (10):";
                cin>>terus;


    }while(terus!=10);



}



1 comment:

  1. Top 7 best tipsters on Bet365 - Thakasino
    How カジノ シークレット to Bet with Bet365 · TipsterRank · TipsterRating · TipsterType.com. Rating · 1.1 온카지노 · bet365 1,128 reviews

    ReplyDelete