Website Summary Files Commits Branches @commit @diff @stats
path: root / Week08 / Exercise01 / main.cpp
blob: 8ba91e81f0c07913bd56f3617ed50f41121b0575 (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
#include <cstring>
#include <iostream>

#include "SpaceAgency.h"

int main() {
	char command[1024];
	SpaceAgency sa;

	while (true) {
		std::cin.getline(command, sizeof(command) / sizeof(*command));
		if (strcmp(command, "exit") == 0) {
			break;
		}
		else if (strcmp(command, "new_hangar") == 0) {
			sa.AddHangar(Hangar());
		}
		else if (strcmp(command, "new_launch_site") == 0) {
			char nameBuffer[251];
			std::cout << "Name: ";
			std::cin.getline(nameBuffer, sizeof(nameBuffer) / sizeof(*nameBuffer));

			double maxWeight;
			std::cout << "Max weight: ";
			std::cin >> maxWeight;

			unsigned maxHeight;
			std::cout << "Max height: ";
			std::cin >> maxHeight;

			std::cin.ignore();

			LaunchSite ls;
			ls.SetName(nameBuffer);
			ls.SetMaxWeight(maxWeight);
			ls.SetMaxHeight(maxHeight);

			sa.AddLaunchSite(ls);
		}
		else if (strcmp(command, "new_rocket_stage") == 0) {
			char name[101];
			std::cout << "Name: ";
			std::cin.getline(name, sizeof(name) / sizeof(*name));

			unsigned height;
			std::cout << "Height: ";
			std::cin >> height;

			double weight;
			std::cout << "Weight: ";
			std::cin >> weight;

			double liftForce;
			std::cout << "Lift force: ";
			std::cin >> liftForce;

			unsigned burnTime;
			std::cout << "Burn time: ";
			std::cin >> burnTime;

			RocketStage rs;
			rs.SetName(name);
			rs.SetHeight(height);
			rs.SetWeight(weight);
			rs.SetLiftForce(liftForce);
			rs.SetBurnTime(burnTime);

			unsigned hangarIndex;
			std::cout << "Hangar index: ";
			std::cin >> hangarIndex;

			std::cin.ignore();

			sa.AddRocketStage(rs, hangarIndex);
		}
		else if (strcmp(command, "new_rocket") == 0) {
			unsigned rocketHangarIndex;
			std::cout << "Rocket hangar index: ";
			std::cin >> rocketHangarIndex;

			std::cin.ignore();

			char name[512];
			std::cout << "Name: ";
			std::cin.getline(name, sizeof(name) / sizeof(*name));

			Rocket r;
			r.SetName(name);
			unsigned rocketIndex = sa.AddRocket(r, rocketHangarIndex);

			unsigned stages;
			std::cout << "Stages: ";
			std::cin >> stages;

			for (unsigned i = 0; i < stages; ++i) {
				unsigned stageHangar, stageIndex;

				std::cout << "Stage hangar index: ";
				std::cin >> stageHangar;
				std::cout << "Stage index: ";
				std::cin >> stageIndex;

				sa.MoveRocketStageToRocket(stageHangar, stageIndex, rocketHangarIndex, rocketIndex);
			}
			std::cin.ignore();
		}
		else if (strcmp(command, "can_launch") == 0) {
			unsigned siteIndex;
			std::cout << "Site index: ";
			std::cin >> siteIndex;

			unsigned hangarIndex;
			std::cout << "Rocket hangar index: ";
			std::cin >> hangarIndex;

			unsigned rocketIndex;
			std::cout << "Rocket index: ";
			std::cin >> rocketIndex;

			std::cin.ignore();

			if (sa.CanLaunch(siteIndex, hangarIndex, rocketIndex)) {
				std::cout << "Can be launched!" << std::endl;
			}
			else {
				std::cout << "Cannot be launched!" << std::endl;
			}
		}
		else {
			std::cout << "Invalid command!" << std::endl;
		}
	}

	return 0;
}