How to set individual characters in a 2D array

I have this project for school that requires a 2D array of [24] [60] filled with spaces that will be set to characters to draw shapes(square, circle, triangle, and a point). The purpose of the program is to learn inheritance. I have the grid working fine, I just need to figure out this set function to receive the parameters (int ROW, int COL, char c) and set the initial point which will be the upper left corner of the shape. The other classes will draw the rest of the shape, but I'm not even there yet.
grid.cpp
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
26
27
28
29
30
31
32
#include "grid.h"

Grid::Grid()
{
    
	for (int i=0; i<x; i++)
	{
    	for (int j=0; j<y; j++)
    	{
      		cGrid[i][j]=' ';
    	}
    }
}

void Grid::set(int x, int y, char c)
{
	// Takes entered (x,y)
	// If the coordinate is in the grid, set position equal to char c.
	// If the coordinate is outside the grid, do nothing
}

void Grid::print()
{
    for (int i = 0; i < x; i++)
    {
        for (int j = 0; j < y; j++)
        {
            cout << cGrid[i][j];
        }
        cout << endl;
    }
}


grid.h
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
26
27
28
29
#ifndef GRID_H
#define GRID_H
#include <iostream>
#include <vector>
#include <string>
using namespace std;

// int x = 24;
// int y = 60;
// char c;

class Grid
{
	public:
	Grid();
	void set(int x, int y, char c);
	void print();
	const static int x = 24;
	const static int y = 60;
	char c;
	

	private:
	//magic numbers?
	char cGrid [24][60];

	
};
#endif 
Last edited on
Topic archived. No new replies allowed.