Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

HI, I trying to figure out how to start this assignment for my C++ class and I don't have a clue how to start it.

HI, I trying to figure out how to start this assignment for my C++ class and I don't have a clue how to start it. I was wondering if you could help me thanks.

// Hockey class keeping track of a players goals, assists,

// penalties and penalty minutes

class Hockey

{

private:

int goals, // number of goals

assists, // number of assists

penalties, // number of penalties

penalty_minutes; // total of penalty minutes

public:

void initialize ();

void tripping ();

void fighting ();

void score_goal ();

void assist_goal ();

void print ();

};

The HockeyImp file looks as follows:

// Records the fact that the player has scored another goal

void Hockey::score_goal ()

{

goals++;

}

// Prints the player's current statistics

void Hockey::print ()

{

cout << " Goals: " << goals;

cout << " Assists: " << assists;

if (penalties == 1)

cout << " " << penalties << " penalty for "

<< penalty_minutes << " minutes.";

else

cout << " " << penalties << " penalties for " << penalty_minutes << " minutes.";

}

Continued on Back

The public class methods score_goal and print have been defined for you. Add the other public class methods. initialize sets all private data items equal to zero. tripping increases the number of penalties by 1 and increases the penalty minutes by 2. fighting increases the number of penalties by 1 and increases the penalty minutes by 5. assist_goal increases the number of assists by 1.

In the main program, declare two variables of type Hockey, vanek and myers. Apply the public method initialize to both variables. Use the public methods to have vanek score two goals, get one assist and a penalty for tripping. Use the public methods to have myers get three assists and two penalties for fighting. Use the public method print to display each players statistics (after each label printing the players name). Get your program to run correctly.

Consider these items to better your understanding:

1. Add the following statement to main to print the number of goals that myers has

scored:

cout << myers.goals;

Rebuild All from the Execute menu. Why doesnt this code compile?

Remove this cout.

2. Remove Hockey:: from the score_goal method definition in the Hockey.h file.

Select Rebuild All from the Execute menu.

a. What compiler error is now given?

b. What does the Hockey:: indicate to the compiler that allows the code to compile?

Restore the Hockey::

3. Comment out the calls to the initialize method in main (put // before them). Run your

program. What happens and why?

Uncomment the code.

4. Comment out the #include Hockey.h line. What happens and why?

Uncomment the code and then be sure your program functions correctly

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions