PROGRAM 10
// FILENAME: PROG10.CPP // THIS PROGRAM CALCULATES TOTAL YARDS AND PRICE OF CARPET AND PRINTS THEM // ON THE SCREEN. #include #include #include #include #include #include #include ofstream prnt; void main () { clrscr (); char my, ans; char type [10], width [10], length [10], kind [10]; int type2, yards; float width2, length2, price; #include "a:\copy.h" gotoxy (6, 7); cout << " PROG10.CPP"; gotoxy (48, 14); my = getch (); window (1, 1, 80, 25); textbackground (3); do { clrscr (); gotoxy (18, 1); cout << "HONEST ABE'S CARPETORIUM"; gotoxy (17, 3); cout << "CARPET TYPES COST / YARD"; gotoxy (17, 5); cout << "1. QUALITY - $ 12.00"; gotoxy (17, 7); cout << "2. PREMIUM - $ 18.00"; gotoxy (17, 9); cout << "3. SUPERIOR - $ 22.00"; gotoxy (7, 11); cout << "CARPET TYPE DESIRED:"; gotoxy (7, 13); cout << " LENGTH DESIRED: WIDTH DESIRED:"; gotoxy (7, 15); cout << " YARDS NEEDED: PRICE:"; do { gotoxy (28, 11); gets (type); type2 = atoi (type); if ((type2 < 1) || (type2 > 3)) { gotoxy (35, 11); cout << "ERROR, TYPE 1, 2, OR 3."; } else { gotoxy (29, 11); cout << " "; } } while ((type2< 1) || (type2 > 3)); do { gotoxy (28, 13); gets (length); length2 = atof (length); if ((length2 < 1) || (length2 > 100)) { gotoxy (35, 13); cout << "ERROR."; } else { gotoxy (31, 13); cout << " "; } } while ((length2 < 1) || (length2 > 100)); do { gotoxy (60,13); gets (width); width2 = atof (width); if ((width2 < 1) || (width2 > 100)) { gotoxy (65, 13); cout << "ERROR."; } else { gotoxy (63, 13); cout << " "; } } while ((width2 < 1) || (width2 > 100)); yards = ((length2 * width2) / 9) + 1; if (type2 == 1) { price = 12.00 * yards; strcpy (kind, "QUALITY"); } if (type2 == 2) { price = 18.00 * yards; strcpy (kind, "PREMIUM"); } if (type2 == 3) { price = 22.00 * yards; strcpy (kind, "SUPERIOR"); } gotoxy (28, 15); cout << yards; gotoxy (60, 15); cout.setf (ios :: showpoint); cout.setf (ios :: fixed); cout << setprecision (2) << price; gotoxy (2, 17); cout << " PRINT QUOTE SHEET (Y/N): "; do { gotoxy (28, 17); cin >> ans; if ((ans != 'y') && (ans != 'Y') && (ans != 'n') && (ans != 'N')) { gotoxy (35, 17); cout << "ERROR, TYPE EITHER Y, y, N, n."; } else { gotoxy (29, 17); cout << " "; } } while ((ans != 'y') && (ans != 'Y') && (ans != 'n') && (ans != 'N')); if ((ans == 'y') || (ans == 'Y')) { prnt.open ("LPT1", ios :: out); prnt.setf (ios :: showpoint); prnt.setf (ios :: fixed); prnt << setprecision (2); prnt << " HONEST ABE'S CARPETORIUM\n\n\n"; prnt << " 1111 LINCOLN STREET\n"; prnt << " WASHINGTON CA 22222\n\n\n"; prnt << " QUOTE SHEET\n"; prnt << " -----------\n"; prnt << " TYPE OF CARPET: " << kind << "\n"; prnt << " NUMBER OF YARDS: " << yards << "\n"; prnt << " PRICE OF CARPET: " << price << "\n\f"; prnt.close (); } gotoxy (1, 19); cout << "WOULD YOU LIKE TO CONTINUE (Y/N)? "; do { gotoxy (35, 19); cin >> ans; if ((ans != 'y') && (ans != 'Y') && (ans != 'n') && (ans != 'N')) { gotoxy (40, 19); cout << "ERROR, TYPE EITHER Y, y, N, n."; } else { gotoxy (36,19 ); cout << " "; } } while ((ans != 'y') && (ans != 'Y') && (ans != 'n') && (ans != 'N')); } while ((ans == 'y') || (ans == 'Y')); return; } // FILENAME: COPY.H // SEE PROGRAM 7. // OUTFILE: PROG10.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 WOULD YOU LIKE TO CONTINUE (Y/N)? n
BACK TO CIS162 PAGE.