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;
}
The first error:
conversion error from string to double, the correct format:
double nScore = sodoku.getScore();
The second error:
Member reference base type 'Game [12]' is not a structure or union, the correct format is:
tetris[0].getName()
#include <iostream>
using namespace std;
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];
double nScore = sodoku.getScore();
return 0;
cout << "The first tetris player is "
<< tetris[0].getName() << endl;
}
Comments
Leave a comment