Website Summary Files Commits Branches @commit @diff @stats
path: root / Week08 / Exercise01 / main.cpp
diff options
context:
space:
mode:
Commit7d98b664c9e459a08f2e6e6fa5b636686dfed554 (patch)
Author
 Syndamia <kamen@syndamia.com>
2026-04-08 10:42:51 +0300
Committer
 Syndamia <kamen@syndamia.com>
2026-04-08 10:42:51 +0300
Filesb2b6eddb0c6f582999ebb32c8dea2a01b477d747 /Week08/Exercise01/main.cpp
oop-2025-solutions-7d98b664c9e459a08f2e6e6fa5b636686dfed554.tar
oop-2025-solutions-7d98b664c9e459a08f2e6e6fa5b636686dfed554.tar.gz
oop-2025-solutions-7d98b664c9e459a08f2e6e6fa5b636686dfed554.zip
Parent945f7e67d6ca8047c961457786fac5e2d9a13d82 (diff)
feat(Week08): Add solutions
1 files changed, 135 insertions, 0 deletions
-rw-r--r--Week08/Exercise01/main.cpp135
diff --git a/Week08/Exercise01/main.cpp b/Week08/Exercise01/main.cpp
new file mode 100644
index 0000000..8ba91e8
--- /dev/null
+++ b/Week08/Exercise01/main.cpp
@@ -0,0 +1,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;
+}