Consider the class declaration and main() function below. There are two errors in
the main() function. Name the errors and explain how to fix them, providing all the
code required to correct the errors.
class Game
{
public:
Game();
string getName();
int getLevel();
double getScore();
private:
string Name;
string Champion;
int Level
double Score;
};
int main()
{
Game sodoku, tetris[12];
.........(additional code)
double nScore = sodoku.Champion;
.........(additional code)
return 0;
cout << "The first tetris player is "
<< tetris.getName() << endl;
There is no closing parenthesis for the main function, This can be corrected by adding a closing parenthesis for the main method.
}
Accessing private variable outside the class. The statement "double nScore = sodoku.Champion;" generates an error since "Champion" is declared as private hence cannot be accessed outside the class. This can be corrected by defining a get methon in the class and then using the get method to access the variable in the main method.
string getChampion(){
return Champion;
}
double nScore = sodoku.getChampion();
Comments
Leave a comment