New course! Every coder should learn Generative AI!
Try a free lesson0
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.
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 ...
+ 2
Hahaha it's 02:05 here, struggling to keep my eyes open LOL
+ 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
}
+ 1
Did you forget a semicolon? Oo"
ptr -> getCharge();
+ 1
Lol i missed a semicole what coding at 3am gets ya