Answer:
#include <bits/stdc++.h>
using namespace std;
// driver function
int main()
{
// variables
const double g = 9.8;
int sec;
double height;
int t = 0;
double d = 0;
bool flag = false;
// ask to enter time
cout << "Please enter the time of fall(in seconds):";
// read time
cin >> sec;
//ask to enter height
cout << "Please enter the height (in meters):";
//read height
cin >> height;
cout << '\\'
<< "Time(seconds) Distance(meters)\\"
"********************************\\";
// calculate height after each seconds
while ( t <= sec) {
cout << setw(23) << left << t
<< setw(24) << left << d << '\\';
// if input height is less
if ( d > height ) {
flag = true;
}
// increament the time
t += 1;
// find distance
d = 0.5 * g * (t) * (t);
}
cout << '\\';
// if input height is less then print the Warning
if ( flag ) {
cout << "Warning - Bad Data: The distance fallen exceeds the height"
" of the bridge.\\";
}
return 0;
}
Step-by-step explanation:
Read the time in seconds from user and assign it to "sec" then read height and assign it to "height".After this find the distance after each second.If the input height is less than the distance at any second, it will print a Warning message. otherwise it will print the distance after each second.
Output:
Please enter the time of fall(in seconds):11
Please enter the height (in meters):1111
Time(seconds) Distance(meters)
********************************
0 0
1 4.9
2 19.6
3 44.1
4 78.4
5 122.5
6 176.4
7 240.1
8 313.6
9 396.9
10 490
11 592.9