Answer to Question #211757 in C++ for Jaguar

Question #211757

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-01T01:12:00-0400

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();

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