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

***This Question actually has 2 parts, but for this question, i only posted only

ID: 3628988 • Letter: #

Question

***This Question actually has 2 parts, but for this question, i only posted only the first part, that way i can give out more points for the 2nd part of the question. Below is just the explanation of the entire question. (Its long because i tend to explain in detail)

EXPLANATION OF THE WHOLE QUESTION
Design and implement a display of the player ship and the region of space in front of it, the movement of the player ship, and the detection of collisions with a single asteroid. In the game, the user will enter text commands to control the mining ship and print a picture of the player ship and the space in front of it. If the player ship collides with the asteroid, the program prints a message and terminates. The user can also terminate the program with the ‘q’ command at any time. As well, after each move, the displayed region of space in the game will move one column to the right.


##############################################################

# #

# #

# #

# #

# #

# /-- #

# |XX| #

# --/ #

# #

# #

# / #

# >=====| #

# I*--o> #

# >=====| #

# #

# #

# #

# #

# #

# #

##############################################################

To prepare for displaying the player ship and the region of space in front of it, a temporary area of memory, called a buffer, should be used to represent the picture before it is displayed. The buffer is represented by a two-dimensional array of characters. Before drawing each frame, the buffer is initialized to contain all blank (‘ ’) characters. After that, the characters representing the player ship and the asteroid are copied into the buffer. Finally, the buffer is printed on the screen.


(a) Define BUFFER_ROWS and BUFFER_COLUMNS as integer constants with values of 20 and 60 respectively. Define BUFFER_EMPTY and BUFFER_BORDER as character constants with values of ‘ ’ and ‘#’ respectively. Use typedef to define a Buffer type corresponding to a 2-dimensional array of chars with dimensions BUFFER_ROWS and BUFFER_COLUMNS.
--> Suggestion: The functions from part A steps 1-4 will eventually be placed in a file called Buffer.cpp. The constants and type declarations as well as prototypes for the functions will be placed in Buffer.h. You can either put them in these files immediately or keep all your code in one file for now.


(b) Implement a bufferClear function that takes a Buffer as a parameter. This function should set the value of each element in the Buffer to BUFFER_EMPTY.
Implement a bufferPrint function that takes a Buffer as a parameter. This function should print the contents of the Buffer with a border of BUFFER_BORDER characters around it.
--> Hint: start by printing a row of BUFFER_BORDER characters. Then, for each row, print a BUFFER_BORDER character, the row in the Buffer, and another BUFFER_BORDER character. Finally, print another row of BUFFER_BORDER characters.


(c) Implement a bufferSetCell function that takes a Buffer, a char, and two ints, representing a row and column, as parameters. This function should set the element of the Buffer specified by the row and column to the character. If the row and column lie outside the Buffer, there should be no effect.

Explanation / Answer

please rate - thanks

hope this is everything for this phase

#include <iostream>
using namespace std;
#define BUFFER_ROWS 20
#define BUFFER_COLS 60
#define BUFFER_EMPTY ' '
#define BUFFER_BORDER '#'
typedef char buffer[BUFFER_ROWS][BUFFER_COLS];
void bufferclear(buffer);
void bufferprint(buffer);
void buffersetcell(buffer,char,int,int);
int main()
{int i,j;
buffer a;
bufferclear(a);
bufferprint(a);

system("pause");
return 0;  
}
void bufferclear(buffer a)
{int i,j;
for(i=0;i<BUFFER_ROWS;i++)
     for(j=0;j<BUFFER_COLS;j++)
           a[i][j]=BUFFER_EMPTY;
}
void bufferprint(buffer a)
{int i,j;
for(i=0;i<BUFFER_COLS+2;i++)
      cout<<BUFFER_BORDER;
cout<<endl;

for(i=0;i<BUFFER_ROWS;i++)
     {cout<<BUFFER_BORDER;
      for(j=0;j<BUFFER_COLS;j++)
           cout<<a[i][j];
     cout<<BUFFER_BORDER<<endl;
     }
for(i=0;i<BUFFER_COLS+2;i++)
      cout<<BUFFER_BORDER;
cout<<endl;    
}
void buffersetcell(buffer a,char c,int i,int j)
{if(i<BUFFER_ROWS&&j<BUFFER_COLS)
        a[i][j]=c;
}