Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Implement the empty functions marked with ///Fill This Function comments. You will need understand the purpose of these functions in order to implement them. Do
Implement the empty functions marked with ///Fill This Function comments. You will need understand the purpose of these functions in order to implement them. Do this by looking where the functions are being called and how the functions are being used in the program. Also, there may be other functions that perform similar task; these functions may give you a clue how to implement the empty functions. #include #include // For time() #include // For srand() and rand() #include // std::flush #include #include #include using namespace std; //generates random numbers 0 or 1 int coinToss() { return rand() % 2; } //generates random coordinates for the grid int randCoord(int ceiling, int floor) { return floor + rand() % (( ceiling + 1 ) - floor); } //initializes the grid 2D array void GridInit(char grid[25][25]) { for(int i=0; i0) //if distance is positive, move up return 'w'; else return 's'; //otherwise move down } else { if(h_distance>0) return 'a'; else return 'd'; } } //checks if coordinates are invalid or not bool InvalidPos(int x, int y){ if(x ==-1 || y ==-1) return true; else return false; } //checks if capture occurs //If rabbit is on an square next to the fox, or they are in the same square, capture happens bool Capture(int x, int y, char grid[25][25]){ if(grid[x][y] == 'X' || grid[x+1][y] == 'X' || grid[x-1][y] == 'X' || grid[x][y+1] == 'X' || grid[x][y-1] == 'X') return true; else return false; } void UpdateGrid(int rabbitsX[],int rabbitsY[], int foxesX[], int foxesY[], char grid[25][25], int &score, int numRabbits, int numFoxes) { //reset graphics for foxes for(int j=0; jrabbitsX[i]; myfile>>rabbitsY[i]; } myfile.close(); } else cout//FILL THIS FUNCTION } void MoveRabbits(int rabbitsX[],int rabbitsY[], bool stationary, int numRabbits) { //iterate through all rabbits for(int i=0; i//FILL THIS FUNCTION } //This function is activated when a best score has been beaten // it promptes the user for an alias //and prints the alias along with score on the 'leaderboard.txt' file void SaveScore(int score, bool RandMove, bool stationary) { string alias; ofstream outfile; outfile.open("leaderboard.txt"); if(stationary == true) outfile Objectives: This assignment will give you an opportunity to explore the process of dividing a C++ program into modules and using the project support components of a C++ IDE to manage your modules. General Instructions: Read the problem description below and reorganize this program in C++. The files for this assignment are provided under the folder for this assignment. You will be submitting two separate projects. See Part A and Part B for details. O All of the functions making up this program are complete and in working order except for functions marked with "/// FILL THIS FUNCTION". You will need to implement these functions. The major challenge in this assignment is to divide the program into separately compiled modules. 0 You have just earned an internship position at a company developing simulations. You and a team of interns have been tasked with updating a prototype simulation program. The simulation involves five foxes and fifteen rabbits that roam around the grid. If a fox is next to a rabbit, the rabbit is captured and removed from the grid. In the visualization of the grid, the foxes are marked with an 'X' while rabbits are marked with an 'o'. You have been given unfinished code that includes all functionality within a single file (main.cpp), and severely hinders development as it prevents multiple interns from contributing at the same time. Thus, you have been asked to split the program into four separate modules: The Grid module must contain the files Gridh and Grid.cpp. It deals with code related to printing, updating, and querying characteristics related to grid positions. The Foxes module must contain the files Foxesh and Foxes.cpp. It mainly deals with the foxes' movement. The Rabbits module must contain the files Rabbith and Rabbit.cpp. It mainly deals with the rabbits movements. The Util module must contain the files Util.h and Util.cpp. It includes functions utilized by both the Rabbits and Foxes modules. Capturing A fox can capture a rabbit, if the rabbit is directly above, below, left, right, or in the same square with the fox. This is illustrated in the figure below which shows rabbits that can be captured. RF Random Movement While foxes have already included functionality to chase the rabbits, there is an additional mode for completely random movement that will be used as a base case to evaluate the chase algorithm. In this mode, a fox will move at a random direction based on a random number generator, without taking into consideration whether a rabbit is in the vicinity. Simulation Modes 1. Positions from file In this mode, the rabbits' and foxes' coordinates will be loaded from the files rabbits.txt and foxes.txt. 2. Random Positions In this mode, the coordinates of the foxes and the rabbits will be randomly generated. 3. Stationary Rabbits In this mode, the rabbits will not roam around the grid, but will instead remain in their initial position. 4. Moving Rabbits In this mode, the rabbits move randomly 5. Random Fox Movement In this mode, the foxes move randomly. 6. Chase Fox Movement In this mode, the foxes move based on a simple chase algorithm, based on which, the fox moves towards the direction of the closest rabbit. Part A: Create a project containing the file 'main.cpp'. Implement the empty functions marked with "///Fill This Function comments. You will need understand the purpose of these functions in order to implement them. Do this by looking where the functions are being called and how the functions are being used in the program. Also, there may be other functions that perform similar task; these functions may give you a clue how to implement the empty functions. Part B: Create a project containing the files 'main.cpp', 'Rabbits.cpp', 'Babbits.b', 'Foxes.cpp', 'Foxes.h', 'Grid.cpp', 'Grid.b', 'Util.cpp', 'Util.h'. Split the functions from Part A into the appropriate modules as outlined in the general instructions. The program should compile and have the same input and output as Part A. In order to determine where a function belongs, look to see what functions it calls, and which functions it is called by. Functions which rely heavily on each other are good candidates for a module. Main Menu Launch Import Positions from file Random Positions Stationary Rabbits Moving Rabbits Random Fox Movement Chase Fox Movement - -- --- -- --- -- --- - -- --- Stationary Rabbits : 1 Random Fox Movement : 1 Random Positions : 1 ERMO -- -- Enter Action: Random Positions File Positions Score:5 Turns:9 score:1 Turns: Main Menu (1) Launch Import Positions from file (2) Random Positions (3) Stationary Rabbits (4) Moving Rabbits Random Fox Movement (6) Chase Fox Movement (7) (5) --------- ------ Stationary Rabbits : 1 Random Fox Movement : 1 Random Positions :1 Enter Action: Objectives: This assignment will give you an opportunity to explore the process of dividing a C++ program into modules and using the project support components of a C++ IDE to manage your modules. General Instructions: Read the problem description below and reorganize this program in C++. The files for this assignment are provided under the folder for this assignment. You will be submitting two separate projects. See Part A and Part B for details. O All of the functions making up this program are complete and in working order except for functions marked with "/// FILL THIS FUNCTION". You will need to implement these functions. The major challenge in this assignment is to divide the program into separately compiled modules. 0 You have just earned an internship position at a company developing simulations. You and a team of interns have been tasked with updating a prototype simulation program. The simulation involves five foxes and fifteen rabbits that roam around the grid. If a fox is next to a rabbit, the rabbit is captured and removed from the grid. In the visualization of the grid, the foxes are marked with an 'X' while rabbits are marked with an 'o'. You have been given unfinished code that includes all functionality within a single file (main.cpp), and severely hinders development as it prevents multiple interns from contributing at the same time. Thus, you have been asked to split the program into four separate modules: The Grid module must contain the files Gridh and Grid.cpp. It deals with code related to printing, updating, and querying characteristics related to grid positions. The Foxes module must contain the files Foxesh and Foxes.cpp. It mainly deals with the foxes' movement. The Rabbits module must contain the files Rabbith and Rabbit.cpp. It mainly deals with the rabbits movements. The Util module must contain the files Util.h and Util.cpp. It includes functions utilized by both the Rabbits and Foxes modules. Capturing A fox can capture a rabbit, if the rabbit is directly above, below, left, right, or in the same square with the fox. This is illustrated in the figure below which shows rabbits that can be captured. RF Random Movement While foxes have already included functionality to chase the rabbits, there is an additional mode for completely random movement that will be used as a base case to evaluate the chase algorithm. In this mode, a fox will move at a random direction based on a random number generator, without taking into consideration whether a rabbit is in the vicinity. Simulation Modes 1. Positions from file In this mode, the rabbits' and foxes' coordinates will be loaded from the files rabbits.txt and foxes.txt. 2. Random Positions In this mode, the coordinates of the foxes and the rabbits will be randomly generated. 3. Stationary Rabbits In this mode, the rabbits will not roam around the grid, but will instead remain in their initial position. 4. Moving Rabbits In this mode, the rabbits move randomly 5. Random Fox Movement In this mode, the foxes move randomly. 6. Chase Fox Movement In this mode, the foxes move based on a simple chase algorithm, based on which, the fox moves towards the direction of the closest rabbit. Part A: Create a project containing the file 'main.cpp'. Implement the empty functions marked with "///Fill This Function comments. You will need understand the purpose of these functions in order to implement them. Do this by looking where the functions are being called and how the functions are being used in the program. Also, there may be other functions that perform similar task; these functions may give you a clue how to implement the empty functions. Part B: Create a project containing the files 'main.cpp', 'Rabbits.cpp', 'Babbits.b', 'Foxes.cpp', 'Foxes.h', 'Grid.cpp', 'Grid.b', 'Util.cpp', 'Util.h'. Split the functions from Part A into the appropriate modules as outlined in the general instructions. The program should compile and have the same input and output as Part A. In order to determine where a function belongs, look to see what functions it calls, and which functions it is called by. Functions which rely heavily on each other are good candidates for a module. Main Menu Launch Import Positions from file Random Positions Stationary Rabbits Moving Rabbits Random Fox Movement Chase Fox Movement - -- --- -- --- -- --- - -- --- Stationary Rabbits : 1 Random Fox Movement : 1 Random Positions : 1 ERMO -- -- Enter Action: Random Positions File Positions Score:5 Turns:9 score:1 Turns: Main Menu (1) Launch Import Positions from file (2) Random Positions (3) Stationary Rabbits (4) Moving Rabbits Random Fox Movement (6) Chase Fox Movement (7) (5) --------- ------ Stationary Rabbits : 1 Random Fox Movement : 1 Random Positions :1 Enter Action
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started