Question
C++ Create a class called SoccerPlayer Create 5 private attributes: First Name, Last Name, Games, Goals and Average Goals. Have two constructors Constructor 1 default
C++
Create a class called SoccerPlayer
Create 5 private attributes: First Name, Last Name, Games, Goals and Average Goals.
Have two constructors
Constructor 1 default constructor; all values to null or zero
Constructor 2 accepts input of first name, last name, games and goals.
Create get and set methods for each of the first four attributes
Create a method the returns a double that calculates the average goals per game
This method sets the attribute to the calculated value
This method checks for zero games played:
If there are zero games played, display an error and set average to 0;
If greater than zero, do the math and set average to result of calculation
In main() write code that allows entry of the first name, last name, number of games and number of goals. The number of games and goals must be greater than or equal to zero. If a negative value is entered, the program should display an error and allow the reentry of the number.
Create two instances of players.
The first should use the default constructor and the set methods to fill the attributes
The second should use the other constructor to set the attributes
Display the info about the players including the average goals per game.
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