Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

^^^^^^^ Language is c++ ^^^^^^^^ For this exercise you will be creating a set of simple player characters for a D&D game. Program Description This

^^^^^^^Language is c++^^^^^^^^

image text in transcribedimage text in transcribed

For this exercise you will be creating a set of simple player characters for a D&D game. Program Description This problem is designed to give you practice at using inheritance, composition, and virtual methods to support polymorphism. If you have questions while working on it, it is suggested you review the documents in Moodle on these three topics. Those documents have examples that should help in solving this lab. For this program you will define two distinct classes and four that inherit from one of those two. You will use the provided test driver to test your code. It is suggested you use your own test drivers to test each class as you develop it. Program Requirements For this, as in all assignments, you are expected to follow the course programming style guidelines and to properly implement both header and source files for your functions. All input should be fully validated You should have two header and source files, one for the Person class and its methods and the Player class and its methods. Note that Player header needs to include Person header. You should also have separate header and source files for getInteger since it is called both in main to get the number of characters and in createCharacter to get an age. Person Class The Person class should include three private variables, string firstName, lastName and int age. It should have a default constructor that sets both names to and age to 0. It should have an overloaded constructor that has parameters to set all values. All constructors should use initialization lists. There should be a destructor that does nothing. All variables should have setters and getters. All getters should be constant. All setters and getters should be inline functions (defined in class). The source file for Person will be empty. Player Class The Player class is an abstract class. It includes an instance of a person, which should be created dynamically and deleted when Player goes away, this is an example of class composition. Constructor - default constructor creates a default Person, overloaded constructor has parameters firstName, lastName, and age and creates Person using those values. Destructor - deletes the Person. getPlayerName - returns a single string that is firstName, space, lastName getPlayer Age-returns the age getClassName, getAction - pure virtual functions with return type string. Character Classes The four different character classes all inherit from Player. Each has an overloaded constructor with parameters firstName, lastName, and age that is used to initialize Player. They also all override the getClassName and getAction methods with the following information. Class Ranger - "shoots arrows" Class Wizard - "casts fireballs" Class Rogue - "picks pockets Class Priest - "heals Helper Functions getInteger used to get an input value o input parameters are min and max value o get and validates an integer between min and max o return the value create Player used to dynamically create a new character class o get both names and age, age validated as between 5 and 90. o get character class, validated to be in one of the above dasses use names and age to dynamically create proper character using a Player pointer return the Player pointer displayPlayers used to display array of Players for each player display the full name, age, and class o no return values Main functionality Your main program should ask the user how many players are in the game. It should use getInteger to enter a value between 5 and 10 and create a dynamic array of Player pointers. It should have a for loop that calls createPlayer and fills the array with the returned Player objects. Finally, it should call displayPlayers to list each player's full name, age, class, and action. Example Output sue jones aged 25 playing a Priest heals bob smith aged 30 playing a Rogue picks pocket mary smith aged 35 playing a Wizard casts fireballs joe jones aged 27 playing a Ranger shoots arrows barb player aged 32 playing a Wizard casts fireballs fred flintstone aged 45 playing a Rogue picks pocket martha flintstone aged 46 playing a Priest heals For this exercise you will be creating a set of simple player characters for a D&D game. Program Description This problem is designed to give you practice at using inheritance, composition, and virtual methods to support polymorphism. If you have questions while working on it, it is suggested you review the documents in Moodle on these three topics. Those documents have examples that should help in solving this lab. For this program you will define two distinct classes and four that inherit from one of those two. You will use the provided test driver to test your code. It is suggested you use your own test drivers to test each class as you develop it. Program Requirements For this, as in all assignments, you are expected to follow the course programming style guidelines and to properly implement both header and source files for your functions. All input should be fully validated You should have two header and source files, one for the Person class and its methods and the Player class and its methods. Note that Player header needs to include Person header. You should also have separate header and source files for getInteger since it is called both in main to get the number of characters and in createCharacter to get an age. Person Class The Person class should include three private variables, string firstName, lastName and int age. It should have a default constructor that sets both names to and age to 0. It should have an overloaded constructor that has parameters to set all values. All constructors should use initialization lists. There should be a destructor that does nothing. All variables should have setters and getters. All getters should be constant. All setters and getters should be inline functions (defined in class). The source file for Person will be empty. Player Class The Player class is an abstract class. It includes an instance of a person, which should be created dynamically and deleted when Player goes away, this is an example of class composition. Constructor - default constructor creates a default Person, overloaded constructor has parameters firstName, lastName, and age and creates Person using those values. Destructor - deletes the Person. getPlayerName - returns a single string that is firstName, space, lastName getPlayer Age-returns the age getClassName, getAction - pure virtual functions with return type string. Character Classes The four different character classes all inherit from Player. Each has an overloaded constructor with parameters firstName, lastName, and age that is used to initialize Player. They also all override the getClassName and getAction methods with the following information. Class Ranger - "shoots arrows" Class Wizard - "casts fireballs" Class Rogue - "picks pockets Class Priest - "heals Helper Functions getInteger used to get an input value o input parameters are min and max value o get and validates an integer between min and max o return the value create Player used to dynamically create a new character class o get both names and age, age validated as between 5 and 90. o get character class, validated to be in one of the above dasses use names and age to dynamically create proper character using a Player pointer return the Player pointer displayPlayers used to display array of Players for each player display the full name, age, and class o no return values Main functionality Your main program should ask the user how many players are in the game. It should use getInteger to enter a value between 5 and 10 and create a dynamic array of Player pointers. It should have a for loop that calls createPlayer and fills the array with the returned Player objects. Finally, it should call displayPlayers to list each player's full name, age, class, and action. Example Output sue jones aged 25 playing a Priest heals bob smith aged 30 playing a Rogue picks pocket mary smith aged 35 playing a Wizard casts fireballs joe jones aged 27 playing a Ranger shoots arrows barb player aged 32 playing a Wizard casts fireballs fred flintstone aged 45 playing a Rogue picks pocket martha flintstone aged 46 playing a Priest heals

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

Information Modeling And Relational Databases

Authors: Terry Halpin, Tony Morgan

2nd Edition

0123735688, 978-0123735683

More Books

Students also viewed these Databases questions

Question

help asp

Answered: 1 week ago