PROGRAM 14
// FILENAME: PROG14.CPP // THIS PROGRAM CALCULATES THE PRICE OF A CARPET BOUGHT AT ABE' CARPETORIUM. #include #include #include #include #include #include #include #include #include ofstream prnt; char save [2000]; get_copyright (); paint_screen (); int get_type (); int get_length (); int get_width (); compute_yards_cost (int &type1, int &length1, int &width1, int &area, float &cost); show_em (int area, float cost); char get_yn (int col, int row); print_quote (int length1, int width1, int area, float cost, int type); get_it (); return_it (); display_errormessage (); main () { int type1, length1, width1, area; float cost; char ans1; get_copyright (); do { paint_screen (); type1 = get_type (); length1 = get_length (); width1 = get_width (); compute_yards_cost (type1, length1, width1, area, cost); show_em (area, cost); int row = 19; int col = 32; ans1 = get_yn (col, row); if (ans1 == 'Y' || ans1 == 'y') { print_quote (length1, width1, area, cost, type1); } row = 19; col = 62; ans1 = get_yn (col, row); } while (ans1 == 'Y' || ans1 == 'y'); return 0; } get_copyright () { char pause; #include gotoxy (6, 7); cprintf (" PROG14.CPP"); gotoxy (22, 9); pause = getch (); cprintf ("\a"); return 0; } paint_screen () { textbackground (9); window (1, 1, 80, 25); clrscr (); textbackground (8); window (8, 4, 77, 24); clrscr (); textbackground (12); textcolor (15); window (5, 3, 74, 23); clrscr (); gotoxy (22, 3); cprintf ("HONEST ABE'S CARPETORIUM"); gotoxy (21, 5); cprintf ("CARPET TYPES COST/YARD"); gotoxy (21, 7); cprintf ("1. QUALITY - $12.00 "); gotoxy (21, 9); cprintf ("2. PREMIUM - $18.00 "); gotoxy (21, 11); cprintf ("3. SUPERIOR - $22.00 "); gotoxy (11, 13); cprintf ("CARPET TYPE DESIRED: "); gotoxy (11, 15); cprintf (" LENGTH DESIRED: WIDTH DESIRED:"); gotoxy (11, 17); cprintf (" YARDS NEEDED: PRICE:"); gotoxy (7, 19); cprintf ("PRINT QUOTE SHEET (Y/N): REPEAT (Y/N):"); return 0; } int get_type () { int type1; char type2 [10]; get_it (); do { gotoxy (32, 13); gets (type2); type1 = atoi (type2); if ((type1 < 1) || (type1 > 3)) { display_errormessage (); gotoxy (5, 2); cprintf ("ERROR, TYPE 1, 2, OR 3. "); } else { return_it (); } } while (type1 < 1 || type1 > 3); gotoxy (32, 13); cprintf ("%i\a", type1); return (type1); } int get_length () { int length1; char length2 [10]; get_it (); do { gotoxy (32, 15); gets (length2); length1 = atoi (length2); if ((length1 < 1) || (length1 > 100)) { display_errormessage (); gotoxy (5, 2); cprintf ("ERROR, LENGTH MUST RANGE FROM 1 TO 100. "); } else { return_it (); } } while (length1 < 1 || length1 > 100); gotoxy (32, 15); cprintf ("%i\a", length1); return (length1); } int get_width () { int width1; char width2 [10]; get_it (); do { gotoxy (62, 15); gets (width2); width1 = atoi (width2); if ((width1 < 1) || (width1 > 100)) { display_errormessage (); gotoxy (5, 2); cprintf ("ERROR, WIDTH MUST RANGE FROM 1 TO 100. "); } else { return_it (); } } while (width1 < 1 || width1 > 100); gotoxy (62, 15); cprintf ("%i\a", width1); return (width1); } compute_yards_cost (int &type1, int &length1, int &width1, int &area, float &cost) { area = length1 * width1 / 9 + 1; if (type1 == 1) { cost = area * 12.00; } else if (type1 == 2) { cost = area * 18.00; } else { cost = area * 22.00; } return 0; } char get_yn (int col, int row) { char ans1; get_it (); do { gotoxy (col, row); ans1 = getche (); if (ans1 != 'Y' && ans1 != 'N' && ans1 != 'y' && ans1 != 'n') { display_errormessage (); gotoxy (5, 2); cprintf ("ERROR, ANSWER MUST BE 'Y' OR 'N'. "); } else { return_it (); } } while (ans1 != 'Y' && ans1 != 'N' && ans1 != 'y' && ans1 != 'n'); gotoxy (col, row); cprintf ("%c\a", ans1); return (ans1); } print_quote (int length1, int width1, int area, float cost, int type1) { char type3 [10]; if (type1 == 1) { strcpy (type3, "QUALITY"); } else if (type1 == 2) { strcpy (type3, "PREMIUM"); } else { strcpy (type3, "SUPERIOR"); } prnt.open ("LPT1", ios :: out); prnt.setf (ios :: showpoint); prnt.setf (ios :: fixed); prnt << "\n ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿\n"; prnt << " ³ ABE'S CARPETORIUM ³\n"; prnt << " ³ 1111 LINCOLN AVE. ³\n"; prnt << " ³ HONEST, CA 22222 ³\n"; prnt << " ³ ³\n"; prnt << " ³ QUOTE SHEET ³\n"; prnt << " ³ ÄÄÄÄÄÄÄÄÄÄÄ ³\n"; prnt << " ³ ³\n"; prnt << " ³ TYPE LENGTH WIDTH AREA COST ³\n"; prnt << " ³ ÄÄÄÄ ÄÄÄÄÄÄ ÄÄÄÄÄ ÄÄÄÄ ÄÄÄÄ ³\n"; prnt << " ³" << setprecision (2) << setw (9) << type3 << setw (8) << length1 << setw (11) << width1 << setw (11) << area << " $" << setw (8) << cost << setw (3) << "³\n"; prnt << " ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ\f"; prnt.close (); return 0; } show_em (int area, float cost) { gotoxy (32, 17); cprintf ("%i", area); gotoxy (62, 17); cprintf ("$%1.2f", cost); return 0; } get_it () { gettext (15, 15, 72, 20, save); return 0; } return_it () { window (5, 3, 74, 23); puttext (15, 15, 72, 20, save); textbackground (12); textcolor (15); return 0; } display_errormessage () { sound (1000); delay (500); sound (2000); delay (500); nosound (); textbackground (8); window (17, 16, 72, 20); clrscr (); textbackground (14); textcolor (3 + 128); window (15, 15, 70, 19); clrscr (); return 0; } // FILENAME: COPY.H // SEE PROGRAM 7. // OUTFILE: PROG14.OUT HONEST ABE'S CARPETORIUM CARPET TYPES COST/YARD 1. QUALITY - $12.00 2. PREMIUM - $18.00 3. SUPERIOR - $22.00 CARPET TYPE DESIRED: 1 LENGTH DESIRED: 100 WIDTH DESIRED: 100 YARDS NEEDED: 1112 PRICE: $13344.00 PRINT QUOTE SHEET (Y/N): n REPEAT (Y/N): n
BACK TO CIS162 PAGE.