Well, I'm not sure that those two functions should be combined into one.
write()
seems to be an initialisation which would be performed only at the start of the program, while
display()
could be called several different times.
One thing you could to is with care remove some of the unnecessary lines. Personally I like a to use blank lines to separate blocks of code as it aids legibility, but as an example, this could be made shorter:
1 2 3 4 5 6 7 8 9 10 11
|
void write(char grid [][COL], int rows)
{
for(int x = 0; x<rows; x++)
{
for (int y = 0 ; y < COL; y++)
{
grid[x][y] = '#';
}
}
}
|
like this:
1 2 3 4 5 6
|
void write(char grid [][COL], int rows)
{
for (int x = 0; x<rows; x++)
for (int y = 0; y < COL; y++)
grid[x][y] = '#';
}
|
The other function could be shortened slightly - but I don't think all whitespace should be removed, that would be sacrificing legibility.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
void display(char grid[][COL], int rows)
{
cout << " Seat \n"
" 123456789012345678901234567890" << endl;
for (int x = 0; x<rows; x++)
{
cout << "Row " << left << setw(3) << (x+1);
for (int y = 0; y < COL; y++)
cout << grid[x][y];
cout << endl;
}
}
|
I have no clue what this should teach us what matter if one has 500 or more line of code I thought programming is about getting it runing |
Well, that's an interesting point. In my opinion "getting it running" is the bare minimum requirement. Beyond that, the program should have a clear, well-planned design with a clean, easy to read structure and layout.
Generally the use of separate functions will tend to make the code shorter, as it reduces unnecessary repetition of the same or similar code over and over again.
If your code is significantly longer than expected, perhaps there are some other design issues to be reconsidered. Without seeing more of the code I don't think it's really possible to give more specific advice.