Question

C++ Programming Windows Application Console

Student Generated Problem Option 2.5 Option 2.5: Suppose Dave drops a watermelon off a high bridge and lets it fall until it hits the water. If we neglect air resistance, then the distance d in meters fallen by the watermelon after t seconds is d 0.5 g* t where the acceleration of gravity 9.8 meters/second?. Write a program that asks the user to input the number of seconds that the watermelon falls and the height h of the bridge above the water. The program should then calculate the distance fallen for each second from t 0 until the value of t input by the user. If the total distance fallen is greater than the height of the bridge, then the program should tell the user that the distance fallen is not valid. Sample Run 1: Please input the time of fall in seconds: Please input the height of the bridge in meters: 100 Time Falling (seconds Distance Fallen (meters) 4.9 19.6

0 0
Add a comment Improve this question Transcribed image text
Answer #1

C++ Program:

/* C++ Program that calculates the distance fallen by watermelon */

#include <iostream>

using namespace std;

//Main function
int main()
{
    int time, i;
    double distance, height;

    //Reading time
    cout << "\n Please input the time of fall in seconds: ";
    cin >> time;

    //Reading height of bridge
    cout << "\n Please input the height of bridge in meters: ";
    cin >> height;

    //Printing header
    cout << "\n \t Time Falling (seconds) Distance Fallen (meters) \n ";
    cout << " *********************************************************** \n ";

    //Iterating over time from 0 to t
    for(i=0; i<=time; i++)
    {
        //Calculating distance
        distance = 0.5 * 9.8 * (i*i);

        //Printing time and distance
        cout << "\n \t " << i << " \t\t\t " << distance;

        //Checking for distance
        if(distance > height)
        {
            //If distance crossed height
            cout << "\n Warning - Bad Data: The distance fallen exceeds the height of the bridge. \n\n";
            return 0;
        }
    }

    cout << "\n\n";

    return 0;
}

Sample Run:

CTC watermelon\bin Please input the time of fall in seconds: 2 Please input the height of bridge in meters: 100 wa .exe Time

Add a comment
Know the answer?
Add Answer to:
C++ Programming Windows Application Console Student Generated Problem Option 2.5 Option 2.5: Suppose Dave drops a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Watermelon Problem: The answer should not include any whitespace. #include<iostream> using namespace std; int main() {...

    Watermelon Problem: The answer should not include any whitespace. #include<iostream> using namespace std; int main() {     double distance, gravity =9.8, height;     int time, t=0;     cout<<"Please input the time of fall in seconds:"<<endl;     [ A ] // Get the user input of the time of fall in seconds (Use cin>> method)     cout<<endl;     cout<<"Please input the height of the bridge in meters:"<<endl;     [ B ] // Get the user input of the height of the bridge in meters (Use cin>>...

  • Please can someone help me to finish this program? It is a C programming not a...

    Please can someone help me to finish this program? It is a C programming not a C++, when programming the program in linux I keep getting expected expression before || token, also please check if everything else is fine, maybe there is something else worng in my program and may ask me later to fix it, I am concern about the sin and cosine. The program is supposed to do all this: 1.Display a welcome message. 2.Prompt for the height...

  • Homework-2 – Working with a class. Problem: Attached with this homework is code for a class...

    Homework-2 – Working with a class. Problem: Attached with this homework is code for a class called DroppedObject. This class is used to to store the state of a falling object. The problem this class/object can be used to solve is detailed below. Your task for this homework is to read and understand the attached class. Note this class is formatted like all classes should be with private variables, constructors, a toString method, getter and setter methods, and other relevant...

  • Write a MATLAB Graphical User Interface (GUI) to simulate and plot the projectile motion – the...

    Write a MATLAB Graphical User Interface (GUI) to simulate and plot the projectile motion – the motion of an object projected into the air at an angle. The object flies in the air until the projectile returns to the horizontal axis (x-axis), where y=0. This MATLAB program should allow the user to try to hit a 2-m diameter target on the x-axis (y=0) by varying conditions, including the lunch direction, the speed of the lunch, the projectile’s size, and the...

  • 5.15 PROGRAM: Functions - Upset Fowls (C++) (1) Correct the first FIXME by moving the intro...

    5.15 PROGRAM: Functions - Upset Fowls (C++) (1) Correct the first FIXME by moving the intro text to the function stub named PrintIntro and then calling the PrintIntro function in main. Development suggestion: Verify the program has the same behavior before continuing. (2) Correct the second FIXME by completing the function stub GetUsrInpt and then calling this function in main. Notice that the function GetUsrInpt will need to return two values: fowlAngle and fowlVel. (3) Correct the third FIXME by...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT