Questions
Task You will write a class called Grid, and test it with a couple of programs....

Task

You will write a class called Grid, and test it with a couple of programs. A Grid object will be made up of a grid of positions, numbered with rows and columns. Row and column numbering start at 0, at the top left corner of the grid. A grid object also has a "mover", which can move around to different locations on the grid. Obstacles (which block the mover) and other objects (that can be placed or picked up) are also available. Here is a sample picture of a Grid object in its display format:

0 . . .    This is a Grid object with 4 rows and 4 columns (numbered 0 - 3). 
. . > .    The mover '>' is at row 1, column 2, facing east. 
. . . .    The obstacle '#' is at row 3, column 1 
. # . .    The other item '0' is at row 0, column 0

The @ character indicates that the mover and an item (0) currently occupy the same position on the grid.

Program Details and Requirements

1) Grid class

Download this starter file: grid_starter.h and rename it as grid.h. Your member function prototypes are already given in this file. You will need to add appropriate member data. You will also need to define each of the member functions in the file grid.cpp. You may add whatever member data you need, but you must store the grid itself as a two-dimensional array. Maximum grid size will be 40 rows and 40 columns. (Note that this means dynamic allocation will NOT be needed for this assignment).

Meaning of Grid symbols

.       empty spot on the grid
0       an item that can be placed, or picked up
#       a block (an obstacle).  Mover cannot move through it
<    mover facing WEST
>    mover facing EAST
^       mover facing NORTH
v       mover facing SOUTH
@       mover occupying same place as item (0)

A printed space ' ' in a grid position represents a spot that the mover has already moved through when the path display is toggled on

public Member function descriptions

  • Grid()
    The default constructor should create a 1 x 1 grid, with the mover in the only position, facing EAST
  • Grid(int r, int c)
    The two-parameter constructor will accept two integers, representing rows and columns. Create a grid with r rows and c columns. If either of these is less than 3, default it to 3. If either is greater than the max number of rows or columns, default it to the max number. This grid should be built such that blocks are placed all around the edge, with one random exit (i.e. with no block). The mover should be in a random position and facing a random direction within the grid. When setting up the randomness, make sure each possibility has an equal chance of happening. For example, the random direction has 4 possibilities, so each one should happen about 25% of the time. For the random exit, it will be sufficient to pick a random wall first, then pick a random location on that wall (note that the exit cannot be in a corner spot).

    You'll need the library cstdlib for the srand and rand functions. While it's not normally the best place to do it, you can go ahead and seed the random number generator here in the constructor in some appropriate way so that it's different for seperate program runs.

    If you need a refresher on pseudo-random number generation, see this notes set from COP 3014: http://www.cs.fsu.edu/~myers/c++/notes/rand.html

  • Grid(int r, int c, int mr, int mc, int d)
    This constructor (5 parameters) takes in the following information, in this order:
    • number of starting rows for the grid (if out of range, adjust like in the 2-parameter constructor, although minimum in this case is 1)
    • number of starting columns for the grid (if out of range, adjust like in the 2-parameter constructor, although minimum in this case is 1)
    • The starting row position of the mover (if out of range, adjust to the first or last row, whichever is closer)
    • The starting column position of the mover (if out of range, adjust to the first or last column, whichever is closer)
    • The starting direction of the mover
    Build the starting grid based on the incoming parameters and their descriptions above. Other than the mover, this grid starts out empty.
  • Display()
    This function should print out "The Grid:" on one line, then output the full grid below it -- place spaces between columns so that outputs line up more evenly. End with a newline (so that any next output will be on a separate line). If the path setting is toggled to ON, then any position the mover has already moved through should show up blank. If the path setting is toggled to OFF, then all empty grid spaces show up as dots '.'
    Examples of the full Display format can be seen in the sample run for test1.cpp linked below under "Test Programs".
    For description of the path setting, see the funtion TogglePath() below
  • TogglePath()
    This function, when called, should reverse whatever the current "path" setting is. The path setting can be either ON or OFF. If it's ON, it means that displays of the grid should indicate where the mover has been by showing those positions as spaces. If the path is OFF, then all blank spots on the grid show as the dot character '.' no matter what. The initial default setting for any grid should be ON.
  • Simple Accessors (Getters)
    These are "getter" functions that should return the requested information:
    • GetRow() should return the current row of the mover
    • GetCol() should return the current column of the mover
    • GetNumRows() should return the number of rows in the grid
    • GetNumCols() should return the number of columns in the grid
  • Predicate functions
    These two functions return boolean values (true or false) to answer simple questions:
    • FrontIsClear() should return an indication of whether the space in front of the mover is clear (i.e. not blocked and on the grid)
    • RightIsClear() should return an indication of whether the space to the right of the mover is clear (i.e. not blocked and on the grid)
  • Placing blocks and/or items
    These functions involve placing things on the grid:
    • PutDown(): This function should place an "item" at the current location of the mover. If the location already contains an item, then nothing changes (i.e. the item is still there)
    • PutDown(int r, int c): This function should place an "item" at position (r,c) where r is the row and c is the column. This function should return true for a successful placement, and false for failure. For successful placement, the position has to exist within the grid boundaries and not already contain a block or another item. (It can, however, be placed in a spot where only the mover is located).
    • PlaceBlock(int r, int c): This function should place a "block" at position (r,c) where r is the row and c is the column. This function should return true for a successful placement, and false for failure. For successful placement, the position has to exist within the grid boundaries and be an empty space (i.e. not containing a block, an item, or the mover)
  • PickUp()
    This function should pick up the "item" at the mover's position. This means removing it from the grid. This function should return true for a successful pick-up (i.e. the item is at the mover's current position), and false for failure (there is no item there).
  • Move(int s)
    This function should move the mover forward, in the current direction, for s spaces. Return true for success, false for failure. A successful move must be a positive number of spaces, must remain on the grid, and must not attempt to move through a "block". On a failed move, the mover should remain in the original position. (i.e. the move must be all or nothing, based on the number of spaces given by the parameter).
  • TurnLeft()
    This function will cause the mover to turn 90 degrees to the left, from whichever way it is currently facing. (example: if the mover is facing NORTH, then TurnLeft() will make it face WEST).
  • void Grow(int gr, int gc)
    This function should increase the size of the grid by gr rows and gc columns. If the increase causes either the number of rows or columns to exceed the maximum, simply set that (rows or columns) to the maximum. The grow should not change the current position of any item, mover, or block on the grid.
  • Note that the list of member functions given in the provided starter file (and described above) constitute the entire public interface of the class. These should be the ONLY public member functions in your class. If you create any extra member functions as helpers, put them in the private section of the class

2) Test Program

  1. Trapped!

    Write a main program in a file called trap.cpp that solves the following scenario, using your Grid class:

    Giant Mole People have risen from their underground lairs and are taking over the world. You have been taken prisoner and placed in an underground jail cell. Since the Mole People are blind and don't know how to build doors, your cell has one open exit (no door). Since you are deep underground, it is completely dark and you cannot see. Your task is to escape your prison to join the human resistance!

    Your program should ask the user to input the number of rows, then columns, for the grid. (Note that this is the ONLY keyboard input for this program). Create a grid with the specified number of rows and columns, using the constructor with two parameters -- (this is the one that should automatically create a fenced-in grid containing one exit and a randomly placed mover). Display the initial grid. Since the placement of the exit and the mover is random, execution of this program will look a little different every time. Your task is to escape the trap! You will need to create an algorithm that will instruct the mover to find its way to the exit. (Hint: Think about how to use the Predicate functions before you move). Upon reaching the exit, you should print a message of success, like "We escaped!", and then output the final position of the mover. Keep the path toggled ON. You only need to display the initial setup grid and the final grid for this program.

General Requirements:

  • All class member data (other than the provided static constants) must be private
  • As your only output in the Grid class is the Display function, your output should match mine exactly. (i.e. if I check your output against mine with the "diff" command, there should be no differences in the output of a grid).
  • Adhere to the good programming practices discussed in class. (No global variables, use const in all appropriate places, don't #include .cpp files, document your code. etc).
  • You may use the iostream library, as well as any of the basic C function libraries. You'll probably want to take a look at ctime and cstdlib for setting up random number generation
  • Do not use any C++11 - only features

Submit the following files through the web page in the usual manner:

  grid.h
  grid.cpp
  trap.cpp

// ---------------------------------------

// header file grid.h

// Grid class

class Grid
{
public:
   // public static class constants, for direction indicators
   static const int NORTH = 0;
   static const int WEST = 1;
   static const int SOUTH = 2;
   static const int EAST = 3;

   // public member funcitons

   Grid();                      // build 1 x 1 grid with mover in only
                                //  square, facing east
   Grid(int r, int c);          // build grid with r rows, c cols,
                                //  blocks around edge with random exit
                                //  and random mover position and direction

   Grid(int r, int c, int mr, int mc, int d);
                        // build empty grid with r rows, c cols, and mover
                        //  at row mr, col mc, and facing direction d

   bool Move(int s);            // move forward s spaces, if possible
   void TogglePath();           // toggle whether or not moved path is shown
   void TurnLeft();             // turn the mover to the left
   void PutDown();              // put down an item at the mover's position
   bool PutDown(int r, int c);  // put down an item at (r,c), if possible
   bool PickUp();               // pick up item at current position
   bool PlaceBlock(int r, int c);       // put a block at (r,c), if possible
   void Grow(int gr, int gc);   // grow the grid by gr rows, gc columns


   void Display() const;        // display the grid on screen

   // Accessors
   bool FrontIsClear() const;   // check to see if space in front of 
                                //  mover is clear
   bool RightIsClear() const;   // check to see if space to right of 
                                //  mover is clear
   int GetRow() const;          // return row of the mover
   int GetCol() const;          // return column of the mover
   int GetNumRows() const;      // return number of rows in the grid
   int GetNumCols() const;      // return number of columns in the grid
   
private:

};

In: Computer Science

Artificial Intelligence Question. This topic is about AI representation stochastic methods. I will like it if...

Artificial Intelligence Question. This topic is about AI representation stochastic methods. I will like it if this is good explained and answer

Represent the robot arm problem from earlier sections as a production system. For simplicity use the basic representation that doesn’t care exactly where the blocks are, just if they’re stacked or not. It will only be given four blocks a, b, c, d in some configuration and have to move them until a goal configuration is reached.

In: Computer Science

JAVA CODE BEGINNERS, I already have the demo code included Write a Bottle class. The Bottle...

JAVA CODE BEGINNERS, I already have the demo code included

Write a Bottle class. The Bottle will have one private int that represents the countable value in the Bottle. Please use one of these names: cookies, marbles, M&Ms, pennies, nickels, dimes or pebbles. The class has these 14 methods: read()(please use a while loop to prompt for an acceptable value), set(int), set(Bottle), get(), (returns the value stored in Bottle), add(Bottle), subtract(Bottle), multiply(Bottle), divide(Bottle), add(int), subtract(int), multiply(int), divide(int), equals(Bottle), and toString()(toString() method will be given in class). All add, subtract, multiply and divide methods return a Bottle. This means the demo code b2 = b3.add(b1) brings into the add method a Bottle b1 which is added to b3. Bottle b3 is the this Bottle. The returned bottle is a new bottle containing the sum of b1 and b3. The value of b3 (the this bottle) is not changed. Your Bottle class must guarantee bottles always have a positive value and never exceed a maximum number chosen by you. These numbers are declared as constants of the class. Use the names MIN and MAX. The read() method should guarantee a value that does not violate the MIN or MAX value. Use a while loop in the read method to prompt for a new value if necessary. Each method with a parameter must be examined to determine if the upper or lower bound could be violated. In the case of the add method with a Bottle parameter your code must test for violating the maximum value. It is impossible for this add method to violate the minimum value of zero. The method subtract with a Bottle parameter must test for a violation of the minimum zero value but should not test for exceeding the maximum value. In the case of a parameter that is an integer, all methods must be examined to guarantee a value that does not violate the MIN or MAX values. Consider each method carefully and test only the conditions that could be violated.

import java.util.Scanner;
// test driver for the Bottle class
                public class BottleDemo3
{
        public static void main(String[] args)
        {
                Scanner scan = new Scanner(System.in);
                int x;
                Bottle bottle1 = new Bottle();
                Bottle bottle2 = new Bottle();
                Bottle bottle3 = new Bottle();
                Bottle bottle4 = new Bottle();
                Bottle bottle5 = new Bottle();
                System.out.println("please enter a number for bottle1:");
                bottle1.read();
                System.out.println("Bottle1 is this value " + bottle1 + ".");
                System.out.println("Please enter a number for bottle2:");
                bottle2.read();
                bottle3 = bottle2.add(bottle1);
                System.out.println("The sum of bottle2 and bottle1 is: " + bottle3 + ".");
                bottle4 = bottle3.divide(2);
                System.out.println("The 2 bottle average is: " + bottle4 + ".");
                System.out.print("Subtracting bottle1 from bottle2 is: " );
                bottle3 = bottle2.subtract(bottle1);
                System.out.println( bottle3);
                bottle3 = bottle2.divide(bottle1);
                System.out.println("Dividing bottle2 with bottle1 is: " + bottle3 + ".");
                if (bottle1.equals(bottle2))
                {
                        System.out.println("Bottle1 and bottle2 are equal.");
                }
                else
                {
                        System.out.println("Bottle1 and bottle2 are not equal.");
                }
                System.out.println("Bottle4 is now given the value of 10 with the set() method.");
                bottle4.set(10);
                System.out.println("The value of bottle4 is " + bottle4 + ".");
                System.out.println("Bottle4 is now multipled with bottle1.  The value is placed in " +
                                "bottle5.");
                bottle5 = bottle1.multiply(bottle4);
                System.out.println("The value of bottle5 is " + bottle5 + ".");
                System.out.println("Enter an integer to add to the value bottle1 has.");
                System.out.println("The sum will be put in bottle3.");
                x = scan.nextInt();
                bottle3 = bottle1.add(x);
                System.out.println("Adding your number " + x +
                        " to bottle1 gives a new Bottle with " + bottle3 + " in it.");
                System.out.print("Adding the number " + bottle2 + " which is the number" +
                                " in bottle2 to the\nnumber in ");
                bottle2 = bottle1.add(bottle2);
                System.out.println("bottle1 which is " + bottle1 +" gives " + bottle2 + ".");
                bottle2.set(bottle2.get());
        }
}

In: Computer Science

briefly describe the characteristics of Sermo and Doximity as social media platforms with respect to; platform...

briefly describe the characteristics of Sermo and Doximity as social media platforms with respect to; platform type, user population, scope of medicine and health problems, and member interaction style.

In: Computer Science

C++ Coding Exercise (If... Else) Hello All, I know this question has been asked before, but...

C++ Coding Exercise (If... Else)

Hello All, I know this question has been asked before, but I was unable to run any of the programs that were posted and I'm stuck. I would like to see an explanation with the code and exactly how to add a .txt file to the program through VS 2019, if possible.

LAB:

Write a C++ program that computes a student’s grade for an assignment as a percentage given the student’s score and total points. The final score must be rounded up to the nearest whole value using the ceil function in the header file. You must also display the floating-point result up to 5 decimal places. The input to the program must come from a file containing a single line with the score and total separated by a space.

In addition, you must print to the console “Excellent” if the grade is greater than or equal to 90, “Well Done” if the grade is less than 90 and greater than or equal to 80, “Good” if the grade is less than 80 and greater than or equal to 70, “Need Improvement” if the grade is less than 70 and greater than or equal to 60, and “Fail” if the grade is less than 60.

In: Computer Science

Python Programming This assignment will give you practice with interactive programs, if/else statements, collections, loops and...

Python Programming

This assignment will give you practice with interactive programs, if/else statements, collections, loops and functions.

Problem Description
A small car yard dealing in second hand cars needs an application to keep records of cars in stock. Details of each car shall include registration(rego), model, color, price paid for the car (i.e. purchase price) and selling price. Selling price is calculated as purchased price plus mark-up of 30%. For example, Toyota Corolla bought for $20,000 will have the selling price of 20000 * (1 + 0.3) = 26000.

Task Requirements
Imagine you have been invited to develop a menu driven python application to manage records of cars in stock. Based on the problem description, starter program (code template) has been provided. Investigate the provided starter program. There are four scripts(application.py, caryard.py, cars.py and vehicle.py). Driver function(main) is defined in the appliction.py, which imports caryard module(caryard.py). Caryard declares all the core functions (buy, sell, search, etc. …) for supporting the car yard business. The caryard module imports cars module(cars.py), and the cars module in turn imports the vehicle that include a definition of a Car class.
Program is executed by loading and running the application.py. The important work of interconnecting and wiring of modules and functions have been already been done. However, most of these functions, although declared and wired up in the program are not yet implemented. Your task is to implement these functions. There are eleven (11) tasks to be completed described next within the modules:

1. application.py
• Task 1: implement menu ()


2. caryard.py
• Task 2: implement buy_car ()
• Task 3: implement sell_car ()
• Task 4: implement search_car ()
• Task 5: implement list_all_cars ()


3. cars.py
• Task 6: implement addCar (rego, model, color, price)
• Task 7: implement removeCar (rego)
• Task 8: implement all_cars ()
• Task 9: implement search(rego)


4. vehicle.py
• Task 10: implement the Car class
• Task 11: UML model of a Car class

Description of Program functions:

Program displays a menu on execution. Five menu options are available to allow the user to buy, sell, search, show all cars, and exit program respectively. Program functionality and screen output for each of the menu option when selected by the user follows:

Program menu on execution:



Option 1 (Buy a car): User enters 1. Note the error message for duplicate car rego


Option 2 (Sell a car): User enters 2. Note the error message for invalid car rego, and the sell price which is a (30%) mark-up of purchase price.

Option 3 (Search): User enters 3

Option 4 (Show all): User enters 4

Option 5 (Exit Program): User enters 5

In: Computer Science

Course : Physical Security Submit a paper on the weaknesses of biometric authentication Assignment is worth...

Course : Physical Security

Submit a paper on the weaknesses of biometric authentication

Assignment is worth 50 points and 10% of your grade

  • Submit a paper on the weaknesses of biometric authentication
  • There are numerous examples of weaknesses, write about the ones which interest you the most
  • Do NOT use bullets, that is not APA format!
  • Paper MUST be submitted in APA format
  • Propose a mitigating control or controls to help overcome the weaknesses identified in your paper
  • Submit at least 2 but no more than 4 pages double spaced
  • No photos or graphs
  • Reference all sources used
  • Individual work and NOT a group effort

In: Computer Science

SQL Server 6. Our new system cannot handle Unicode (Links to an external site.) characters, only...

SQL Server

6. Our new system cannot handle Unicode (Links to an external site.) characters, only ASCII (Links to an external site.) characters.
The current Productname data type is NVARCHAR, which is unicode, and might have non-ASCII characters in it. We need to check!
Show the ProductID, and ProductName, and the first location of any non-Unicode characters. See the note at the bottom for how to find non-Unicode characters.

In: Computer Science

When a user program needs the operating system to perform an input operation on its behalf...

When a user program needs the operating system to perform an input operation on its behalf such as reading a fixed number of bytes from a file into a string variable, it needs to issue a system call. Explain the sequence of events that take place when a user program issues a system call, until the time the request from the user program is satisfied, under the assumption that the computer has dual mode operation.

In: Computer Science

Convert a list of decimal numbers into their binary and hexadecimal equivalents Add the elements of...

  1. Convert a list of decimal numbers into their binary and hexadecimal equivalents
  2. Add the elements of each of these lists to generate a total sum
  3. Print the lists, and the total sum of each value

C++ contains some built-in functions (such as itoa and std::hex) which make this assignment trivial. You may NOT use these in your programs. You code must perform the conversion through your own algorithm.

The input values are:


5

9

24

2

39

83

60

8

11

10

6

18

31

27

In: Computer Science

(Minimum 100 words) 1. What are the two different transmission modes? Explain? 2.Define a DC component...

(Minimum 100 words)

1. What are the two different transmission modes? Explain?

2.Define a DC component and its effect on digital transmission.

3. Distinguish between a signal element and a data element

In: Computer Science

Using Python read dataset in the HTML in beautiful way. You need to read CSV file...

Using Python read dataset in the HTML in beautiful way.

You need to read CSV file ( Use any for example, You can use small dataset)
You need to use pandas library
You need to use Flask

Make search table like YouTube has.

In: Computer Science

Shapes2D Write the following four classes to practice using an abstract class and polymorphism. Submit all...

Shapes2D
Write the following four classes to practice using an abstract class and polymorphism. Submit all four classes.

Shape2D class
For this class, include just an abstract method name get2DArea() that returns a double.

Rectangle2D class
Make this class inherit from the Shape2D class. Have it store a length and a width as fields. Provide a constructor that takes two double arguments and uses them to set the fields. Note, the area of a rectangle is the length times the width.

Circle2D class
Also make this class inherit from the Shape2D class. Have it store a radius as a field. Provide a constructor that takes a double argument and uses it to set the field. Note, the area of a circle is PI times it's radius times it's radius.

Shape2DDriver class
Have this class provide a method named displayArea() that takes an object from just any of the above three classes (you can't use an Object type parameter). Have the method display the area of the object, rounded to one decimal place.

Also the code should Enforce an abstract get2DArea() method and the right parameter type for displayArea()

Executes the following code:

Shape2DDriver tester = new Shape2DDriver();

Rectangle2D r = new Rectangle2D( 2, 3 );
Circle2D c = new Circle2D( 4 );

tester.displayArea( r );
tester.displayArea( c );

In: Computer Science

Design and implement a special purpose system that allows access to doors 1 and 2 (D1...

Design and implement a special purpose system that allows access to doors 1 and 2 (D1 and D2 respectively) by persons who have been given a valid four-bit binary code. The code is entered using four switches: S1, S2, S3, and S4. Each valid switch can be set to 0 or 1. The system gives access to doors according to the following scheme:

  1. D1 if 0101 or 1110 is entered.
  2. D1 and D2 if 0111 is entered.
  3. D2 if 0100 is entered.

Provide a truth table and implement your circuit only using NOR gates. The correct implementation of this circuit should only have two layers of NOR gates.

In: Computer Science

Design a kernel module that creates a /proc file named /proc/jiffies that reports the current value...

  • Design a kernel module that creates a /proc file named /proc/jiffies that reports the current value of jiffies when the /proc/jiffies file is read, such as with the command

    cat /proc/jiffies
    Be sure to remove /proc/jiffies when the module is removed.

Please help with this assignment using C programming and testing in Linux Ubuntu.

In: Computer Science