Question: IN C++ PROGRAMMING: Create a class that holds Games that includes three pieces of information as data membersa game name called name (type string), a
IN C++ PROGRAMMING:
Create a class that holds Games that includes three pieces of information as
data membersa game name called name (type string), a game type called
(type string) and cost of game called cost (type float). Your class should have
a constructor that initializes the three data members, another overloaded
version that defaults the name to No Name, and accepts the type and price
parameters, another overloaded version that defaults the name to No
Name, and sets the type to Unknown and the price parameter, and lastly a
default constructor that sets name to No Name, and sets the type to
Unknown and the price to 0. Provide set and get functions for each data
member, using the verb (set or get) followed by the members name (see the
test case code).
This code is used:
//prototypes and declarations at the top, comment your code
void taskD() { std::string gameName[] = {"Puzzled Penny", "Reality", "Adventure Aardvark"}; //List of Game Names std::string gameType[] = {"Puzzle", "Simulation", "Adventure"}; //List of Game Types float gamePrice[] = {0, 50, 75}; //List of Game Prices. Inputted zero to show change to 100 float MODIFIER = 1.1; // TO increase Prices by 10%, multiply values by this
//Creation and Initialization of 3 Game objects Games Game_1(gameName[0], gamePrice[0], gameType[0]); Games Game_2(gameName[1], gamePrice[1], gameType[1]); Games Game_3(gameName[2], gamePrice[2], gameType[2]); Games Game_4(200, "Intrigue"); Games Game_5(150); Games Game_6;
//Outputting game data before multiplying the price by the modifier cout << "Game Name: " << Game_1.getName() << endl << "Game Type: " << Game_1.getType() << endl << "Game Cost: " << Game_1.getCost() << endl << endl; cout << "Game Name: " << Game_2.getName() << endl << "Game Type: " << Game_2.getType() << endl << "Game Cost: " << Game_2.getCost() << endl << endl; cout << "Game Name: " << Game_3.getName() << endl << "Game Type: " << Game_3.getType() << endl << "Game Cost: " << Game_3.getCost() << endl << endl; cout << "Game Name: " << Game_4.getName() << endl << "Game Type: " << Game_4.getType() << endl << "Game Cost: " << Game_4.getCost() << endl << endl; cout << "Game Name: " << Game_5.getName() << endl << "Game Type: " << Game_5.getType() << endl << "Game Cost: " << Game_5.getCost() << endl << endl; cout << "Game Name: " << Game_6.getName() << endl << "Game Type: " << Game_6.getType() << endl << "Game Cost: " << Game_6.getCost() << endl << endl;
//Modifying the price and then outputting updated game data cout << "--------------------Games with 10% mark-up below:---------------------------" << endl; Game_1.setCost(Game_1.getCost() * MODIFIER); Game_2.setCost(Game_2.getCost() * MODIFIER); Game_3.setCost(Game_3.getCost() * MODIFIER); Game_4.setCost(Game_4.getCost() * MODIFIER); Game_5.setCost(Game_5.getCost() * MODIFIER); Game_6.setCost(Game_6.getCost() * MODIFIER);
cout << "Game Name: " << Game_1.getName() << endl << "Game Type: " << Game_1.getType() << endl << "Game Cost: " << Game_1.getCost() << endl << endl; cout << "Game Name: " << Game_2.getName() << endl << "Game Type: " << Game_2.getType() << endl << "Game Cost: " << Game_2.getCost() << endl << endl; cout << "Game Name: " << Game_3.getName() << endl << "Game Type: " << Game_3.getType() << endl << "Game Cost: " << Game_3.getCost() << endl << endl; cout << "Game Name: " << Game_4.getName() << endl << "Game Type: " << Game_4.getType() << endl << "Game Cost: " << Game_4.getCost() << endl << endl; cout << "Game Name: " << Game_5.getName() << endl << "Game Type: " << Game_5.getType() << endl << "Game Cost: " << Game_5.getCost() << endl << endl; cout << "Game Name: " << Game_6.getName() << endl << "Game Type: " << Game_6.getType() << endl << "Game Cost: " << Game_6.getCost() << endl << endl;
cout << "end of task D" << endl; cin.get(); }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
