blob: c79afb99952879f476bd1d0523402b7dc9416125 (
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
// BlankConsoleLab.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
using namespace std;
using std::cout;
using std::cin;
using std::endl;
// Functions
float GetLength();
float GetWidth();
void CalcAR(float length, float width);
float CalcArea(float length, float width);
float CalcMass(float area);
void CalcGP(float mass);
// Main code
int main()
{
float length = 0;
float width = 0;
float area = 0;
float aspectRatio = 0;
float mass = 0;
// Get measurements
length = GetLength();
width = GetWidth();
// Calculate aspect ratio
CalcAR(length, width);
// Calculate area
area = CalcArea(length, width);
// Calculate mass
mass = CalcMass(area);
// Calculate gravitational pull
CalcGP(mass);
return 0;
}
float GetLength()
{
float length;
cout << "Enter kite length in centimeters: ";
cin >> length;
// Set max length to 400
while (length > 400)
{
cout << "Length is too large. Must be less than 400." << endl;
cout << "Enter kite length in centimeters: ";
cin >> length;
}
// Set min length to 1
while (length < 1)
{
cout << "Length is too small. Must be greater than 1." << endl;
cout << "Enter kite length in centimeters: ";
cin >> length;
}
return length;
}
float GetWidth()
{
float width;
cout << "Enter kite width in centimeters: ";
cin >> width;
// Set max width to 400
while (width > 400)
{
cout << "Width is too large. Must be less than 400." << endl;
cout << "Enter kite width in centimeters: ";
cin >> width;
}
// Set min width to 1
while (width < 1)
{
cout << "Width is too small. Must be greater than 1." << endl;
cout << "Enter kite width in centimeters: ";
cin >> width;
}
return width;
}
void CalcAR(float length, float width)
{
float aspectRatio = width / length;
cout << endl << "Length: " << length << endl;
cout << "Width: " << width << endl;
cout << endl << "Your kite's aspect ratio is: " << aspectRatio << endl;
// Print warning
if (aspectRatio > 1)
{
cout << endl << "WARNING: Aspect ratio is too high. A lower aspect ratio will provide greater stability. Consider increasing the kite's aspect ratio." << endl;
}
}
float CalcArea(float length, float width)
{
float area;
area = (width * length) / 2;
area = area / 10000;
cout << endl << "The area of you kite is " << area << " square meters." << endl;
return area;
}
float CalcMass(float area)
{
float mass;
const int fabricWeight = 135;
mass = (area * fabricWeight) / 1000;
cout << endl << "Your kite weighs " << mass << " kg." << endl;
return mass;
}
void CalcGP(float mass)
{
float gravitationalPull;
gravitationalPull = mass * 9.8;
cout << endl << "The gravitational pull on your kite is " << gravitationalPull << " N/kg" << endl;
}
// Finished
|