Question
#include #include #include // (a) Declare four global integer variables, as follows: // x - the horizontal location of the left edge of the rectangle
#include #include #include
// (a) Declare four global integer variables, as follows: // x - the horizontal location of the left edge of the rectangle // y - the vertical location of the top edge of the rectangle // w - the width of the rectangle. // h - the height of the rectangle.
// (b) Declare a global variable of type char called c. // This is the character that is to be used to render the rectangle.
void draw_rect(void) { // (c) Insert code to draw the outline of the rectangle defined by the global variables. // If either of the width or height is less than or equal to zero, // the function must not draw anything. }
int main(void) { setup_screen();
// draw a box. x = rand() % screen_width() / 2; y = rand() % screen_height() / 2; w = 1 + rand() % (screen_width() - x - 1); h = 1 + rand() % (screen_height() - y - 1); c = '@'; draw_rect(); show_screen();
// draw a box. x = rand() % screen_width() / 2; y = rand() % screen_height() / 2; w = 1 + rand() % (screen_width() - x - 1); h = 1 + rand() % (screen_height() - y - 1); c = '&'; draw_rect(); show_screen();
// draw a box with zero width. x = rand() % screen_width() / 2; y = rand() % screen_height() / 2; w = 0; h = 1 + rand() % (screen_height() - y - 1); c = '*'; draw_rect(); show_screen();
// draw a box. x = rand() % screen_width() / 2; y = rand() % screen_height() / 2; w = 1 + rand() % (screen_width() - x - 1); h = 1 + rand() % (screen_height() - y - 1); c = '#'; draw_rect(); show_screen();
// draw a box with negative width. x = rand() % screen_width() / 2; y = rand() % screen_height() / 2; w = -rand() % screen_width(); h = 1 + rand() % (screen_height() - y - 1); c = '!'; draw_rect(); show_screen();
// draw a box. x = rand() % screen_width() / 2; y = rand() % screen_height() / 2; w = 1 + rand() % (screen_width() - x - 1); h = 1 + rand() % (screen_height() - y - 1); c = '+'; draw_rect(); show_screen();
// draw a box with zero height. x = rand() % screen_width() / 2; y = rand() % screen_height() / 2; w = 1 + rand() % (screen_width() - x - 1); h = 0; c = 'a'; draw_rect(); show_screen();
// draw a box. x = rand() % screen_width() / 2; y = rand() % screen_height() / 2; w = 1 + rand() % (screen_width() - x - 1); h = 1 + rand() % (screen_height() - y - 1); c = 'b'; draw_rect(); show_screen();
// draw a box with negative width. x = rand() % screen_width() / 2; y = rand() % screen_height() / 2; w = -rand() % screen_width(); h = 1 + rand() % (screen_height() - y - 1); c = 'c'; draw_rect(); show_screen();
// draw a box. x = rand() % screen_width() / 2; y = rand() % screen_height() / 2; w = 1 + rand() % (screen_width() - x - 1); h = 1 + rand() % (screen_height() - y - 1); c = 'd'; draw_rect(); show_screen();
timer_pause(5000); cleanup_screen(); return 0; }
omplete the implementation of the draw_rect function. This function augments the ZDK by adding the ability to draw rectangular boxes. The hash-tags for this exercise are: cab202 and #cab202DrawRect1. This exercise will give you practice with the drawing functions in the ZDK and the use of global variables to transfer data between functions. Given the definition of a rectangle, you will complete a function that draws the outline of the rectangle using pre-existing functions defined in the ZDK. This function does not return a result. To complete the program, follow the instructions detailed in the in-line comments in the draw_rect () function
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started