Simulating Ping-Pong Championship
VerifiedAdded on  2019/09/23
|8
|1988
|443
Report
AI Summary
In this assignment, the objective is to create a simulation of a ping-pong championship between single players using C++. The program needs to simulate games between players, keep track of goals scored by each player, and determine the ranking based on points, goal difference, goals for, and goals against. The class template 'Game' should have data members to store the number of goals scored by each competitor in a game, as well as methods to simulate a game and compare players based on ranking criteria. The program should also manage dynamic memory allocation properly.
Contribute Materials
Your contribution can guide someone’s learning journey. Share your
documents today.
Purpose: Get practical experience in
using
- Class and function templates
- Namespace
- STL
- stream manipulators
- code reuse
- UML diagrams
- typeid()
General Requirements
• Follow the principles of OO and generic programming
• Put your name, student number at the beginning of each file submitted
/*-------------------------------------------------
Student's Name:
Student's email address:
Laboratory group (group code and
time): Purpose of this assignment:
-------------------------------------------------------*/
• Add comments to the source code to make your solution easier to follow
Assignment requirements
Write a program that can simulate a championship between competitors such as sport
teams (soccer, hockey, etc), or individual players (tennis, ping-pong, badminton, etc ). You
can reuse code from your own assignment2 solution. If your assignment 2 code was well
structured according to the OOM, it can be efficiently reused. The major objective of this
assignment is to get practical experience with object and generic programming. Sport
competition simulation requirements are deliberately simplified.
BACKGROUND
The structure of the simulation is such that a given number of competitors play in a league
on a double round- robin basis, in which every competitor plays with all others in the league
once at home and once away. It means that if there are n competitors, there would be n*(n –
1) games played.
Competitors receive two points for a win and one point for a draw (if draws are
permitted). No points are awarded for a loss. Draws are permitted for teams, but draws are
not permitted for individual players.
Compititors are ranked according to the following criteria:
using
- Class and function templates
- Namespace
- STL
- stream manipulators
- code reuse
- UML diagrams
- typeid()
General Requirements
• Follow the principles of OO and generic programming
• Put your name, student number at the beginning of each file submitted
/*-------------------------------------------------
Student's Name:
Student's email address:
Laboratory group (group code and
time): Purpose of this assignment:
-------------------------------------------------------*/
• Add comments to the source code to make your solution easier to follow
Assignment requirements
Write a program that can simulate a championship between competitors such as sport
teams (soccer, hockey, etc), or individual players (tennis, ping-pong, badminton, etc ). You
can reuse code from your own assignment2 solution. If your assignment 2 code was well
structured according to the OOM, it can be efficiently reused. The major objective of this
assignment is to get practical experience with object and generic programming. Sport
competition simulation requirements are deliberately simplified.
BACKGROUND
The structure of the simulation is such that a given number of competitors play in a league
on a double round- robin basis, in which every competitor plays with all others in the league
once at home and once away. It means that if there are n competitors, there would be n*(n –
1) games played.
Competitors receive two points for a win and one point for a draw (if draws are
permitted). No points are awarded for a loss. Draws are permitted for teams, but draws are
not permitted for individual players.
Compititors are ranked according to the following criteria:
Secure Best Marks with AI Grader
Need help grading? Try our AI Grader for instant feedback on your assignments.
1. By the total points first;
2. For competitors with an equal number of points, by goal difference
(i.e. the number of goals scored for minus the number of goals
scored against);
3. If the goal difference is also the same, by goals scored for.
4. If still equal, the competitors will occupy the same position.
CODING REQIREMENTS
• Your program shall be well structured and designed based upon concepts of
object oriented and generic programming.
• Your program shall be subdivided into several .h and .cpp files. You also need to
provide a make file to control compilation of your program and produce asm3.exe
executable file. You can select any appropriate template compilation model supported
on banshee.
The program shall define classes, class templates and function templates to simulate
championships for teams or individual players depending on the type explicitly specified
(Team or Player). Classes Team, Player and OrganizingCommittee shall be defined in a
namespace asm3. Your solution shall implement the structure shown on the UML diagram
below:
asm3
Tea
m Player
OrganizingCommittee Championship T:class, maxScore:int
that can be
Team or
2 .. n 2 .. n * (n- 1)
T 2
Game
T:class, maxScore:int
2. For competitors with an equal number of points, by goal difference
(i.e. the number of goals scored for minus the number of goals
scored against);
3. If the goal difference is also the same, by goals scored for.
4. If still equal, the competitors will occupy the same position.
CODING REQIREMENTS
• Your program shall be well structured and designed based upon concepts of
object oriented and generic programming.
• Your program shall be subdivided into several .h and .cpp files. You also need to
provide a make file to control compilation of your program and produce asm3.exe
executable file. You can select any appropriate template compilation model supported
on banshee.
The program shall define classes, class templates and function templates to simulate
championships for teams or individual players depending on the type explicitly specified
(Team or Player). Classes Team, Player and OrganizingCommittee shall be defined in a
namespace asm3. Your solution shall implement the structure shown on the UML diagram
below:
asm3
Tea
m Player
OrganizingCommittee Championship T:class, maxScore:int
that can be
Team or
2 .. n 2 .. n * (n- 1)
T 2
Game
T:class, maxScore:int
A UML diagram that describes the program structure, where T is a
parameterized type Team or Player
The class template Championship shall have a c-string data member to store the competitor
type. It also shall use an STL vector to store the required number of objects of type T. It
shall generate all possible n*(n – 1) games played in a random order among the teams for
the whole season. It shall run the championship when a member function (implemented as
a template) Championship::runChampionship() is called from
OrganizingComittee::start(…). Once all games have been played, one of the member
functions shall print a table with the results of the championship according to the required
output format (see below).
The class Team shall have a data member name to store a team name, and also other
members to store total points, goals scored for and goals scored against, which should
be updated during the championship. The private data members points, goals scored for
and goals scored against shall be updated and accessed through public methods. To make
implementation simple, team names should be: Team1, Team2, Team3,… You also need
to implement the < , >, ==, != overloaded operators to compare teams based on the ranking
criteria described earlier. If other operators are needed, they should be implemented too.
parameterized type Team or Player
The class template Championship shall have a c-string data member to store the competitor
type. It also shall use an STL vector to store the required number of objects of type T. It
shall generate all possible n*(n – 1) games played in a random order among the teams for
the whole season. It shall run the championship when a member function (implemented as
a template) Championship::runChampionship() is called from
OrganizingComittee::start(…). Once all games have been played, one of the member
functions shall print a table with the results of the championship according to the required
output format (see below).
The class Team shall have a data member name to store a team name, and also other
members to store total points, goals scored for and goals scored against, which should
be updated during the championship. The private data members points, goals scored for
and goals scored against shall be updated and accessed through public methods. To make
implementation simple, team names should be: Team1, Team2, Team3,… You also need
to implement the < , >, ==, != overloaded operators to compare teams based on the ranking
criteria described earlier. If other operators are needed, they should be implemented too.
The class Player shall have a data member name to store a player name, and also other
members to sore total points, goals scored for and goals scored against which should be
updated during the championship. The private data members points, goals scored for and
goals scored against shall be updated and accessed through public methods. To make
implementation simple, player names should be: Player1, Player2, Player3,… You also need
to implement the < , >, ==, != overloaded operators to compare players based on the
ranking criteria described earlier (for simplicity reason - the same ranking criteria as for
teams). If other operators are needed, they should be implemented too.
The class template Game shall have two data members to implement association with two
competitors (see the
UML
diagram)
T *competitor1, *competitor2;
This class template shall also have data members to store the number of goals scored by
the first competitor, and the number of goals scored by the second competitor in a single
game. This class template shall have a method to simulate a game by generating
randomly the number of goals scored by each competitor, thus simulating a random
outcome for each game. The maximum number of goals which a competitor can score in a
single game must be limited to a constant passed to Game through the second template
parameter maxScore (see the UML diagram). As draws are not permitted for individual
players, the randomly generated numbers of goals need to be discarded if they are equal and
generated again until they are different. However, draws are permitted for teams.
Although you solution shall be generic, the main() function for this assignment shall use
classes and class templates to simulate only a ping-pong championship between single
players. It shall read one arguments from its command line: the number of competitors: an
integer value that is greater than 1, as the minimum number of competitors for playing a
game is 2. The template parameter maxScore for ping-pong is 11.
If the provided number of competitors does not satisfy the requirements, the program shall
output an error message into the standard error stream and terminate further execution. If the
argument is valid, the main() function shall create an instance of a class
OrganizingCommittee and an instance of a class template Championship. The start of the
championship has to be initialised by the OrganizingCommittee.
For
example:
OrganizingComittee
orgCom;
members to sore total points, goals scored for and goals scored against which should be
updated during the championship. The private data members points, goals scored for and
goals scored against shall be updated and accessed through public methods. To make
implementation simple, player names should be: Player1, Player2, Player3,… You also need
to implement the < , >, ==, != overloaded operators to compare players based on the
ranking criteria described earlier (for simplicity reason - the same ranking criteria as for
teams). If other operators are needed, they should be implemented too.
The class template Game shall have two data members to implement association with two
competitors (see the
UML
diagram)
T *competitor1, *competitor2;
This class template shall also have data members to store the number of goals scored by
the first competitor, and the number of goals scored by the second competitor in a single
game. This class template shall have a method to simulate a game by generating
randomly the number of goals scored by each competitor, thus simulating a random
outcome for each game. The maximum number of goals which a competitor can score in a
single game must be limited to a constant passed to Game through the second template
parameter maxScore (see the UML diagram). As draws are not permitted for individual
players, the randomly generated numbers of goals need to be discarded if they are equal and
generated again until they are different. However, draws are permitted for teams.
Although you solution shall be generic, the main() function for this assignment shall use
classes and class templates to simulate only a ping-pong championship between single
players. It shall read one arguments from its command line: the number of competitors: an
integer value that is greater than 1, as the minimum number of competitors for playing a
game is 2. The template parameter maxScore for ping-pong is 11.
If the provided number of competitors does not satisfy the requirements, the program shall
output an error message into the standard error stream and terminate further execution. If the
argument is valid, the main() function shall create an instance of a class
OrganizingCommittee and an instance of a class template Championship. The start of the
championship has to be initialised by the OrganizingCommittee.
For
example:
OrganizingComittee
orgCom;
Secure Best Marks with AI Grader
Need help grading? Try our AI Grader for instant feedback on your assignments.
Championship<Player, 11> *ppChmp = new Championship<Player,11>( "ping-pong",
numOfCompt);
orgCom.start( ppChmp
);
Before you start writing C++ code, consider what data members and member functions (or
function templates) are needed for each class and a class template to make sure that your
solution is generic and after minor modifications in main() function can simulate
competitions between teams, or individual players. Also consider how to implement the
specified relationship between template classes.
The program shall properly manage dynamic memory
allocation.
You can use the command bcheck on banshee to check if there is any
memory leak.
numOfCompt);
orgCom.start( ppChmp
);
Before you start writing C++ code, consider what data members and member functions (or
function templates) are needed for each class and a class template to make sure that your
solution is generic and after minor modifications in main() function can simulate
competitions between teams, or individual players. Also consider how to implement the
specified relationship between template classes.
The program shall properly manage dynamic memory
allocation.
You can use the command bcheck on banshee to check if there is any
memory leak.
DEVELOPMENT and TESTING
You need to follow good programming practices when you write the source code:
- meaningful identifiers for data members, member functions, classes
- no global variables
- appropriate indentation
- appropriate comments
To minimize time needed to complete this assignment, develop your program incrementally
testing each new component added. Make sure you program is robust and does not crash.
The program shall not produce memory leaks.
Target platform: Sun UNIX ( banshee ), g++ compiler , -Wall -ansi compilation options
Testing:
1. Upload all source code files to your working directory on banshee.
2. Write a make file named Makefile that will be used to compile your program to produce
asm3.exe
executable file
3. Compile your program by running make and check if asm3.exe executable file is produced.
4. Run the program with two arguments provided:
asm3.exe 3
Your program should produce output in the following format:
*** Ping-Pong Championship ***
- Participant list -
Player1
Player2
Player3
-
Games
played -
Player3Player1 Player2 7 0
Player2 Player3 3 1
Player3 Player1 2 1
Player1 Player2 7 0
Player3 Player2 3 1
- Championship table -
Position | Competitor | Points | GoalDiff | GoalsFor | GoalsAgainst
1 Player1 4 3 4 1
2 Player3 2 3 6 3
You need to follow good programming practices when you write the source code:
- meaningful identifiers for data members, member functions, classes
- no global variables
- appropriate indentation
- appropriate comments
To minimize time needed to complete this assignment, develop your program incrementally
testing each new component added. Make sure you program is robust and does not crash.
The program shall not produce memory leaks.
Target platform: Sun UNIX ( banshee ), g++ compiler , -Wall -ansi compilation options
Testing:
1. Upload all source code files to your working directory on banshee.
2. Write a make file named Makefile that will be used to compile your program to produce
asm3.exe
executable file
3. Compile your program by running make and check if asm3.exe executable file is produced.
4. Run the program with two arguments provided:
asm3.exe 3
Your program should produce output in the following format:
*** Ping-Pong Championship ***
- Participant list -
Player1
Player2
Player3
-
Games
played -
Player3Player1 Player2 7 0
Player2 Player3 3 1
Player3 Player1 2 1
Player1 Player2 7 0
Player3 Player2 3 1
- Championship table -
Position | Competitor | Points | GoalDiff | GoalsFor | GoalsAgainst
1 Player1 4 3 4 1
2 Player3 2 3 6 3
3 Player2 0 -6 1 7
This example shows only the required output format. The actual numbers will be different.
Prepare several test cases to test your program properly.
This example shows only the required output format. The actual numbers will be different.
Prepare several test cases to test your program properly.
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Important:
- Submissions without Makefile will not be tested and marked
- If compilation guided by your Makefile does not produce asm3.exe executable file on
banshee server, your assignment will not be tested and marked
NOTES:
1. Submit your assignment before the due date. You can resubmit later if necessary.
Only the latest submission will be tested and marked providing that you have
submitted at least one meaningful solution before the due date, otherwise resubmitted
assignments will not be assessed.
2. If compilation guided by your Makefile does not produce asm3.exe executable file
on banshee, your assignment will not be tested and marked.
3. SUBMISSION BY EMAIL IS NOT ACCEPTABLE. YOU HAVE TO USE SUBMIT
COMMAND TO SUBMIT YOUR WORK.
4. ASSIGNMENT FILES WITHOUT PROPERLY FILLED HEADERS WILL NOT
BE MARKED
5. DO NOT FORWARD THE ACKNOWLEDGEMENT FROM THE
SERVER THAT YOU WILL RECEIVE AFTER SUBMITTING YOUR
ASSIGNMENT TO ANY OTHER EMAIL ACCOUNT, OTHER THAN
UNIVERSITY'S EMAIL ACCOUNT.
THIS ACKNOWLEDGEMENT MAY BE NEEDED IF YOU
WANT TO QUERY ABOUT YOUR ASSIGNMENT.
WITHOUT THE ACKNOWLEDGEMENT FROM THE
SERVER, YOUR QUERY WILL NOT BE PROCESSED
6. Enquiries about the marks can only be made within a maximum of 1 week after the
assignment results are published. After
1 week the marks cannot be changed .
Mark deductions: compilation errors on the target platform, compilation warnings,
incorrect result, no required c l ass templates, no function templates, wrong relationship
between template classes, no namespace, no .h file, memory leaks, games played in a
predefined order, global variables, public data members, poor comments, poor indentation,
meaningless iden ti fiers.
The deductions here are merely a guide. Marks may also be deducted for other mistakes and
poor practices.
- Submissions without Makefile will not be tested and marked
- If compilation guided by your Makefile does not produce asm3.exe executable file on
banshee server, your assignment will not be tested and marked
NOTES:
1. Submit your assignment before the due date. You can resubmit later if necessary.
Only the latest submission will be tested and marked providing that you have
submitted at least one meaningful solution before the due date, otherwise resubmitted
assignments will not be assessed.
2. If compilation guided by your Makefile does not produce asm3.exe executable file
on banshee, your assignment will not be tested and marked.
3. SUBMISSION BY EMAIL IS NOT ACCEPTABLE. YOU HAVE TO USE SUBMIT
COMMAND TO SUBMIT YOUR WORK.
4. ASSIGNMENT FILES WITHOUT PROPERLY FILLED HEADERS WILL NOT
BE MARKED
5. DO NOT FORWARD THE ACKNOWLEDGEMENT FROM THE
SERVER THAT YOU WILL RECEIVE AFTER SUBMITTING YOUR
ASSIGNMENT TO ANY OTHER EMAIL ACCOUNT, OTHER THAN
UNIVERSITY'S EMAIL ACCOUNT.
THIS ACKNOWLEDGEMENT MAY BE NEEDED IF YOU
WANT TO QUERY ABOUT YOUR ASSIGNMENT.
WITHOUT THE ACKNOWLEDGEMENT FROM THE
SERVER, YOUR QUERY WILL NOT BE PROCESSED
6. Enquiries about the marks can only be made within a maximum of 1 week after the
assignment results are published. After
1 week the marks cannot be changed .
Mark deductions: compilation errors on the target platform, compilation warnings,
incorrect result, no required c l ass templates, no function templates, wrong relationship
between template classes, no namespace, no .h file, memory leaks, games played in a
predefined order, global variables, public data members, poor comments, poor indentation,
meaningless iden ti fiers.
The deductions here are merely a guide. Marks may also be deducted for other mistakes and
poor practices.
1 out of 8
Your All-in-One AI-Powered Toolkit for Academic Success.
 +13062052269
info@desklib.com
Available 24*7 on WhatsApp / Email
Unlock your academic potential
© 2024  |  Zucol Services PVT LTD  |  All rights reserved.