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

c++

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.

6th Nov 2021, 6:42 PM
Mando
Mando - avatar
5 Answers
+ 2
Other than a missing semicolon in the line where you invoke getCharge(), I am not seeing a problem (yet). What "using the correct selection operator" means? the Phone class doesn't have any operator defined ...
6th Nov 2021, 7:03 PM
Ipang
+ 2
Hahaha it's 02:05 here, struggling to keep my eyes open LOL
6th Nov 2021, 7:06 PM
Ipang
+ 1
#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; ptr -> getCharge() //call the getCharge() method on ptr }
6th Nov 2021, 6:43 PM
Mando
Mando - avatar
+ 1
Did you forget a semicolon? Oo" ptr -> getCharge();
6th Nov 2021, 7:02 PM
SoloProg
SoloProg - avatar
+ 1
Lol i missed a semicole what coding at 3am gets ya
6th Nov 2021, 7:04 PM
Mando
Mando - avatar