Midterm: Question 1 (35%) (30 minutes) Write an assembly program to draw a rectangle. (5%) Show a...

3
Midterm: Question 1 (35%) (30 minutes) Write an assembly program to draw a rectangle. (5%) Show a message to ask for information of the rectangle (5%) Read the width, height and coordinates of the upper left corner of the rectangle. (5%) Draw the boundary (width = 1) of the rectangle with green color. (5%) Fill the center with yellow color. (5%) Press ‘q’ to quit the program and clear the screen. (5%) Show your student ID at the end of the program. (5%) Explain how you implement the program. – Example: Enter the information of the rectangle Width : 7 Height : 5 Upper left corner X coordinate: 5 Upper left corner Y coordinate: 10 (0, 0) X Y

description

Midterm: Question 3 (30%) Estimated time: One hour Write a program to move two characters horizontally. The screen dimension is 80x24 (width x height). The colors of the two characters are red and green, respectively. Initially: – (2%) the two characters are at (39, 12) and (38, 12). – (5%) the red character moves to the left side. – (2%) the green character moves to the right side. - (5%) If they hit the boundary of the window, reverse their movement direction. - (5%) If they hit each other, reverse their movement direction. The movement of each character has a delay. - (5%) Can be continue. - (2%) Press key ‘q’ to quit the program at any time and clear the screen. - (2%) Show your student ID at the end of the program. -(2%) Explain how you implement the program. Example: Enter the movement delay of the red character (ms): 500 Enter the movement delay of the green character (ms): 250 Snapshots direction

Transcript of Midterm: Question 1 (35%) (30 minutes) Write an assembly program to draw a rectangle. (5%) Show a...

Page 1: Midterm: Question 1 (35%) (30 minutes) Write an assembly program to draw a rectangle.  (5%) Show a message to ask for information of the rectangle  (5%)

Midterm: Question 1 (35%)• (30 minutes) Write an assembly program to draw a rectangle.

– (5%) Show a message to ask for information of the rectangle– (5%) Read the width, height and coordinates of the upper left corner of the

rectangle.– (5%) Draw the boundary (width = 1) of the rectangle with green color.– (5%) Fill the center with yellow color.– (5%) Press ‘q’ to quit the program and clear the screen.– (5%) Show your student ID at the end of the program.– (5%) Explain how you implement the program.

– Example:Enter the information of the rectangleWidth : 7Height : 5Upper left corner X coordinate: 5Upper left corner Y coordinate: 10

(0, 0) X

Y

Page 2: Midterm: Question 1 (35%) (30 minutes) Write an assembly program to draw a rectangle.  (5%) Show a message to ask for information of the rectangle  (5%)

Midterm: Question 2 (35%)• (1.5 hours) The following is a program “P” written in C++. Assume no overflow.• Write an assembly to perform what “P” does.

• (20%) void main () {unsigned int a[100]; int n;cout << “Please enter a number:” << endl;cin >> n; //ask for inputfor ( int i = 0; i < n; ++i ) {

a[i] = rand() % n; // random generator cout << “a[i]:” << a[i] << endl;sum = evaluate( a[i] ) ;cout << “The result is:” << sum << endl;

}for ( int i = 0; i < n; ++i ) cout << a[i] << “ “ << endl;

}

int evaluate( unsigned int m ) {If ( m ==0 ) return m;else return m*computeSum(m-1);

}

int computeSum ( unsigned int m ) {If ( m ==0 ) return m+1;else return m*m+computeSum( m-1 );

}

Please enter a number:3a[0]: 1The result is: 1a[1]: 0The result is: 0a[2]: 2The result is: 41 0 2

(10%) (5%)

Page 3: Midterm: Question 1 (35%) (30 minutes) Write an assembly program to draw a rectangle.  (5%) Show a message to ask for information of the rectangle  (5%)

Midterm: Question 3 (30%)• Estimated time: One hour• Write a program to move two characters horizontally.• The screen dimension is 80x24 (width x height).• The colors of the two characters are red and green, respectively.

Initially:– (2%) the two characters are at (39, 12) and (38, 12).– (5%) the red character moves to the left side.– (2%) the green character moves to the right side.

- (5%) If they hit the boundary of the window, reverse their movement direction.- (5%) If they hit each other, reverse their movement direction.The movement of each character has a delay. - (5%) Can be continue.- (2%) Press key ‘q’ to quit the program at any time and clear the screen.- (2%) Show your student ID at the end of the program. -(2%) Explain how you implement the program.

Example:Enter the movement delay of the red character (ms): 500Enter the movement delay of the green character (ms): 250

Snapshots direction