Advertisement
Guest User

project

a guest
Feb 23rd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.52 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdbool.h>
  3. #include <iomanip>
  4. using namespace std;
  5. double coeffOfRestitution[4] = {0.7,0.75,0.09,0.3} ;
  6. bool validate(int ball_id)
  7. {
  8.     if (ball_id > 3 || ball_id < 0)
  9.         return false ;
  10.     return true ;
  11. }
  12. void compute(int ball_id , double initial_height )
  13. {
  14.     cout<<"Coefficient of restitution: "<<setprecision(2) << fixed<<coeffOfRestitution[ball_id]<<endl ;
  15.     double current_height = initial_height ;
  16.     int nb_bounce = 0 ;
  17.     double distance = 0 ;
  18.     while (current_height > 0.1)
  19.     {
  20.         nb_bounce++ ;
  21.         distance+=current_height ;
  22.         current_height *= coeffOfRestitution[ball_id] ;
  23.         if (current_height >= 0.1)
  24.             distance+=current_height ;
  25.     }
  26.     //distance-=current_height ;
  27.     cout<<"Number of bounces: "<<nb_bounce<<endl;
  28.     cout<<"Meters traveled for ball: "<<setprecision(2) << fixed<<distance<<endl ;
  29.  
  30.  
  31. }
  32. int main()
  33. {
  34.     int ball_id ;
  35.     cout<<"Enter the type of ball (0 to 3) :" ;
  36.     cin>>ball_id;
  37.     bool verified = validate(ball_id) ;
  38.     while (!verified)
  39.     {
  40.         cout<<"Please enter 0 to 3 .."<<endl ;
  41.         cout<<"Enter the type of ball (0 to 3) :";
  42.         cin>>ball_id;
  43.         verified = validate(ball_id) ;
  44.     }
  45.     double initial_height ;
  46.     cout<<"Enter initial height in meters:" ;
  47.     cin>>initial_height ;
  48.     while (initial_height < 0)
  49.     {
  50.         cout<<"Enter initial height in meters:" ;
  51.         cin>>initial_height ;
  52.     }
  53.     compute(ball_id ,initial_height);
  54.     return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement