etchasketch

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
/******************************************************************************
* Program:
* Programmer: Christina Backlund
* Date : 
* Purpose:
* notes:
*******************************************************************************/
/*
You MUST submit your work by email to cpolen@shastacollege.edu by the due date. 
Late assignments are NOT accepted after the due date. You may turn in your assignment as early as you would like.

Sometimes, storing an image is easier if you store the steps taken to draw the
image rather than 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:

8  1  2
\ | /
\|/
7-----------3
/|\
/ | \
6  5  4

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 and create a drawing based on the
sequence, using the arrow directions displayed in the first figure. Your program must use the
text screen for the drawing surface and must 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. 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 must move in the direction you would if the value were positive,
but you do not put an asterisk in the position when done moving.
Sequences may be of any length. After inputting the zero value, your program will display the final image. 

To get full credit on this assignment you must use a class and objects for image processing.
You must use an array to store and print the character sequence onto the screen. 
(A 2 dimensional array would be ideal.) Please do as much code as you can in your class and leave main()
as small as possible. You should have a 2 dimensional array inside of your class along with some sort of
int values for the x and y coordinates to keep track of what array elements you are going to store the user inputted image.

Sample Run: 
Enter drawing sequence below.

1 1 1 2 2 4 4 5 5 7 7 7 0

Your picture:

*
* *
*   *
*   *
___________________________________________________________________
It is easier if you have one class, say draw and put the x and y in your draw class.

In your draw class you will have a initialize picture function that sets all array elements of your 
"board grid" (you can't have a space in the name.) to a space ( ' ' ).
You will have another function say printPic that prints all the array elements of your 
"board grid". Lastly at least one more function for getting the users input and processing the picture.
____________________________________________________________________

*/
//______________________________________________________________________________
//-----------------------------headers------------------------------------------
#include<iostream>// for cin and cout msg display.
using namespace std;
//______________________________________________________________________________
//-----------------------------Global Variables---------------------------------
//______________________________________________________________________________
//-----------------------------Classes------------------------------------------
///////////////////////////////////////////////////////////////////////////////
// Class Board for making the two dimensional array to draw in.
//".... 20 characters tall and 70 characters wide."
class draw
{
private:
	int x;
	int y;
	// or would it be char as the array values since '#' is a char not int value?
	int grid[70][20];//creates the board that is 70 x 20; must assign values to the grid. so character pen would move.
public:
	
	draw ()  //constructor (no args)
	{  }
	void printPic();
	void move()
	{      } 
};
//Class Functions
//void draw::print
//void board::printPic()
//{
//}

void print(int grid[][]) 
{ 
	for(x = 0; x < 70; x++) 
	{ 
		for(y = 0; y < 20; y++) 
			cout << " " << grid[x][y];
		cout << endl; 
	} 
}

// need to set starting point at bottom/left corner of screen.
//code for out of bounds movement.


///////////////////////////////////////////////////////////////////////////////
//______________________________________________________________________________
//----------------------------Functions----------------------------------------

/******************************************************************************
Function main()
parameters: n/a (null)
purpose: to start the program and call classes and class functions.
must be as small as it can be.
******************************************************************************/
int main()
{
	cout<<"main()"<<endl;
	cout<<":Image Processing with ASCII Character '#':\nDirection values:"<<endl;
	cout<<"   8  1  2"<<endl;
	cout<<"    \\ | /"<<endl;
	cout<<"     \\|/"<<endl;
	cout<<"7-----------3"<<endl;
	cout<<"     /|\\"<<endl;
	cout<<"    / | \\"<<endl;
	cout<<"   6  5  4"<<endl;
	draw::printPic();

	// create a board to draw in 
	// have user input direction to draw to
	// have code that loops through the user's string of numbers to draw ACSII Characters
	//chosen character is '#' because it fills more of the box space in the array


	system("pause");
	return 0;
}




/******************************************************************************
Function:
parameters:
purpose: 
******************************************************************************/
//______________________________________________________________________________ 


how do I get it to draw a table array to the screen
I am making a etchasketch program
that the user has to input a string of numbers.
Table array? What do you mean?

If you mean a 2D array, then you have a function for that in your class.

-Albatross
Last edited on
yeah a 2d array
that is going to the basis"paper" for the etchasketch program
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
/******************************************************************************
* Program:
* Programmer: Christina Backlund
* Date : 
* Purpose:
* notes:
*******************************************************************************/
/*
You MUST submit your work by email to cpolen@shastacollege.edu by the due date. 
Late assignments are NOT accepted after the due date. You may turn in your assignment as early as you would like.

Sometimes, storing an image is easier if you store the steps taken to draw the
image rather than 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:

8  1  2
\ | /
\|/
7-----------3
/|\
/ | \
6  5  4

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 and create a drawing based on the
sequence, using the arrow directions displayed in the first figure. Your program must use the
text screen for the drawing surface and must 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. 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 must move in the direction you would if the value were positive,
but you do not put an asterisk in the position when done moving.
Sequences may be of any length. After inputting the zero value, your program will display the final image. 

To get full credit on this assignment you must use a class and objects for image processing.
You must use an array to store and print the character sequence onto the screen. 
(A 2 dimensional array would be ideal.) Please do as much code as you can in your class and leave main()
as small as possible. You should have a 2 dimensional array inside of your class along with some sort of
int values for the x and y coordinates to keep track of what array elements you are going to store the user inputted image.

Sample Run: 
Enter drawing sequence below.

1 1 1 2 2 4 4 5 5 7 7 7 0

Your picture:

*
* *
*   *
*   *
___________________________________________________________________
It is easier if you have one class, say draw and put the x and y in your draw class.

In your draw class you will have a initialize picture function that sets all array elements of your 
"board grid" (you can't have a space in the name.) to a space ( ' ' ).
You will have another function say printPic that prints all the array elements of your 
"board grid". Lastly at least one more function for getting the users input and processing the picture.
____________________________________________________________________

*/
//______________________________________________________________________________
//-----------------------------headers------------------------------------------
#include<iostream>// for cin and cout msg display.
using namespace std;
//______________________________________________________________________________
//-----------------------------Global Variables---------------------------------
//______________________________________________________________________________
//-----------------------------Classes------------------------------------------
///////////////////////////////////////////////////////////////////////////////
// Class Board for making the two dimensional array to draw in.
//".... 20 characters tall and 70 characters wide."
class draw
{
private:
	int x;
	int y;
	// or would it be char as the array values since '#' is a char not int value?

public:
	int i,j;
	int grid[70][20];//creates the board that is 70 x 20; must assign values to the grid. so character pen would move.
	draw ()  //constructor (no args)
	{  }
	void printPic(int grid[][20]);
	void read(int grid[][20]);
	void move()
	{      } 
};
//Class Functions
//void draw::print
//void board::printPic()
//{
//}
void draw::read(int grid[][20])
{
	cout <<"read";
	for(i = 0; i < 70; i++)
	{
		cout <<"row " << i << ": ";
		for(j = 0; j < 20; j++)
		{
			cin >> grid[i][j];
		}
	}
}


void draw::printPic(int grid[][20]) 
{ 

	for(i = 0; i < 70; i++) 
	{ 
		for(j = 0; j < 20; j++) 
			cout << " " << grid[i][j];
		cout << endl; 
	} 
}

// need to set starting point at bottom/left corner of screen.
//code for out of bounds movement.


///////////////////////////////////////////////////////////////////////////////
//______________________________________________________________________________
//----------------------------Functions----------------------------------------

/******************************************************************************
Function main()
parameters: n/a (null)
purpose: to start the program and call classes and class functions.
must be as small as it can be.
******************************************************************************/
int main()
{
	cout<<"main()"<<endl;
	cout<<":Image Processing with ASCII Character '#':\nDirection values:"<<endl;
	cout<<"   8  1  2"<<endl;
	cout<<"    \\ | /"<<endl;
	cout<<"     \\|/"<<endl;
	cout<<"7-----------3"<<endl;
	cout<<"     /|\\"<<endl;
	cout<<"    / | \\"<<endl;
	cout<<"   6  5  4"<<endl;
	draw board; // creates the game()
	board.read(); 
	board.printPic();

	// create a board to draw in 
	// have user input direction to draw to
	// have code that loops through the user's string of numbers to draw ACSII Characters
	//chosen character is '#' because it fills more of the box space in the array


	system("pause");
	return 0;
}




/******************************************************************************
Function:
parameters:
purpose: 
******************************************************************************/
//______________________________________________________________________________ 

Topic archived. No new replies allowed.