From 46b84d67043886ff169585c4048fce2b92e746e9 Mon Sep 17 00:00:00 2001 From: Alexander Zhirov Date: Mon, 9 Aug 2021 13:14:45 +0300 Subject: [PATCH] Chapter_2_Final_Test --- Chapter_2_Final_Test/constants.hpp | 16 +++++++ Chapter_2_Final_Test/main.cpp | 72 ++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 Chapter_2_Final_Test/constants.hpp create mode 100644 Chapter_2_Final_Test/main.cpp diff --git a/Chapter_2_Final_Test/constants.hpp b/Chapter_2_Final_Test/constants.hpp new file mode 100644 index 0000000..b428452 --- /dev/null +++ b/Chapter_2_Final_Test/constants.hpp @@ -0,0 +1,16 @@ +/* + * constants.hpp + * + * Created on: 9 авг. 2021 г. + * Author: alexander + */ + +#ifndef CONSTANTS_HPP_ +#define CONSTANTS_HPP_ + +namespace myConstants +{ + const float g(9.8); +} + +#endif /* CONSTANTS_HPP_ */ diff --git a/Chapter_2_Final_Test/main.cpp b/Chapter_2_Final_Test/main.cpp new file mode 100644 index 0000000..5e22a51 --- /dev/null +++ b/Chapter_2_Final_Test/main.cpp @@ -0,0 +1,72 @@ +/* + * main.cpp + * + * Created on: 9 авг. 2021 г. + * Author: alexander + */ +#include +#include "constants.hpp" +#include +#include + +using namespace std; + +void exercise_3(); +void exercise_4(); + +float dropPerSecond(const int& second); + +int main() +{ + exercise_3(); + exercise_4(); + + return 0; +} + +void exercise_3() +{ + double a(0.0); + double b(0.0); + + cout << "Enter a double value: "; + cin >> a; + cout << "Enter a double value: "; + cin >> b; + + char operation; + + cout << "Enter one of the following: +, -, * or /: "; + cin >> operation; + + if (operation == '+') + cout << a << " + " << b << " = " << a + b << endl; + else if (operation == '-') + cout << a << " - " << b << " = " << a - b << endl; + else if (operation == '*') + cout << a << " * " << b << " = " << a * b << endl; + else if (operation == '/') + cout << a << " / " << b << " = " << a / b << endl; +} + +void exercise_4() +{ + int towerHeight(0); + + cout << "Enter the initial height of the tower in meters: "; + cin >> towerHeight; + + for (int i = 0; i <= 5; ++i) + { + if (towerHeight - dropPerSecond(i) < 0) + cout << "At " << i << " seconds, the ball is on the ground" << endl; + else + cout << "At " << i << " seconds, the ball is at height: " << + towerHeight - dropPerSecond(i) << endl; + } +} + +float dropPerSecond(const int& second) +{ + return (myConstants::g * pow(second, 2)) / 2; +}