59.2 practice charge! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

59.2 practice charge!

Can anyone fix it? Selection Operator You are creating a program to manage smartphones. The given code declares a Phone class, with its constructor and two methods: use() and getCharge(). A Phone object is declared in main. Complete the code to call the getCharge() method using the correct selection operator. You can call a member function directly on the object, or using the pointer. #include <iostream> using namespace std; class Phone { public: int charge; Phone() { charge = 100; } void use() { charge -=10; } void getCharge() { cout << charge; } }; int main() { Phone p; p.use(); Phone *ptr = &p; //call the getCharge() method on ptr }

23rd Sep 2021, 7:10 PM
SAUL ALFREDO LOPEZ HIGUERA
SAUL ALFREDO LOPEZ HIGUERA - avatar
4 Answers
+ 2
#include <iostream> using namespace std; class Phone { public: int charge; Phone() { charge = 100; } void use() { charge -=10; } void getCharge() { cout << charge; } }; int main() { Phone p; p.use(); Phone *ptr = &p; //call the getCharge() method on ptr ptr -> getCharge(); } Good Luck
25th Jan 2022, 5:54 PM
Muhammad Alif Deva Rizqon
Muhammad Alif Deva Rizqon - avatar
0
Please, read lesson 59.1 again, and you will find the answer how to solve it. It's all in the lesson!
23rd Sep 2021, 7:20 PM
Jan
Jan - avatar
9th Oct 2021, 10:45 AM
Khomi TAKAYANAGI
Khomi TAKAYANAGI - avatar