CSCI204/MCS9204/CSCI804 Object and Generic Programming in C++ Laboratory Exercise 2 (Week 3)

Task 1: Basic class/object construction (1.0)
A basketball union manage the competitions among the teams. There is a text file contains results of the competitions. The format for each competition is like
Define a class Team in the file competition.h that contains a team name, total win, total loss,total score for, total score against. Define the necessary member functions for the class, such as default constructor and other member functions to set and get data members’ values.
Define a class Result in the file competition.h that contains an array of Team with
maximum 10 elements, an integer number counts how many teams. Define the following member functions for the class.
• A load function that loads competition results from a given text file, analysis each competition result by modify the two teams’ information as following:
o If a team is not exists in the Team array, add the team in the Team array.
o If the team already exists, modify the team’s data by
 Increase the total win by one if the team won the competition;
 Increase the total loss by one if the team lost;
 Add the score that the team has got to the total score for;
 Add the score that opponent team has got to the total score against.
• A sort function that sorts the teams in the descending order according to the total win. If the total win times are the same, compare the total loss time, the less the better. If the total win and total loss times are the same, compare the differences of total score for and total score against, the bigger the better. The sorting algorithm is up to you.
• A print function print out the teams’ records to screen.
Implement the member functions in a file competition.cpp.
Write C++ driver program include main function in a file basketball.cpp that read a file name of competition results from keyboard, declare an instance of Result, load the competition results by using the instance of Result, analyse the results, sort the records and print out all teams’ information in the descending order.
You can download a file results.txt from the site for your testing. The example output results will be like:
Input a basketball competition results' file name: results.txt
Shellharbour 10 0 471 100
Raptors 6 5 227 257
Bobcats 6 5 178 225
Spurs 6 6 275 270
MTSO Warriors 5 7 234 273
Mavericks 1 11 159 419
Powered by