课程: Complete Guide to C++ Programming Foundations

免费学习该课程!

今天就开通帐号,24,100 门业界名师课程任您挑!

Challenge: Calculate rhythm game scores

Challenge: Calculate rhythm game scores

(upbeat music) - [Tutor] For this challenge, your task was to write two versions of the same function by means of overloading. The calculate score function must return a double with the calculated score based on how far off the player hit a button in a rhythm game. Both functions must specify a default value for a bonus multiplier. Let's see my solution. Starting at line 13, we have the function that takes in the time difference, in milliseconds, as an integer. In this line, you were expected to add the default value of 1.0 to the second parameter. Then starting at line 15, we have a sequence of if-else statements calculating the score based on the value of the difference. Lastly, in line 24, we returned the score multiplied by the bonus. Now, for the second function, starting at line 29, we also specify a default value of 1.5 for the bonus multiplier. And now for the body of the function, I cheated, because I could. In line 30, I converted the difference in seconds to milliseconds…

内容