Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

c++ program Problem Statement: The scenes in the Asn2 Scenes link on the Web Pag

ID: 3903666 • Letter: C

Question

c++ program

Problem Statement: The scenes in the Asn2 Scenes link on the Web Page represents an island (yellow squares) surrounded by water (blue squares). There is a cat on the island (brown square) and a bridge leading to safety (black square). A (drunken) mouse is placed in the center of the island. Initialized Scene Lucky Mouse Escaping Water Water Mouse Bridge Bridge Cat Cat sland Island Prof Amr Goneid AUC Prof Amr Goneid AUC A Mouse Drownin A Mouse encounters Cat Water Water Bridge Bridge Cat Cat Island Island Prof. Amr Goneid, AUC Prof. Amr Goneid,AUC Write a program to make the mouse move randomly across the island. The mouse is allowed to move one square at a time, either horizontally or vertically (no diagonal moves). A random number between 0 and 3 inclusive is used to define the direction of the next move (0 for North, 1 for East, 2 for South and 3 for West). The mouse drowns if it hits water, dies of starvation if it makes more than 100 moves, gets eaten if it meets the cat, or hopefully it crosses the bridge. The program should be run from the start several times to count the number of times the mouse drowns, escapes or dies

Explanation / Answer

#include<iostream>
#include<stdlib.h>
#include<time.h>

using namespace std;

int main(){
  
   int island[100][100];
   int catx;
   int caty;
   int mousex;
   int mousey;
   int bridgex;
   int bridgey;

   srand(time(NULL));
   int eatenbycat = 0;
   int drown = 0;
   int starvation = 0;
   int crossbridge = 0;
   int move = 0;

   
   cout << "Enter number of simulation:";
   int n;
   cin >> n;
   while(n > 0){
         catx = rand() % 100;
         caty = rand()% 100;
         mousex = rand() % 100;
         mousey = rand() % 100;
         bridgex = rand() % 100;
         bridgey = rand() % 100;
         while(true){
             int a = rand() % 4;
              if (a == 0){
                  mousex--;
              }
              if (a == 1){
                  mousey--;
              }
              if (a == 2){
                  mousey++;
              }
              if (a == 3){
                  mousex++;
              }
              if (mousex < 0 || mousey < 0 || mousex >= 100 || mousey >=0){
                  drown++;
                  break;
              }
              if (mousex == catx && mousey == caty){
                  eatenbycat++;
                  break;
              }
              if (mousex == bridgex && mousey == bridgey){
                  crossbridge++;
                  break;
              }
              move++;
              if (move > 100){
                 starvation++;
                 break;
              }
         }
         n--;      
   }
   cout << "Total Simulation:" << n << endl;
   cout << "Starvation:" << starvation << endl;
   cout << "eatenbycat:" << eatenbycat << endl;
   cout << "crossbridge:" << crossbridge << endl;
   cout << "drown:" << drown << endl;

   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote