Question
Please help me out with this lab Create a project containing these three files. The Hockey.h header file looks as follows: // Hockey class keeping
Please help me out with this lab
Create a project containing these three files. The Hockey.h header file looks as follows: // Hockey class keeping track of a player's 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 Hockey.cpp implementation file looks as follows: #include #include Hockey.h using namespace std; // 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."; }
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, eichel and cozens. Apply the public method initialize to both variables. Use the public methods to have eichel score two goals, get one assist and a penalty for fighting. Use the public methods to have cozens get three assists and two penalties for tripping. Use the public method print to display each players statistics (after each label printing the players name). Get your program to run correctly. 1. Add the following statement to main to print the number of goals that eichel has scored: cout << eichel.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.cpp 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. What concept have we learned about which would remove the need for the initialize function? 5. Comment out the #include Hockey.h line from the HockeyApp.cpp file. What happens and why?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started