Improve the chessboard program

So I have this professor who enjoys giving us assignments that are well out of the experience of everybody in my class. I am only just now reading through our book and another C++ book trying to catch myself up to the level shes teaching at thanks to me having a pretty terrible first professor who spent too much time teaching us his own shell code he made up as opposed to C++ like he was supposed to. Anyway, my assignment is to come up with 3 structural improvements that could be made to this program. And I have to explain why they are improvements. I dont even know where to begin because I couldnt even come up with this source code by myself if she asked me to, let alone tell her how to improve it. Im trying to teach myself the basics from scratch but I have to keep bouncing back and forth between teaching myself the simple stuff and having to do more complicated assignments.

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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87

  //*****************************************************
// Chessboard program
// This program prints a chessboard pattern that is
// built up from basic strings of white and black
// characters.
//*****************************************************
#include <iostream>
#include <string>

using namespace std;

const string BLACK = "********"; // Define black square line
const string WHITE = "        "; // Define white square line
const string BORDER = "________";


int main()
{
    string whiteRow;   // White square beginning row
    string blackRow;   // Black square beginning row
    string borderRow;
    // Create a white-black row
    whiteRow = "|" + WHITE + BLACK + WHITE + BLACK +
               WHITE + BLACK + WHITE + BLACK + "|";
    // Create a black-white row
    blackRow = "|" + BLACK + WHITE + BLACK + WHITE +
               BLACK + WHITE + BLACK + WHITE + "|";

    borderRow = BORDER +BORDER + BORDER + BORDER +
                BORDER + BORDER + BORDER + BORDER;

    cout << " " + borderRow + " " << endl;
  // Print five white-black rows
    cout << whiteRow << endl;
    cout << whiteRow << endl;
    cout << whiteRow << endl;
    cout << whiteRow << endl;
    cout << whiteRow << endl;
  // Print five black-white rows
    cout << blackRow << endl;
    cout << blackRow << endl;
    cout << blackRow << endl;
    cout << blackRow << endl;
    cout << blackRow << endl;
  // Print five white-black rows
    cout << whiteRow << endl;
    cout << whiteRow << endl;
    cout << whiteRow << endl;
    cout << whiteRow << endl;
    cout << whiteRow << endl;
  // Print five black-white rows
    cout << blackRow << endl;
    cout << blackRow << endl;
    cout << blackRow << endl;
    cout << blackRow << endl;
    cout << blackRow << endl;
  // Print five white-black rows
    cout << whiteRow << endl;
    cout << whiteRow << endl;
    cout << whiteRow << endl;
    cout << whiteRow << endl;
    cout << whiteRow << endl;
  // Print five black-white rows
    cout << blackRow << endl;
    cout << blackRow << endl;
    cout << blackRow << endl;
    cout << blackRow << endl;
    cout << blackRow << endl;
  // Print five white-black rows
    cout << whiteRow << endl;
    cout << whiteRow << endl;
    cout << whiteRow << endl;
    cout << whiteRow << endl;
    cout << whiteRow << endl;
  // Print five black-white rows
    cout << blackRow << endl;
    cout << blackRow << endl;
    cout << blackRow << endl;
    cout << blackRow << endl;
    cout << blackRow << endl;

    cout << "|" + borderRow + "|" << endl;

    return 0;
}
Would do you mean by "improve"? giving it graphics or just simply adjust the size of the code?
All she said in the assignment description was to "identify three structural improvements (not comments or formatting) improvements that could be made to the program. Explain why these are improvements. Implement the improvements."

I mean I dont know how to improve a program that already outputs what this does. Because aside from doing that she just wants the pseudocode and full documentation. But as far as "improving" it im at a loss. Im sure there are probably ways to shorten it up but like I said Im only a beginner. I wouldnt know where to begin improving it.
There's tonnes of repetition, try using for loops.
heh, that's not too shabby ;P But yeah, you could lessen the number of cout lines by utilizing loop(s). Could add a new label feature -- labels to the left of the border with numbers 1-8 going upwards, and labels below the board A-H going left to right.

As for a third improvement... perhaps take all the board-drawing logic and move it into its own method? Then call that function from main() -- all these improvements should make main() itself super short (maybe 5 lines).
Topic archived. No new replies allowed.