CS 115: Assignment 6 Assignment 6 Due April 14, 2021 Overview This assignment will be in two sections. In the first section, you will modify your game to use interface inheritance to handle the...

1 answer below »
Extract the zip file and run the code.
The pdf shows you the steps you need to do to get this assignment done.
I have very little time. So do let me know if you can do it.



CS 115: Assignment 6 Assignment 6 Due April 14, 2021 Overview This assignment will be in two sections. In the first section, you will modify your game to use interface inheritance to handle the different types of tiles. Instead of a single Tile type with a genus variable, each tile genus will have its own subclass (e.g. TileMoney). The Tile type will become an abstract superclass. You will also add bomb tiles which, when activated, will destroy themselves and their neighbouring tiles. In the second section, you will write a small module that centers double values in output. You will then convert the module to use templates so that it works on any data type. This will be a separate program and is not connected to the game is any way. The purpose of this assignment is to give you practice with polymorphism, including interface inheritance and templates. For Part A, you will convert your Tile class to an abstract superclass. For Parts B, C, and D, you will create subclasses for money, dice, and points tiles. For Part E, you will adapt your program to use the new types of tiles. For Part F, you will create a subclass for bomb tiles. For Part G, you will write a pair of template functions to center values when printing them. Copying Tiles After creating the tile subclasses, a tile might have any of several types. This makes copying tiles difficult because we won't know what type the copy should have. Normally the program doesn't need to know because a Tile* pointer can point to any subclass of Tile. But when creating a copy, we need to invoke the correct copy constructor, which requires us to know the type. To solve this, we will use a virtual function named getClone that creates and returns a dynamically allocated copy of the current object. Each subclass will have its own (very similar) implementation that invokes the copy constructor for that subclass. Then, to create a copy, we just need to call getClone from a Tile pointer (Tile*) or reference (Tile&). Dynamic binding will ensure the correct implementation will be invoked, and thus the correct copy constructor will be used. Centering Text The C++ standard libraries include commands to left-align and right-align values printed to output streams (e.g. cout). However, there are times when other alignments are useful. For example, programmers sometimes want to center headings. To address this problem, you will write a pair of template functions named center. One of these will center a value within a block of a specified width. To do this, you will first use the stringstream class to convert the value to a string. Then you will add the appropriate number of spaces on the two sides and return the result. The function will be used as follows: cout < center(my_var,="" 20)="">< endl;="" the="" second="" function="" will="" center="" a="" value="" across="" the="" entire="" console,="" assuming="" that="" the="" console="" has="" the="" traditional="" width="" of="" 80="" characters.="" this="" is="" a="" convenience="" function,="" meaning="" that="" its="" only="" purpose="" is="" to="" provide="" a="" more="" convenient="" way="" to="" call="" another="" function.="" this="" function="" will="" be="" used="" as="" follows:="" cout="">< center(my_var)="">< endl;="" you="" will="" first="" implement="" these="" functions="" to="" work="" with="" double="" values.="" then="" you="" will="" convert="" them="" to="" template="" functions="" that="" work="" with="" any="" data="" type="" for="" which="" the="" stream="" insertion="" operator=""><) is defined. requirements part a: convert tile to an abstract superclass [22% = 18% test program + 4% code] in part a, you will convert your tile class to be an abstract superclass. by the end of part a, your abstract tile superclass will have the following public member functions: • tile (); • tile (const tile& to_copy); • virtual ~tile (); • tile& operator= (const tile& to_copy); • virtual tile* getclone () const = 0; • bool isowner () const; • unsigned int getaffectedplayer ( unsigned int whose_turn) const; • void setowner (unsigned int owner1); • virtual void activate (unsigned int who_rolled, const cellid& rolled_cell, board& board) const = 0; • virtual void print () const = 0; you will also have the following protected member function (which was private): • void printownerchar () const; you will remove following member functions: • tile (unsigned int genus, unsigned int species); • unsigned int getgenus () const; • unsigned int getspecies () const; • void printgenuschar () const; • void printspecieschar () const; • bool isinvarianttrue () const; perform the following steps: 1. update the function prototypes. remove the implementations for the removed functions. also remove the implementations from the pure virtual member functions (the ones with = 0). • hint: put a forward declaration for the board class right after the #includes in the tile.h file: class board; this is like a function prototype, except that it is for a class. • warning: do not put an #include "board.h" in the tile.h file. if you do, you will have circular #includes (tile.h includes board.h includes tile.h includes board.h includes…). these cause your program to fail to compile with strange error messages. • note: the activate function now has two more parameters. we will need them for bomb tiles in part f. • note: at this point, much of your game will stop compiling. it will not compile again until the end of part e. files that will not compile include board.cpp, availabletiles.cpp, main.cpp, and game.cpp. however, the test programs for parts a, b, c, and d should compile and run when they are mentioned below. 2. remove the genus and species member fields. remove all references to them from the member functions. subclasses will declare their own member variables as needed. 3. remove the lines that declare the constants for tile genus, e.g., genus_money, etc. 4. remove the class invariant. it is no longer needed. 5. add the implementations for the copy constructor, destructor, and assignment operator. • reminder: every constructor should set the value of every member variable. the assignment operator should also set the value of every member variable. • reminder: instructions for writing copy constructors, destructors, and assignment operators are given in section 10 of the on-line notes on canonical form. • reminder: the assignment operator should check for self-assignment and return *this at the end. 6. test your tile abstract class using the testtile6.cpp program provided. you will need testhelper.h and testhelper.cpp. this test program was added on april 8, 2021. • note: to compile this test program, you must not compile your board.cpp file. on posix systems (including replit), change the file extension from .cpp to .cppx. in visual studio, right-click on the file and choose "exclude from project". • note: you may also have to exclude availabletiles.cpp, game.cpp, and main.cpp. • note: your complete game will not compile at the end of part a, b, c, or d. it should compile at the end of part e. part b: add the tilemoney subclass [15% = 7% test program + 3% output + 5% code] in part b, you will create the tilemoney class as a subclass of tile. it will have a member variable for the amount of money that the affected player receives when it activates. http://www2.cs.uregina.ca/%7eanima/115/terms/202110/assignments/assignment6/testtile6.cpp http://www2.cs.uregina.ca/%7eanima/115/terms/202110/assignments/assignment1/testhelper.h http://www2.cs.uregina.ca/%7eanima/115/terms/202110/assignments/assignment1/testhelper.cpp by the end of part a, your tilemoney class will have the following public member functions: • tilemoney (unsigned int money1); • tilemoney (const tilemoney& to_copy); • virtual ~tilemoney (); • tilemoney& operator= (const tilemoney& to_copy); • virtual tile* getclone () const; • virtual void activate (unsigned int who_rolled, const cellid& cell, board& board) const; • virtual void print () const; perform the following steps: 1. create the tilemoney class with the appropriate function prototypes. it should have a member variable for the amount of money that the affected player receives when the tile is activated. it should inherit from the tile class using public inheritance. add an #include for "tile.h" in both of the tilemoney.h and tilemoney.cpp files. 2. add an implementation for the money constructor (the one with the money1 parameter). it should use an initializer list (":" notation) to explicitly invoke the tile default constructor and to set the member variable. 3. add an implementation for the copy constructor. it should use an initializer list (":" notation) to explicitly invoke the tile copy constructor and to copy the member variable. 4. add an implementation for the destructor. it should be empty. • reminder: do not call the tile destructor. it will be invoked automatically. 5. add an implementation for the assignment operator. it should invoke the assignment operator from the tile class and then it should copy the member variable for the tilemoney class. remember to check for self-assignment and to return *this at the end. 6. is="" defined.="" requirements="" part="" a:="" convert="" tile="" to="" an="" abstract="" superclass="" [22%="18%" test="" program="" +="" 4%="" code]="" in="" part="" a,="" you="" will="" convert="" your="" tile="" class="" to="" be="" an="" abstract="" superclass.="" by="" the="" end="" of="" part="" a,="" your="" abstract="" tile="" superclass="" will="" have="" the="" following="" public="" member="" functions:="" •="" tile="" ();="" •="" tile="" (const="" tile&="" to_copy);="" •="" virtual="" ~tile="" ();="" •="" tile&="" operator="(const" tile&="" to_copy);="" •="" virtual="" tile*="" getclone="" ()="" const="0;" •="" bool="" isowner="" ()="" const;="" •="" unsigned="" int="" getaffectedplayer="" (="" unsigned="" int="" whose_turn)="" const;="" •="" void="" setowner="" (unsigned="" int="" owner1);="" •="" virtual="" void="" activate="" (unsigned="" int="" who_rolled,="" const="" cellid&="" rolled_cell,="" board&="" board)="" const="0;" •="" virtual="" void="" print="" ()="" const="0;" you="" will="" also="" have="" the="" following="" protected="" member="" function="" (which="" was="" private):="" •="" void="" printownerchar="" ()="" const;="" you="" will="" remove="" following="" member="" functions:="" •="" tile="" (unsigned="" int="" genus,="" unsigned="" int="" species);="" •="" unsigned="" int="" getgenus="" ()="" const;="" •="" unsigned="" int="" getspecies="" ()="" const;="" •="" void="" printgenuschar="" ()="" const;="" •="" void="" printspecieschar="" ()="" const;="" •="" bool="" isinvarianttrue="" ()="" const;="" perform="" the="" following="" steps:="" 1.="" update="" the="" function="" prototypes.="" remove="" the="" implementations="" for="" the="" removed="" functions.="" also="" remove="" the="" implementations="" from="" the="" pure="" virtual="" member="" functions="" (the="" ones="" with="0)." •="" hint:="" put="" a="" forward="" declaration="" for="" the="" board="" class="" right="" after="" the="" #includes="" in="" the="" tile.h="" file:="" class="" board;="" this="" is="" like="" a="" function="" prototype,="" except="" that="" it="" is="" for="" a="" class.="" •="" warning:="" do="" not="" put="" an="" #include="" "board.h"="" in="" the="" tile.h="" file.="" if="" you="" do,="" you="" will="" have="" circular="" #includes="" (tile.h="" includes="" board.h="" includes="" tile.h="" includes="" board.h="" includes…).="" these="" cause="" your="" program="" to="" fail="" to="" compile="" with="" strange="" error="" messages.="" •="" note:="" the="" activate="" function="" now="" has="" two="" more="" parameters.="" we="" will="" need="" them="" for="" bomb="" tiles="" in="" part="" f.="" •="" note:="" at="" this="" point,="" much="" of="" your="" game="" will="" stop="" compiling.="" it="" will="" not="" compile="" again="" until="" the="" end="" of="" part="" e.="" files="" that="" will="" not="" compile="" include="" board.cpp,="" availabletiles.cpp,="" main.cpp,="" and="" game.cpp.="" however,="" the="" test="" programs="" for="" parts="" a,="" b,="" c,="" and="" d="" should="" compile="" and="" run="" when="" they="" are="" mentioned="" below.="" 2.="" remove="" the="" genus="" and="" species="" member="" fields.="" remove="" all="" references="" to="" them="" from="" the="" member="" functions.="" subclasses="" will="" declare="" their="" own="" member="" variables="" as="" needed.="" 3.="" remove="" the="" lines="" that="" declare="" the="" constants="" for="" tile="" genus,="" e.g.,="" genus_money,="" etc.="" 4.="" remove="" the="" class="" invariant.="" it="" is="" no="" longer="" needed.="" 5.="" add="" the="" implementations="" for="" the="" copy="" constructor,="" destructor,="" and="" assignment="" operator.="" •="" reminder:="" every="" constructor="" should="" set="" the="" value="" of="" every="" member="" variable.="" the="" assignment="" operator="" should="" also="" set="" the="" value="" of="" every="" member="" variable.="" •="" reminder:="" instructions="" for="" writing="" copy="" constructors,="" destructors,="" and="" assignment="" operators="" are="" given="" in="" section="" 10="" of="" the="" on-line="" notes="" on="" canonical="" form.="" •="" reminder:="" the="" assignment="" operator="" should="" check="" for="" self-assignment="" and="" return="" *this="" at="" the="" end.="" 6.="" test="" your="" tile="" abstract="" class="" using="" the="" testtile6.cpp="" program="" provided.="" you="" will="" need="" testhelper.h="" and="" testhelper.cpp.="" this="" test="" program="" was="" added="" on="" april="" 8,="" 2021.="" •="" note:="" to="" compile="" this="" test="" program,="" you="" must="" not="" compile="" your="" board.cpp="" file.="" on="" posix="" systems="" (including="" replit),="" change="" the="" file="" extension="" from="" .cpp="" to="" .cppx.="" in="" visual="" studio,="" right-click="" on="" the="" file="" and="" choose="" "exclude="" from="" project".="" •="" note:="" you="" may="" also="" have="" to="" exclude="" availabletiles.cpp,="" game.cpp,="" and="" main.cpp.="" •="" note:="" your="" complete="" game="" will="" not="" compile="" at="" the="" end="" of="" part="" a,="" b,="" c,="" or="" d.="" it="" should="" compile="" at="" the="" end="" of="" part="" e.="" part="" b:="" add="" the="" tilemoney="" subclass="" [15%="7%" test="" program="" +="" 3%="" output="" +="" 5%="" code]="" in="" part="" b,="" you="" will="" create="" the="" tilemoney="" class="" as="" a="" subclass="" of="" tile.="" it="" will="" have="" a="" member="" variable="" for="" the="" amount="" of="" money="" that="" the="" affected="" player="" receives="" when="" it="" activates.="" http://www2.cs.uregina.ca/%7eanima/115/terms/202110/assignments/assignment6/testtile6.cpp="" http://www2.cs.uregina.ca/%7eanima/115/terms/202110/assignments/assignment1/testhelper.h="" http://www2.cs.uregina.ca/%7eanima/115/terms/202110/assignments/assignment1/testhelper.cpp="" by="" the="" end="" of="" part="" a,="" your="" tilemoney="" class="" will="" have="" the="" following="" public="" member="" functions:="" •="" tilemoney="" (unsigned="" int="" money1);="" •="" tilemoney="" (const="" tilemoney&="" to_copy);="" •="" virtual="" ~tilemoney="" ();="" •="" tilemoney&="" operator="(const" tilemoney&="" to_copy);="" •="" virtual="" tile*="" getclone="" ()="" const;="" •="" virtual="" void="" activate="" (unsigned="" int="" who_rolled,="" const="" cellid&="" cell,="" board&="" board)="" const;="" •="" virtual="" void="" print="" ()="" const;="" perform="" the="" following="" steps:="" 1.="" create="" the="" tilemoney="" class="" with="" the="" appropriate="" function="" prototypes.="" it="" should="" have="" a="" member="" variable="" for="" the="" amount="" of="" money="" that="" the="" affected="" player="" receives="" when="" the="" tile="" is="" activated.="" it="" should="" inherit="" from="" the="" tile="" class="" using="" public="" inheritance.="" add="" an="" #include="" for="" "tile.h"="" in="" both="" of="" the="" tilemoney.h="" and="" tilemoney.cpp="" files.="" 2.="" add="" an="" implementation="" for="" the="" money="" constructor="" (the="" one="" with="" the="" money1="" parameter).="" it="" should="" use="" an="" initializer="" list="" (":"="" notation)="" to="" explicitly="" invoke="" the="" tile="" default="" constructor="" and="" to="" set="" the="" member="" variable.="" 3.="" add="" an="" implementation="" for="" the="" copy="" constructor.="" it="" should="" use="" an="" initializer="" list="" (":"="" notation)="" to="" explicitly="" invoke="" the="" tile="" copy="" constructor="" and="" to="" copy="" the="" member="" variable.="" 4.="" add="" an="" implementation="" for="" the="" destructor.="" it="" should="" be="" empty.="" •="" reminder:="" do="" not="" call="" the="" tile="" destructor.="" it="" will="" be="" invoked="" automatically.="" 5.="" add="" an="" implementation="" for="" the="" assignment="" operator.="" it="" should="" invoke="" the="" assignment="" operator="" from="" the="" tile="" class="" and="" then="" it="" should="" copy="" the="" member="" variable="" for="" the="" tilemoney="" class.="" remember="" to="" check="" for="" self-assignment="" and="" to="" return="" *this="" at="" the="" end.="">
Answered 1 days AfterApr 14, 2021

Answer To: CS 115: Assignment 6 Assignment 6 Due April 14, 2021 Overview This assignment will be in two...

Kamal answered on Apr 15 2021
153 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here