Having a rough time getting started with the constructors and the display function of this class, any advice/assitance is appreciated!
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
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
Member function descriptions
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.
The header file included is this:
// 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:
int rows, columns, rowmover, columnmover, direction;
char mover, fill;
char grid [40][40];
};import java.util.Scanner;
class scan
{
public static void main(String args[])
{
Scanner sc=new
Scanner(System.in);
System.out.println("Enter your
number");
int a=sc.nextInt();
switch(a)
{
case 1:
int a,b,c;
for(a=1;a<=5;a++)
{
for(b=1;b<=5;b++)
{
if(a==b)
{
System.out.print("$");
}
else
if(a==1 || b==5 || a==5||b==1)
{
System.out.print("*");
}
else
{
System.out.print(" ");
}
}
System.out.println("\n");
}
break;
case 2:
int a,b,c;
for(a=1;a<=5;a++)
{
for(b=1;b<=a;b++)
{
if(a==3)
{
System.out.print("*");
System.out.print("\t");
}
else
{
System.out.print(b);
System.out.print("\t");
}
}
System.out.println("\n");
break;
case 3:
int a,b,c;
for(a=1;a<=5;a++)
{
for(b=1;b<=a;b++)
{
System.out.print(b);
System.out.print("\t");
}
System.out.println("\n");
}
break;
}
}
}
Having a rough time getting started with the constructors and the display function of this class,...
I only need the "functions" NOT the header file nor the main
implementation file JUST the implementations for the
functions
Please help, if its difficult to do the complete program I would
appreciate if you could do as much functions as you can especially
for the derived class.
I am a beginer so I am only using classes and pointers while
implementing everything using simple c++ commands
thank you in advanced
Design and implement two C++ classes to provide matrix...
I need help with the last method listed in the problem: Implement a class Grid that stores measurements in a rectangular grid. The grid has a given number of rows and columns, and a description string can be added for any grid location. Supply the following constructor and methods: public Grid(int numRows, int numColumns) public void add(int row, int column, String description) public String getDescription(int row, int column) public ArrayList getDescribedLocations() Here, Location is an inner class that encapsulates the...
Please help i need a C++ version of this code and keep getting
java versions. Please C++ only
Purpose: This lab will give you experience
harnessing an existing backtracking algorithm for the eight queens
problem, and seeing its results displayed on your console window
(that is, the location of standard output).
Lab
A mostly complete version of the eight queens problem has been
provided for you to download. This version has the class Queens
nearly completed.
You are to provide...
Data Structures and Algorithms C++: I'm having a hard time getting my main.cpp part of the source code (shown below) to output the following: Inserting elements to array list: The list contains 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 Deleting elements: The list contains: 2 4 6 8 10 12 14 16 18 20 22 24 this is a programming problem in...
C++ there is an issue with my if/else statements, I have tried several different ways to make it match the instructions but each time i get different errors. Need help geting this to match the instructions peoperly. *******************instructions***************************** Function: nextGeneration This function has no parameters. This function returns an int. The purpose of this function is to modify the grid to represent the next generation. Here's how you are supposed to do that for this assignment: Set each element of...
The function retrieveAt of the class arrayListType is written as a void function. Rewrite this function so that it is written as a value returning function, returning the required item. If the location of the item to be returned is out of range, use the assert function to terminate the program. note: please give all code in c++ below is the class and implementation(a test program would be helpful in determining how to use it): class arrayListType { public: ...
Please use my code to implement the above instructions.
My Grid class:
import java.util.ArrayList;
import java.util.Collections;
class Grid {
private boolean bombGrid[][];
private int countGrid[][];
private int numRows;
private int numColumns;
private int numBombs;
public Grid() {
this(10, 10, 25);
}
public Grid(int rows, int columns) {
this(rows, columns, 25);
}
public Grid(int rows, int columns, int numBombs) {
this.numRows = rows;
this.numColumns = columns;
this.numBombs = numBombs;
createBombGrid();
createCountGrid();
}
public int getNumRows() {
return numRows;...
in c++
Purpose: This lab will give you experience
harnessing an existing backtracking algorithm for the eight queens
problem, and seeing its results displayed on your console window
(that is, the location of standard output).
Lab
A mostly complete version of the eight queens problem has been
provided for you to download. This version has the class Queens
nearly completed.
You are to provide missing logic for the class Queens that will
enable it to create a two-dimensional array that...
Language is C++ Basic principles and theory of structured programming in C++ by implementing the class: Matrix Use these principles and theory to help build and manipulate instances of the class (objects), call member functions Matrix class implementation from the main function file and, in addition, the Matrix class must have its interface(Matrix.h) in a separate file from its implementation (Matrix.cpp). The code in the following files: matrix.h matrix.cpp matrixDriver.h Please use these file names exactly. Summary Create three files...
Make sure to include: Ship.java, ShipTester.java, Location.java, LocationTester.java, Grid.java, GridTester.java, Player.java, PlayerTester.java, battleship.java. please do every part, and include java doc and comments Create a battleship program. Include Javadoc and comments. Grade 12 level coding style using java only. You will need to create a Ship class, Location class, Grid Class, Add a ship to the Grid, Create the Player class, the Battleship class, Add at least one extension. Make sure to include the testers. Starting code/ sample/methods will be...