Following is my Project 2. In Project 1, I wrote a program to draw square, rectangle and triangle and this is its second part.

I could not figure it out how to do it. Any guidelines and suggestions would be highly appreciated.

Project 2:
Our customer was pleased with the program you created for Project 1. (Go review Project 1 if you don't remember the details.) After using it, she came up with some new features for Version 2.0. As before, you're going to have to handle the technical details. The big difference is that the program should be able to draw as many shapes as the user wants, possibly overlapping, all at one time. This means the program could draw something like this:

******* **
******* ********
********** ********
****** * **
**********
*****

This is a lot more complicated! To start with, instead of sending chars directly to the screen for each shape, they should instead be stored in a char array of 60 columns and 20 rows. The array can then be sent to the screen one row at a time either when requested by the user, or perhaps after every shape is added.

Since we now have a more powerful tool called a "class", we're going to want to use it. Think about all the nouns that represent the concepts in the CUSTOMER's world: square, triangle, etc. These will be your classes. Then for each noun, think about the verbs the CUSTOMER would use with that noun, such as Draw and Erase. These will be your class methods. Besides a width and height, you'll now also need a location for each shape. The location is the row and column of the upper left corner of the shape within the drawing array. Perhaps other things besides the shapes can be represented using classes.

Caution: when drawing the shapes into the array, be sure not to draw beyond the array bounds!

You might want to use a class to manage the array that holds the drawing characters. Such a class might be defined something like this:

class Screen
{
static const int WIDTH = 60;
static const int HEIGHT = 20;
char frameBuffer[HEIGHT][WIDTH];

public:
Screen() { }
void SetPixel(int x, int y, char c); // place c in the frame buffer at location x,y
bool IsInBounds(int x, int y); // called from SetPixel to see if x,y is a legal location
void Display(); // copy the entire frame buffer to the screen
};

1 answer

@MathMate