From the course: Debugging in C++ with Visual Studio Code

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Printing variable values

Printing variable values

- [Instructor] Let's look at a simple battery usage simulation that we will use for a few debugging examples. This program calculates how much charge remains in a battery after running for a specified number of hours. Let's start by looking at the main function at line 31. Here, we define a batteryCapacity of 100%, meaning the battery starts fully charged. Then there are two power drain modes, normalDrain at 5% per hour and lowPowerDrain mode at 2% per hour. We'll simulate the battery usage for 24 hours. At line 37, we create a battery object using these three initial values, the batteryCapacity, the normalDrain rate, and the lowPowerDrain rate. Then we call the simulateUsage function with 24 hours as an argument. And finally, we print out the remaining battery charge. All right, let's take a look at the battery class starting at line 7. First, we have the private member variables, charge, which represents the current battery level, normalDrain, which is the normal power drain rate…

Contents