” CS 215编程 写作、 辅导program程序CS 215 Winter 2019Project 3/4Learning Objectives:- Implementation of a program using Object Oriented Design.- Implementation of lists using Dynamically-Allocated Linked Lists.General Description:You are to write a program that implements score keeping for a league of sports teams. The leagueconsists of a list of teams that are members of the league, and a list of games/matches.Team data and initial game data are read from text files. Using menu options, the user may view variousparts of the data, and May add new games to the data. The game data is then written to a text file onexit from the program.The program presents the user with the menu asshown here, starting with a logo that contains theprogram name and the name of the programmer.The menu option entered by the user is validateduntil a valid Menu option is entered. Only the firstcharacter of the users input is recognized, and thatcharacter is treated as not case sensitive. Afterperformance of a valid option, the menu repeatsuntil the exit option is selected.List all teams:A list of all teams read from the input file is printedusing the format shown in the example. The headerline includes the total number of teams inparenthesis. Field widths include:- Team Id 4- Team Name 25- Coach 20with two spaces between columns. No system pauseis needed after the list is printed.List all games:A list of all games read from the input file and entered by theuser is printed using the format shown in the example. Theheader line includes the total number of teams inparenthesis. The field widths include:- Date 10 (left justified)- Team Ids 4 (left justified)- Scores 3 (right justified)with two spaces between columns. Note that the winningteam is listed first on each line. After the last game is printed,a blank line is followed by a system pause.2Query Team:First, the list of Teams is printed, exactly as in print all teams above.Next, the user is asked to enter the Team Id of the selected team. The users input is validated to be avalid Team Id, repeating until a validvalue is entered.A report of the selected team is printedas shown in the example. It includesthe number of games won and lost bythe team, based on counts taken fromthe game data.Finally, the game list is printed,formatted exactly as described abovefor print all teams. Note that bothgames lost (team data in the rightcolumns) and games won (team data inthe center columns) are printed.Add Game:First, the list of all teams is printed exactly as described above for print all teams.The user is then asked to enter the Team Id for the first team. This is validated/repeated exactly asdescribed for Query Team. The Team Idfor the second team is entered/validated.Next, the points for the two teams andthe date of the game are entered. There isno validation for these three values, and itis assumed the user will enter integers forscores, and a string with no spaces in thecorrect date format for the date.Once all data is entered, and the game data added to the internal list, the program prints Gameadded. Note the program may have to swap team 1 with team 2 when adding the game, dependingon the higher score (since the winning team should be stored as team 1).Exit:The program should write the current game data to anoutput file called games2.txt, then do a systempause before ending the program.3Detailed Design:The program should be designed and implemented using Object Oriented Programming. All lists shouldbe implemented as Dynamically-Allocated Linked Lists.main program:Write a free function called doAbort() that is given an error message (string). It prints the error messageon the screen, Followed by a newline; does a system pause; and ends the program with exit(1); For any.cpp in the project that needs to invoke this free function, place its prototype at the top of the .cpp file.The main program should declare a league class and invoke the go() method. This should be followed bythe standard system pause and return 0;The classes consist of the following:teamA team consists of the following data:- Team Id (assumed to be length 4 or less with no spaces)- Name (assumed to be length 25 or less and may have spaces)- Coach (assumed to be length 20 or less and may have spaces)- next (pointer to the next team object in a linked list of teams)Standard set and get methods should be coded for the Team Id, Name and Coach (probably not neededfor the next pointer, but those may be added if needed).Write a standard constructor (pointers are usually set to NULL in constructors).You may declare the team list Class to be a friend, but no other classes or free functions should bedeclared as friends.team listThe team list is a dynamic linked list of team objects. The only data needed is a head pointer for thelinked list (optional: a tail pointer). The constructor should set the head (and tail) to NULL.The methods that should be implemented include:addTeam: given a new team objectDynamically allocates a new team object and copies the data from the given object into thedynamic object. It should then add the new object to the front (head) of the linked list.4readData:Reads data from a file called teams.txt and adds them to the linked list.The format of the input file is, for each team:- first line: the Team Id, a String with no spaces- second line: the Team Name, a string with spaces- third line: the Coach, a string with spaces-There is no number of teams nor a Sentinel value at the end of the data. Instead use the .eof()method of an ifstream to detect end of file. Ex: while(!f.eof()) { }A sample input file is provided on the course website. Here is one with two teams:UKKentucky WildcatsCalipariLOULouisville CardinalsJob OpenprintTeams:Prints the team list report as described above, based on data currently in the linked list ofteams.getTeamRef: given: a Team Idreturns: a pointer to a team, or NULLSearches the current linked list for a team object that has a matching Team Id member. Whenfound, return the pointer to the team object found; otherwise, return NULL for not found.getNumTeams: returns: the number of teams in the list.Count and return the number of nodes in the list, which may be 0.game: game objects will be part of a linked list (gameList) and will also point to objects in the Team ListA game consists of the following data for a game played between two teams:- date a string assumed to be in YYYY/MM/DD format (length 10)- points scored(2) points scored by team 1 and team 2- team pointer (2) a pointer to a team in the teamList list for team 1 and team 2- next a pointer to a game, the next game in the list or NULLThe class may make class gameList a friend, but no other classes or functions.Constructor: standard constructor initializing all members of the object.set: one set method given a date, two team pointers, and two scores.alternative: one set Method for each member (except next)gets: one get for each member, except next.5gameList: this is a Linked List of game objects, including a head and tail pointer.data and constructorhead – a pointer to a game object, the first in the listtail – a pointer to a game object, the last in the listconstructor simply sets the two pointers to NULL.addGame given a game object.- dynamically allocates a new game object- copies the data members from the given object into the newly allocated object- inserts the newly allocated object into the game list at the tail of the list.readGames: – given a Team List Object.This method reads game data from a file called games.txt (validate the file opens, andclose at the end) and creates the initial game list.The format of the game input file is: each line contains data on one game in the following order:DATE TEAM ID 1 POINTS FOR TEAM 1 TEAM ID2 POINTS FOR TEAM 2There is no number of games at the top of file, and there is no sentinel value/record at theend of the file. Use eof() to detect the end of file. A sample data file is provided on the coursewebsite.The method should read data into a local game object. It will have to look up a pointer to eachteam using the Team List Object passed in. It should invoke addGame on the populated gameobject to add a new game to the list.This function invokes the global free function (declared in main() and prototyped in this .cpp file)abort() when:- the file fails to opengameList::readGames: unable to open games.txt- the Team Id read is not found in the given Team List for either team:gameList::read: invalid team id 1/2 = + teamIdReadFromFilegetNumGames counts and returns the number of games in the entire list.getNumWins given a pointer to a team object, searches the list and counts/returns the number ofgames won by the Team pointed to by the given pointer.getNumLosses given a pointer to a team object, searches the list and counts/returns the number ofgames lost by the team pointed to by the given pointer.6printGames given a pointer to a team object- when the given pointer is NULL, prints all games in the list.(See List all games example above).- when the given pointer is NOT NULL, prints all games in the list where the given pointer pointsto the same team object as team pointer 1 or team pointer 2 in the list.(See Query Team example above).- Print a header as shown in the examples above, including the number of teams in a dashedline for the first line (invoke getNumGames()). Put two blanks between each column. Assumethe max lengths on the data values are:o date: 10o points: 3o team Id 4writeGames Writes the current game data to a text file called games2.txt, in the same format as the inputfile described in readGames above. The method should use the two team pointers for eachgame to retrieve the Team Id for each.league: this represents our whole application. Main simply declares a league object and invokes its go().Most of the methods have been written for you (posted on the course website). Similar to your lab 8,complete the methods where there are // TO DO: comment tags in the code.All methods are private except go()!Data and constructors- a team list object- a game list object- constructor: since both members have their own constructors, a constructor is not needed.askTeamId given: a (string) prompt that is assumed to be like Enter team id returns: a pointer to the team found.This method prints the prompt and allows the user to enter a Team Id (assume no spaces). Itsearches the Team List for the team Id entered. When found, it returns the team Id pointer. Whennot found, it repeats the question (prompt) until the user enters a valid team Id. See Query Team inthe specifications above.addGame This method prints the team list, invokes askTeamId() twice to get the team pointers for two teams,asks for the points for the two teams and the date of the game. It populates a local game objectthen invokes addGame in The game list to add a new game to the list.7queryTeam This method first prints the team list. It invokes askTeamId to get a pointer to the team to look up. Ituses the get() methods from the team class to print the data from the found team object. Finally, itprints all games for the team by invoking printGames() giving it the found team pointer. See QueryTeam above for the format of the output.getMenuOption returns the users selected menu option. This is written for you.go()This is the main of the Application. It starts by invoking the reads in both the team list and gamelist objects. This is followed by the main menu control loop for the application.Submission:zip the following files into a .zip file, and submit the .zip in Canvas:- game.h, game.cpp- gameList.h, gameList.cpp- team.h, team.cpp- teamList.h, teamList.cpp- league.h, league.cpp- proj3/main.cppThere is no need to include data files (.txt)如有需要,请加QQ:99515681 或WX:codehelp
“
添加老师微信回复‘’官网 辅导‘’获取专业老师帮助,或点击联系老师1对1在线指导。