ravesli/Chapter_2_Final_Test/main.cpp

73 lines
1.3 KiB
C++
Raw Normal View History

2021-08-09 10:14:45 +00:00
/*
* 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;
}