C++ Calculate Area of Shapes (CCAS)


CCAS:    SOLD





Assignment

Create a program containing more than two functions, along with questions and answers.

Submit to:
ibnu_muhamma***@yahoo.com

File Format:
NIM_FullName_DATASTRUCTURE.CPP

Deadline:
Thursday, November 20, 2014, at 5:00 PM

Program:

#include <iostream.h>
#include <conio.h>
#include <stdlib.h>

void main() {
    unsigned int pilihan, f;
    float r, Ll, p, l, Lp, a, t, Ls;

    cout << "MENU OPTIONS" << endl;
    cout << "------------" << endl;
    cout << "1. Calculate circle area" << endl;
    cout << "2. Calculate rectangle area" << endl;
    cout << "3. Calculate triangle area" << endl;
    cout << "4. Calculate average of data" << endl;
    cout << "5. Exit" << endl;
    cout << "------------" << endl;

    while (pilihan >= 0) {
        cout << "Your choice (1/2/3/4/5): "; cin >> pilihan;
        switch (pilihan) {
        case 1:
            cout << "-------------------------------------" << endl;
            cout << "Calculating Circle Area" << endl;
            cout << "Enter radius: "; cin >> r;
            Ll = 3.14 * r * r;
            cout << "Circle Area: " << Ll << endl;
            cout << "-------------------------------------" << endl;
            break;
        case 2:
            cout << "-------------------------------------" << endl;
            cout << "Calculating Rectangle Area" << endl;
            cout << "Enter Length: "; cin >> p;
            cout << "Enter Width: "; cin >> l;
            Lp = p * l;
            cout << "Rectangle Area: " << Lp << endl;
            cout << "-------------------------------------" << endl;
            break;
        case 3:
            cout << "-------------------------------------" << endl;
            cout << "Calculating Triangle Area" << endl;
            cout << "Enter Base: "; cin >> a;
            cout << "Enter Height: "; cin >> t;
            Ls = 0.5 * a * t;
            cout << "Triangle Area: " << Ls << endl;
            cout << "-------------------------------------" << endl;
            break;
        case 4:
            cout << "-------------------------------------" << endl;

            int s[1], k, i;
            int j, n;
            float rt;
            cout << "Number of indices: ";
            cin >> j;
            if (j != 0) {
                for (int k = 0; k < j; k++) {
                    cout << "Index " << k + 1 << ": ";
                    cin >> s[i];
                    n = n + s[i];
                }
                cout << endl;
                rt = n / j;
                cout << "Average: " << rt << endl;
            } else {
                cout << "Invalid input data." << endl;
            }

            cout << "-------------------------------------" << endl;
            break;
        case 5:
            exit(5);
            break;
        default:
            cout << "Invalid code entered!" << endl;
        }
    }

    getch();
}

Preview:
That's all, and thank you for your attention.


Post a Comment

Previous Next

نموذج الاتصال