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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!