Compare commits

..

1 Commits

Author SHA1 Message Date
Alexander Zhirov 46b84d6704 Chapter_2_Final_Test 2021-08-09 13:14:45 +03:00
2 changed files with 88 additions and 0 deletions

View File

@ -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_ */

View File

@ -0,0 +1,72 @@
/*
* main.cpp
*
* Created on: 9 авг. 2021 г.
* Author: alexander
*/
#include <iostream>
#include "constants.hpp"
#include <math.h>
#include <iomanip>
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;
}