Chapter_2_Final_Test
This commit is contained in:
parent
e280a4648d
commit
46b84d6704
|
@ -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_ */
|
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue