-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlesson4part1.txt
58 lines (48 loc) · 1.69 KB
/
lesson4part1.txt
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
#include <cmath>
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;
//this program will take a mass (kg) as an input and output the weight (N) of the object on the earth, moon, and venus
int main()
{
const double earthAccel = 9.81, moonAccel = 1.62, venusAccel = 8.87; //our constants
double mass; //we'll ask the user for this
//now we'll make some vectors to hold all the relevant data
vector<double> acceleration = { earthAccel, moonAccel, venusAccel };
vector<double> weight; //this will hold earthWeight, moonWeight, venusWeight
vector<string> location = { "Earth", "Moon", "Venus" };
//prompts user for input, and outputs it in desired format
cout << "Enter the mass in kg\n";
cin >> mass;
cout << "The mass is " << fixed << setprecision(4) << mass << " kg\n";
/*so long as our mass is greater than 0, for each index in the vectors,
we will cycle through our outputs*/
if (mass > 0)
{
//sets our output table up
cout << left << setw(8);
cout << "Location";
cout << right << setw(15); /*the instructions said width of 14 for this column,
but the tests came up with 14 wrong and 15 right*/
cout << "Weight (N)\n";
//now to loop through the vectors' indexes and output into our table
for (int i = 0; i < 3; i++)
{
weight.push_back(mass * acceleration[i]); //will load our weight values into our weight vector
cout << left << setw(8) << location[i];
cout << right << setw(14) << fixed << setprecision(4) << weight[i] << endl;
}
if (weight[0] > 1500)
{
cout << "The object is heavy\n";
}
else if (weight[0] < 5)
{
cout << "The object is light\n";
}
}
else
cout << "The mass must be greater than zero\n";
return 0;
}