Your task will be to create a simple text-based simulation that inherits from a pre-existing World class. You must use the World.h provided as a starting point for your code. At least one object in your solution should meaningfully inherit from this class. DO NOT MODIFY THE WORLD CLASS in any way. Note that the World class is abstract and there are a few pure virtual functions for you to implement in your object that inherits from the world. Namely, you will need to implement: void PrintGrid() - This function should print the grid (10 by 10 char array) to standard out.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Your task will be to create a simple text-based simulation that inherits from a pre-existing World class.

You must use the World.h provided as a starting point for your code. At least one object in your solution should meaningfully inherit from this class. DO NOT MODIFY THE WORLD CLASS in any way. Note that the World class is abstract and there are a few pure virtual functions for you to implement in your object that inherits from the world. Namely, you will need to implement:

  1. void PrintGrid() - This function should print the grid (10 by 10 char array) to standard out.
  2. void UpdateGrid() - This function should update your characters' positions on the grid
  3. void initGrid() - This function should set your grid up (implement your "starting conditions" here)

The scenarios that you will simulate will be confined to a 10x10 grid (defined in the World class as grid) and be subject to at least 10 distinct rules. In addition, there must be at least 2 different objects or “characters” interacting in your simulation. Each should be defined in their own class. Initially, characters should be spawned in random positions in the grid. Their movement on each day (or round of simulation) should be governed by the rules that you develop. After each day or round of your simulation, an updated grid showing the position of all characters should be printed to the standard output. There should be some clear stopping condition of your simulation. In addition, in at least one of your objects should overload at least two operators in a meaningful way. Ex. You may choose to overload your + operator to determine what will result if two of your characters interact. Your program should not contain any memory leaks. Where appropriate, you should use the const keyword.

Example Scenario:

Life Simulation

Starting Condition: The simulation will start with 10 Humans, age 0 with immunity of 1, (5 female and 5 male) and 1 Virus object randomly placed in the grid. Each round of the program will symbolize a year passed.

Example Rules:

  1. Every year a Human object can make one random move vertically, horizontally or diagonally in the grid.
  2. If two Human objects come in contact with one another then if they are of the opposite gender, are unmarried and over age 18 then they will spawn another Human object somewhere in the grid (gender will be randomly assigned).
  3. Every 10 years another Virus object appears on the grid in a random spot.
  4. If a Human object comes in contact with a Virus object then if their immunity value is greater than 0.25 then a number between 0 and 1 will be randomly calculated and subtracted from the Human’s immunity value.
  5. If a Human object comes in contact with a Virus object then if their immunity value is less than 0.25 then they will disappear from the grid.
  6. If the randomly generated move for any Human is illegal (out of bounds) then no move is made. ...

Stopping Condition: The 10x10 grid has filled up or 1000 years (rounds) have passed.

Checklist (and points)

  • Inherit from the World class provided (5 points)
  • Implement the 3 pure virtual functions in the World class (6 points - 2 points each)
  • Implement 10 distinct rules (30 points - 3 points each)
  • Include at least 2 other objects as "characters" in your sim (10 points - 5 for each class)
  • Make sure that there is an option for printing each iteration of the sim to standard out (5 points)
  • Make sure there is a clear stopping condition (5 points)
  • Overload at least two operators in at least one of your objects (4 points - 2 points each)
  • No memory leaks if you choose to use pointers in any way (-5 points for memory leaks)
  • Where appropriate, use the const keyword. (-1-5 points if missing consts - depends on how many you are missing)

Example of PrintGrid()

void Gameboard::PrintGrid()

{

cout << "World at Day " << day << endl;

cout << " ---+---+---+---+---+---+---+--- " << endl;

for(int i = 0; i < 10; i++) {

cout << "| "

}

for(int j = 0; j < 10; j++) {

cout << grid[i][j] << " | "; }

cout << endl; cout << " ---+---+---+---+---+---+---+--- " << endl;

}

}

#ifndef WORLD_H
  #define WORLD_H
  #include <cstdlib>
   
  class World {
   
  public:
  World() {};
   
  virtual void PrintGrid() = 0;
  virtual void UpdateGrid() = 0;
   
  protected:
  int day;
  char grid[10][10];
   
  virtual void initGrid() = 0;
   
  };
   
  #endif /* WORLD_H */
Expert Solution
steps

Step by step

Solved in 6 steps

Blurred answer
Knowledge Booster
Adjacency Matrix
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education