mardi 14 janvier 2020

how to use 'typedef' function properly?

when i try compiling this part A of my assigment it is not debugging as it should be. so basically it should print a map with dots and border of # around it and yes using type def is compulsary what should i do.

To test the Buffer functions, create a main function. It should first declare a Buffer named my_buffer. Then it should call the bufferClear function with my_buffer as a parameter and then call bufferPrint, also with my_buffer as a parameter. Before continuing, test that this works as expected. Then add a call to bufferSetCell, that says to add the letter ‘A’ to the buffer in row 10, column 5. For example, bufferSetCell(my_buffer, 'A', 10, 5);.

#include<iostream>

using namespace std;



const int BUFFER_ROW_COUNT = 20;

const int  BUFFER_COLUMN_COUNT = 60;

const char BUFFER_EMPTY = '.';

const char  BUFFER_BORDER = '#';

typedef char Buffer[BUFFER_ROW_COUNT][BUFFER_COLUMN_COUNT];

void bufferPrint(const Buffer buff)
{
        for (int i = 0; i < 62; i++)
        {
                cout << BUFFER_BORDER;
        }
        cout << endl;
        for (int i = 0; i < BUFFER_ROW_COUNT; i++)
        {
                cout << BUFFER_BORDER;
                for (int j = 0; j < BUFFER_COLUMN_COUNT; j++)
                {
                        cout << buff[i][j];
                }
                cout << BUFFER_BORDER;
                cout << endl;
        }
        for (int i = 0; i < 62; i++)
        {
                cout << BUFFER_BORDER;
        }

}


void bufferClear(Buffer buff)
{
        for (int i = 0; i < BUFFER_ROW_COUNT; i++)
        {
                for (int j = 0; i < BUFFER_COLUMN_COUNT; j++)
                {
                        buff[i][j] = BUFFER_EMPTY;
                }
        }
}

void bufferSetCell(Buffer buff, int row, int column, char value)
{
        if (row <= BUFFER_ROW_COUNT && column <= BUFFER_COLUMN_COUNT)
        {
                buff[row][column] = value;
        }
}

int main()
{
         Buffer my_buffer;
        bufferClear(my_buffer);
        bufferPrint(my_buffer);
        bufferSetCell(my_buffer, 'A', 10, 5);
        bufferPrint(my_buffer);
        cout << my_buffer;
        return 0;
}

Aucun commentaire:

Enregistrer un commentaire