/*---------------------------------------------------------- Elizabeth Sklar Assignment #3 MC140.0X 2 October 2000 This program prints out graphical objects (using ASCII graphics), based on input from the user. The user selects objects to print from a menu. This program is an extension of Assignment #2. It uses a grid in which to define graphical objects and determines mathematically which points should be marked to draw the graphical objects. ----------------------------------------------------------*/ #include #include #define MAX 21 char grid[MAX][MAX]; /*--------------------------------------------------------*/ /* initialize_grid */ /* */ /* This function initializes the grid by drawing an axis */ /* and setting all others points to the space character. */ /* */ /*--------------------------------------------------------*/ void initialize_grid() { } /* end of initialize_grid() */ /*--------------------------------------------------------*/ /* print_grid */ /* */ /* This function prints the grid. */ /* */ /*--------------------------------------------------------*/ void print_grid() { } /* end of print_grid() */ /*--------------------------------------------------------*/ /* get_option */ /* */ /* This function prints the menu and gets the user's */ /* choice of what to do. */ /* */ /*--------------------------------------------------------*/ char get_option() { char tmp[2]; printf( "R (draw rectangle)\n" ); printf( "T (draw triangle)\n" ); printf( "C (draw circle)\n" ); printf( "Q (quit)\n" ); printf( "enter option: " ); scanf( "%s",tmp ); return( tmp[0] ); } /* end of get_option() */ /*--------------------------------------------------------*/ /* draw_rectangle */ /* */ /* This function draws a rectangle. The user is asked to */ /* specify the height and width of the rectangle. */ /* */ /*--------------------------------------------------------*/ void draw_rectangle() { // ask user for dimensions . . . // initialize grid for drawing initialize_grid(); // plot the rectangle in the grid . . . // display the grid print_grid(); } /* end of draw_rectangle() */ /*--------------------------------------------------------*/ /* draw_triangle */ /* */ /* This function draws an upright right triangle, with */ /* its right corner at the origin. The user is asked to */ /* specify the height and width of the triangle. */ /* */ /*--------------------------------------------------------*/ void draw_triangle() { // ask user for dimensions . . . // initialize the grid initialize_grid(); // plot the triangle in the grid . . . // display the grid print_grid(); } /* end of draw_triangle() */ /*--------------------------------------------------------*/ /* draw_circle */ /* */ /* This function draws a circle. The user is asked to */ /* specify the radius of the circle. */ /* */ /*--------------------------------------------------------*/ void draw_circle() { // ask user for dimensions . . . // initialize the grid initialize_grid(); // plot the circle in the grid . . . // display the grid print_grid(); } /* end of draw_circle() */ /*--------------------------------------------------------*/ /* quit */ /* */ /* This function displays a goodbye message to the user. */ /* */ /*--------------------------------------------------------*/ void quit() { printf( "Thanks for playing!\n" ); } /* end of quit() */ /*--------------------------------------------------------*/ /* main program */ /* */ /*--------------------------------------------------------*/ void main() { char option = ' '; while ( option != 'Q' ) { option = get_option(); if ( option == 'R' ) { draw_rectangle(); } else if ( option == 'T' ) { draw_triangle(); } else if ( option == 'C' ) { draw_circle(); } else if ( option != 'Q' ) { printf( "Invalid option.\n" ); } } /* end of while */ quit(); } /* end of main() */