I am stumped. I cannot get the image to display at all. I am suppose to interface with the class Draw, but I cannot change anything in it. So I had to make a class that inherited public from the draw class. From what I can see on my code, it should work out fine, I have the changes in xpos and ypos, along with having it place a '*' on the grid where it needs to. I'm pretty sure it has something to do with setup_screen(), process_picture(), and display_picture. However, I am not sure. I really need help with this. The instructions for the code are listed below along with the code I have so far. Please and thank you!
Btw, I've googled so many things related to this project, many of which are about OpenGL and vectors and such. I've tried 2d grids, arrays, and many other types of searches all to no avail.
Instructions:
Sometimes, storing an image is easier if you store the steps taken to draw the image rather than storing the image itself. In such a situation, a sequence of directed lines are concatenated, or attached to one another, to form the image. For example, a simple drawing program might allow eight simple directions of movement:
For this example, a “picture” composed of the sequence “1, 3, 4, 3” would draw a line segment up, to the right, down on an angle, then right again.
Develop a program to take an encoding sequence of numbers from the user and then create a drawing based on the sequence, using the arrow directions displayed in the first figure. Your program should use the console screen for the drawing surface and should allow for a figure up to 20 characters tall and 70 characters wide. Your drawings on this grid should be made with the asterisk (*) character or you can allow the user to enter a character. Each drawing must start in the lower-left corner and if a command would have the figure move “off the page,” the program must ignore that command and proceed on to the next command in the sequence.
Each encoded sequence entered will be a list of numbers, positive and/or negative, ending with a 0 as the indicator that the drawing is finished. If the number is negative, you should move in the direction you would if the value were positive, but you do not put an asterisk or user defined symbol in the position when done moving. Sequences may be of any length. After inputting the zero value, your program will display the final image.
Inherit from the supplied Draw class that I will provide to you. Add the necessary code in your inherited class but be sure to reuse as much code from my class as possible. Do not change or modify the class code that I provided to you. (You can add comments though.)
Get the source code to get you started on the final project from our class website. I will be in lab during finals week on Wednesday, May 21st from 5:30pm to 7:30pm if you need any last minute help on this project.
Sample Output:
Enter drawing sequence below.
1 1 1 2 2 4 4 5 5 7 7 7 0
Your picture:
1 2 3 4 5
|
*
* *
* *
* *
*****
|
My code so far:
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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
|
/*******************************************************************************
* Program Name:
* Created Date:
* Created By:
* Purpose:
*******************************************************************************/
#include <iostream>
#include <stdlib.h>
#include <string>
using namespace std;
//You can modify these numbers but don't delete these constants or this starting code will not work
const int YMAX = 20; // Array bound for screen height
const int XMAX = 70; // Array bound for screen length
// DO NOT ALTER OR DELETE THIS CODE (START)!!!!!!!!!!!!!!!!!!!!!!!!!!!
/********************************************************************
* Class: Draw
* Purpose: To process a list of numbers to draw a picture on the console.
********************************************************************/
class Draw {
protected:
char display[XMAX][YMAX]; // 20 by 70 character array to hold the picture
int input, xpos, ypos;
public:
// Constructor to initialize object member data
Draw() : input(0), xpos(0), ypos(YMAX - 1)
{ }
void greeting(); // Greeting screen to let the user know what this program is and to instruct the user on how to use the program
void setup_screen(); // Setup the array
void process_picture(); // Process the user provided string and store into the array
void display_picture(); // Print the picture onto the screen
};
void Draw::greeting() {
cout << "Welcome to the picture string generator!" << endl
<< "Please enter a string of numbers representing " << endl
<< "a picture that you would like to display." << endl
<< "Numbers print as the following:" << endl << endl
<< "8 1 2" << endl
<< " \\ | /" << endl
<< "7 --+-- 3" << endl
<< " / | \\" << endl
<< "6 5 4" << endl << endl
<< "Positive numbers will draw an *." << endl
<< "A negative number will move the cursor but not draw a *." << endl;
}
void Draw::setup_screen() {
}
void Draw::process_picture() {
}
void Draw::display_picture() {
}
// DO NOT ALTER OR DELETE THIS CODE (END)!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//You can modify and change main()
class Inherit : public Draw
{
public:
Draw image;
void userinput()
{
cout << "\n\nEnter drawing sequence below. Add spaces between digits.\n\n";
do
{
cin >> input;
//POSITIVE
if (input == 1) //UP
{
if (ypos - 1 > 0) //Make sure the user is in bounds
{
ypos--;
display[xpos][ypos] = '*';
image.process_picture();
}
}
if (input == 2) //UP - RIGHT
{
if (xpos < XMAX && ypos - 1 > 0 ) //Make sure the user is in bounds
{
xpos++, ypos--;
display[xpos][ypos] = '*';
image.process_picture();
}
}
if (input == 3) //RIGHT
{
if (xpos < XMAX) //Make sure the user is in bounds
{
xpos++;
display[xpos][ypos] = '*';
}
}
if (input == 4) //DOWN - RIGHT
{
if (xpos < XMAX && ypos -1 < YMAX) //Make sure the user is in bounds
{
xpos++, ypos++;
display[xpos][ypos] = '*';
}
}
if (input == 5) //DOWN
{
if (ypos - 1 < YMAX) //Make sure the user is in bounds
{
ypos++;
display[xpos][ypos] = '*';
}
}
if (input == 6) //DOWN - LEFT
{
if (xpos > 0 && ypos - 1 < YMAX) //Make sure the user is in bounds
{
xpos--, ypos++;
display[xpos][ypos] = '*';
}
}
if (input == 7) //LEFT
{
if (xpos > 0) //Make sure the user is in bounds
{
xpos--;
display[xpos][ypos] = '*';
}
}
if (input == 8) //UP - LEFT
{
if (xpos > 0 && ypos - 1 > 0) //Make sure the user is in bounds
{
xpos--, ypos--;
display[xpos][ypos] = '*';
}
}
//NEGATIVE
if (input == -1) //UP
{
if (ypos - 1 > 0) //Make sure the user is in bounds
{
ypos--;
}
}
if (input == -2) //UP - RIGHT
{
if (xpos < XMAX && ypos - 1 > 0) //Make sure the user is in bounds
{
xpos++, ypos--;
}
}
if (input == -3) //RIGHT
{
if (xpos < XMAX) //Make sure the user is in bounds
{
xpos++;
}
}
if (input == -4) //DOWN - RIGHT
{
if (xpos < XMAX && ypos - 1 < YMAX) //Make sure the user is in bounds
{
xpos++, ypos++;
}
}
if (input == -5) //DOWN
{
if (ypos - 1 < YMAX) //Make sure the user is in bounds
{
ypos++;
}
}
if (input == -6) //DOWN - LEFT
{
if (xpos > 0 && ypos - 1 < YMAX) //Make sure the user is in bounds
{
xpos--, ypos++;
}
}
if (input == -7) //LEFT
{
if (xpos > 0) //Make sure the user is in bounds
{
xpos--;
}
}
if (input == -8) //UP - LEFT
{
if (xpos > 0 && ypos - 1 > 0) //Make sure the user is in bounds
{
xpos--, ypos--;
}
}
}
while (input != 0);
image.process_picture();
}
};
int main()
{
Draw image;
image.greeting();
image.setup_screen();
Inherit data;
data.userinput();
/*system("cls");*/
cout << "Your picture: \n\n";
image.display_picture();
system("pause");
return 0;
}
|