summaryrefslogtreecommitdiff
path: root/BlankConsoleLab/BlankConsoleLab.cpp
blob: fd66fe57cf874a3bbba0a33883ab89155f382a45 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
*  BlankConsoleLab.cpp : This file contains the 'main' function.Program execution begins and ends there.
*
* Morgan Cyrus
* CST116_Lab1_Cyrus
* Kite Lab
*/

#include <iostream>

using std::cout;
using std::cin;
using std::endl;

float kiteCalc(float wid, float len);
float aspectCalc(float wid, float len);
float massCalc(float areaVal);

int main()
{
    float kiteWidth = 0;
    float kiteLen = 0;
    float kiteArea = 0;
    float kiteMass = 0;

    // get user input for kiteWidth. Value entered must be between 1 and 400 or it will loop and ask again.
    while(kiteWidth < 1 || kiteWidth > 400)
    {
        cout << "Enter value for kite width in cm between 1 and 400 cm: ";
        cin >> kiteWidth;
    }

    // get user input for kiteLen. Value entered must be between 1 and 400 or it will loop and ask again.
    while(kiteLen < 1 || kiteLen > 400)
    {
        cout << endl << "Enter value for kite length in cm: ";
        cin >> kiteLen;
    }
    
    cout << "\nYou have entered " << kiteWidth << "cm for kite width, and " << kiteLen << "cm for kite length." << endl;

    //calculate the area of the kite and store in kiteArea
    kiteArea = kiteCalc(kiteWidth, kiteLen);
    cout << "The area of the kite, in square meters, is: " << kiteArea << endl;

    //calculate the aspect ratio of the kite and spit out a message to the user if the aspect ratio is greater than or equal to 1
    aspectCalc(kiteWidth, kiteLen);

    kiteMass = massCalc(kiteArea);
}

float kiteCalc(float wid, float len)
{
    //calculate kite area in cm^2
    float kiteAreaCalc = (wid * len)/2;

    //convert cm^2 to meters^2
    kiteAreaCalc = kiteAreaCalc / 1000;

    return kiteAreaCalc;
}

float aspectCalc(float wid, float len)
{
    // calculate the aspect ratio of the kite using input from the user in main()
    float aspectRatioCalc = (wid / len);

    if (aspectRatioCalc >= 1)
    {
        cout << "Your kite has an aspect ratio of: " << aspectRatioCalc << endl;
        cout << "a lower aspect ratio would provide more stability. \n";

        return 0;
    }
    else
    {
        return 0;
    }
    
}

float massCalc(float areaVal)
{
    cout << "\nCalculating kite mass....\n";

    // calculate the mass of the kite/square meter assuming fabric mass of 135 Grams/Square meter
    float kiteAreaCalc = 135 / areaVal;

    cout << "Kite mass: " << kiteAreaCalc << " grams." << endl;
    return kiteAreaCalc;
}