HI, I trying to figure out how to start this assignment for my C++ class and I d
ID: 3732806 • Letter: H
Question
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 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 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 player’s statistics (after each label printing the player’s 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 doesn’t 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
Explanation / Answer
first you need two files Hockey.h and a main.cpp i am giving you these files here
after that you need to do whatever the 4 question says and recording the compiler log
here is your files : ------------>>>>>>>>>
Hockey.h : -------->>>>>
#include<iostream>
using namespace std;
class Hockey
{
private:
int goals,assists,penalties,penalty_minutes;
public:
void initialize ();
void tripping ();
void fighting ();
void score_goal ();
void assist_goal ();
void print ();
};
void Hockey::assist_goal(){
assists++;
}
void Hockey::fighting(){
penalties++;
penalty_minutes += 5;
}
void Hockey::initialize(){
goals = assists = penalties = penalty_minutes = 0;
}
void Hockey::tripping(){
penalties++;
penalty_minutes += 2;
}
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.";
}
Main.cpp : -------->>>>>>>>>
#include "Hockey.h"
int main(){
Hockey vanek,myers;
//initializing both Hockey Variables
vanek.initialize();
myers.initialize();
//vanek score two goals so we call score_goal two times
vanek.score_goal();
vanek.score_goal();
//vanek get 1 assits
vanek.assist_goal();
//vanek get a penality for tripping
vanek.tripping();
//myers get Three assists
myers.assist_goal();
myers.assist_goal();
myers.assist_goal();
//myers get two penality for fighting
myers.fighting();
myers.fighting();
//printing both vanek and myers
vanek.print();
myers.print();
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.