//========================================================================= #define PROGRAMMER "BAHN, William" #define PROG_CODE "bahw" #define COURSE "ECE-1021" #define YEAR (2003) #define TERM "Fall" #define SECTION (0) #define ASSIGNMENT "RWA 3.8" #define REVISION (0) #define TITLE "Real World Application from Section 3.8" #define SUBTITLE "Printing a Bar Graph" #define EMAIL "wbahn@eas.uccs.edu" #define FILENAME "rwa0308.c" //========================================================================= // PROBLEM: // // MODIFIED FROM TEXT // // Print a bar graph. // Ask the user for a title for the bar graph // Ask the user for the full scale value // Keep asking for input until the user hits ^z or the maximum number // of lines is entered. // Each input consists of name (not to exceed 18 characters) and a value. // Use the Borland extensions to keep the input at the bottom of the screen // but place the output at the top of the screen (and come down from there) // // TYPICAL OUTPUT: // // ========= // HEADER // ========= // TITLE FULL SCALE: 50 // name1 |***************** // name2 |********** // name3 |******** // // NAME (18 characters max): name4 SIZE: 20 // // PSEUDOCODE // 1) REM: Print Header // 2) REM: Get Global Data // 2.1) GET: Title // 2.2) GET: Full Scale Value // 3) REM: Print Glabal Data 2 lines below header // 4) LOOP: Until User Hits Ctl-Z // 4.1) PUT: Program Termination Message to screen. // 8) PUT: Program Termination Message to screen. // 9) EXIT program //== REUSABLE CODE SEGMENTS =============================================== // Labeled RCS, a reusable code segment is simply a segment of code // that either performs a task that is repeated elsewhere. Sometimes // it is repeated exactly the same each time and in other cases the // code is made sufficiently generic that only minor tweaks are needed // to use it in multiple places. // // The convention that is adopted here is that any code that changes // from one instance of the RCS to another is gathered in the first // few lines at the beginning of the RCS (if practical). // // These RCS blocks are one step removed from functions and converting // them to full fledged functions is very straightforward. //== INCLUDE FILES ======================================================== #include // printf(), scanf(), EOF #include // sqrt() #include // gotoxy() //== FUNCTION PROTOTYPES ================================================== void PrintHeader(void); //== MAIN FUNCTION ======================================================== int main(void) { int i, line; double fullscale; int dots, item; // Variables used by RCS blocks char c; int EOFfound; int promptline, promptcol; int echoline, echocol; int colmax, maxchar; int col; double value; PrintHeader(); printf("\n"); // Print a blank line gotoxy(1,25); printf("Enter Ctlr-Z to quit."); //== GLOBAL DATA INPUT ================================================= // ********** GET THE GRAPH NAME ********** gotoxy(1, 9); printf("TITLE: "); // RCS: PARTIAL LINE CLEAR --------------------------------------- // Clear part of line line = 24; col = 1; colmax = 80; do { gotoxy(col, line); printf(" "); } while(++col < colmax); //---------------------------------------------------------------- // RCS: PROMPT WITH REMOTE ECHO (TEXT INPUT) --------------------- // Prompt for character input at one location // Echo a maximum number of characters // to another location promptline = 24; promptcol = 1; echoline = 9; echocol = 8; maxchar = 40; gotoxy(promptcol, promptline); printf("Enter Graph Title: "); i = 0; c = 0; while(kbhit()) getch(); while( (EOF != scanf("%c", &c)) && ('\n' != c) ) { i++; if(i