ravesli/Chapter_2_Final_Test/main.cpp

73 lines
1.3 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* 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;
}