Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <iostream>
- #include <cmath>
- #include <iomanip>
- using namespace std;
- //Declaring the functions
- float enter_data(const string &);
- double height_calc(const float &, const int &, const float &);
- void display_header(const string &, const string &);
- void display_results(const float &, const double &);
- int main() {
- const float gravity_ms2 = 9.8;
- // Declaring variables
- const string desc_1 = "Time(seconds)";
- const string desc_2 = "Height(Meter)";
- // Calling the enter_data function to ask for the initial velocity
- const float in_vel = enter_data("Enter the Initial Velocity in Meters/Second: ");
- display_header(desc_1, desc_2);
- double current_height = 0;
- int seconds = 0;
- do {
- current_height = height_calc(in_vel, seconds, gravity_ms2);
- display_results(seconds, current_height);
- seconds += 1;
- } while (current_height >= 0);
- return 0;
- }
- float enter_data(const string &prompt)//Outputting the prompt and storring as in_vel
- {
- float in_vel;
- cout << prompt << endl; //Asking for an the input value
- cin >> in_vel;//Setting input value as in_vel
- return in_vel;//returning to in_vel in int main
- }
- double height_calc(const float &in_vel, const int &seconds, const float &gravity_ms2) {
- return ((in_vel * seconds) - (.5 * gravity_ms2 * pow(seconds, 2)));
- }
- void display_header(const string &desc_1, const string &desc_2) {
- //Displaying the headers
- cout << setw(1) << desc_1 << setw(20) << desc_2 << endl;
- }
- void display_results(const float &seconds, const double &height) {
- //Displaying the values for both time and height every second
- cout << setw(1) << setprecision(4) << seconds << setw(20) << height << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement