Answer to Question #217159 in C++ for Maxwell

Question #217159

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;

}


1
Expert's answer
2021-07-14T07:32:15-0400

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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS