File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change
1
+ cmake_minimum_required (VERSION 3.15 )
2
+ project (BouncingBall )
3
+
4
+ set (CMAKE_CXX_STANDARD 14 )
5
+
6
+ add_executable (BouncingBall main.cpp )
Original file line number Diff line number Diff line change
1
+ /* *
2
+ * @file main.cpp
3
+ * @author Arun Kumar Devarajulu
4
+ * @date February 2, 2020
5
+ * @copyright Copyright 2020, Arun Kumar Devarajulu. All rights reserved
6
+ */
7
+ #include < iostream>
8
+
9
+ /* *
10
+ * @brief Class for solving the problem of bouncing ball
11
+ */
12
+ class Bouncingball {
13
+ public:
14
+ /* *
15
+ * @brief Static member function to calculate the number of bounces made
16
+ * by a ball after deprecation of height by bounce % in every turn
17
+ * @param h is the height of the launch location
18
+ * @param bounce is the deprecation factor
19
+ * @param window is the height of the observer
20
+ * @return total number of bounces as an integer
21
+ */
22
+ static int bouncingBall (double h, double bounce, double window);
23
+ };
24
+
25
+ int Bouncingball::bouncingBall (double h, double bounce, double window) {
26
+ if (h > 0 && 0 < bounce && bounce < 1 && window < h) {
27
+ int total_bounces = 1 ;
28
+ h *= bounce;
29
+ while (h > window) {
30
+ total_bounces += 2 ;
31
+ h *= bounce;
32
+ }
33
+ return total_bounces;
34
+ } else return -1 ;
35
+ }
36
+
37
+ int main () {
38
+ std::cout << Bouncingball::bouncingBall (77 , 0.83 , 13 ) << std::endl;
39
+ return 0 ;
40
+ }
You can’t perform that action at this time.
0 commit comments