Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please thoroughly read the question [40 pts.] You will define a single class, SoccerTeam, defined as follows: A SoccerTeam has - a ranking (int) -

please thoroughly read the question

image text in transcribedimage text in transcribed [40 pts.] You will define a single class, SoccerTeam, defined as follows: A SoccerTeam has - a ranking (int) - a name (strin). - a city where it is located (string) - a state (2 letters) where it is located (string) - a collection of opponent SoccerTaan (s) that it intends to play friendly (unofficial) games - with, for pre-toumament practice. Provide the definition of the SoccerTeam class. This is the ONLY class you need to write. Implement the following functions 4 an appropriate constructor for the SoccerTeam class (see the test code below) a output operator for a SoccerTeam object providing the information about the team. This must include the SoccerTeam's ranking, city, state and the list of opponent SoccerTeam names that it will face in the friendly games, if applicable. (See example output below.) - a member function (aka method) add_opponent which adds a SoccerTeam to the collection of opponent SoccerTeam(s). - a member function (aka method) can_play that enforces the rules, below, determining if a team can play another team, i.e. the team that is passed in. can_play will return true if the two teams are allowed to play and false otherwise. You probably want to use this method in your implementation of add_opponent to save a lot of duplicate writing. Enforce the following rules - A SoccerTeam cannot be added to its own collection of opponents - An opponent SoccerTeam may be added if, and only if: - Its ranking differs by less than " 6 " (i.e. 5 or smaller) from the ranking of the SoccerTeam it's being added to, and - The two SoccerTeams are not located in the same state. - This is a reciprocal relationship. That means that when SoccerTeam A adds SoccerTeam B to its collection of opponents, then SoccerTean B will also have SoccerTeam A in its collection of opponents. - a SoccerTeam cannot be added more than once to the collection of another SoccerTeam, - Of course, a SoccerTeam may be added to muitiple SoccerTeams, e.g. SoccerTeam A might be added to SoccerTeam B, as well as to SoccerTeam C's collection of opponents. - the add opponent method should not fail silently. That means that if it fails, retum false. If it succeeds, return true. - It is possible for two different teams to have the same namel Note - This problem does not involve copy control or the heap. Do not allocate a SoccerTeam on the heap! There is Sample test code on the next page Sample test code You should consider the following code to test your implemientation: int main( ) f SoccerTeam p1(22, "Revolution", "Boston", "MA"); SoccerTeam p2(19, "NYFC", "New York", "NY"); SoccerTeam p3(20, "Red Bulls", "New York", "NY"); SoccerTeam p4(20, "Red Devils", "Chicago", "IL"); SoccerTeam p5(25, "LAFC", "Los Angeles", "CA"); SoccerTeam p6(10, "DFC", "Dallas", "TX"): SoccerTeam p7(27, "TFC", "Tampa", "FL"); p1.add_opponent(p2); // returns true p1.add_opponent(p1); // returns false, can't add to self p2.add_opponent(p1); // returns false, already added to p1 p2.add_opponent(p3); // returns false, same state p4.add_opponent(p1); // returns true p5.add_opponent(p6); // returns false, ranking diff >5 p7.add_opponent(p1); // returns true cout p1 end 1 endl p2 endl; \} Sample output The following output was produced from executing our sample test code on our solution: Team Revolution (Boston, MA), ranked 22 faces: YYFC, Red Devils, TFC, Team NYFC (New York, NY), ranked :9 faces: Revolution

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

Professional SQL Server 2012 Internals And Troubleshooting

Authors: Christian Bolton, Justin Langford

1st Edition

1118177657, 9781118177655

More Books

Students also viewed these Databases questions