140k views
1 vote
A standard science experiment is to drop a ball and see how high it bounces. Once the "bounciness" of the ball has been determined, the ratio gives a bounciness index. For example, if a ball dropped from a height of 10 feet bounces 6 feet high, the index is 0.6, and the total distance traveled by the ball is 16 feet after one bounce. If the ball were to continue bouncing, the distance after two bounces would be 10 ft + 6 ft +6 ft + 3.6 ft = 25.6 ft. Note that the distance traveled for each successive bounce is the distance to the floor plus 0.6 of that distance as the ball comes back up. Write a program that lets the user enter the initial height from which the ball is dropped, the bounciness index, and the number of times the ball is allowed to continue bouncing. Output should be the total distance traveled by the ball.

User Johans
by
5.6k points

1 Answer

5 votes

Answer:

Here is code in c++.

#include <bits/stdc++.h>

using namespace std;

int main() {

//declare variables

float height,b_index,tot_distance;

int no_bounce;

cout<<"Please enter the initial height from which ball is dropped:";

//read the initial height

cin>>height;

cout<<"Please enter the bounciness index:";

// read the bounciness index

cin>>b_index;

cout<<"Enter the number of times the ball is allowed to continue bouncing:";

// read the number of bounce

cin>>no_bounce;

tot_distance=0;

// calculate the total distance travelled by the ball

while(no_bounce>0)

{

tot_distance=tot_distance+height;

height=height*b_index;

tot_distance=tot_distance+height;

no_bounce-=1;

}

// print the output

cout<<"total distance travelled by ball is: "<<tot_distance<<" units."<<endl;

return 0;

}

Step-by-step explanation:

Declare variables "height" to store the initial height of the ball,"b_index" to store bounciness index,"no_bounce" to store number of bounce.Then calculate the total distance as total distance +height and then update the height as height*bounciness index and add the new height to distance. then decrease the number of bounce. Repeat the same until number of bounce become 0.

Output:

Please enter the initial height from which ball is dropped:10

Please enter the bounciness index:.6

Enter the number of times the ball is allowed to continue bouncing:2

total distance travelled by ball is: 25.6 units

User Virtualnobi
by
5.8k points