Code in c++
Introduction In this assignment you with be creating a C++ program which will create a Girl Scout Cookie Invoice within a file. Girl Scout Cookie Invoice Write a program that will create an invoice for a customer who purchased Girl Scout cookies. The program should continually loop on customers Program Input For this program, you will be invoicing for 10 different varieties of Girl Scout cookies. The program should loop on each input prompt for valid user input. The program should loop until receiving 'q' to exit. This offers the opportunity to have multiple customer orders entered by the user. Valid input for each customer is name, address, and city, state and zip code followed by their order of each of the ten cookies. If the user enters 'q', for the customer name, the program should exit. Input validation should be performed on each cookie. The example below illustrates input validation. quantity = -1 while ((quantity < min_order) || (quantity > max_order)) In the example above, the program will leave the loop only on good input. If the user enters an order for a negative value or more than 10 cookies of a particular type, the program should re- prompt the user.
Assignment 3S-LO: 6 Before submitting, Refer to C++ Programming Coding Standards document. The program input prompts to the user are (user enters Johnny Good for the first and last name): "Order Number: 1" "Enter the customers first and last name (or q to quit): " "Enter the Johnny Good's address: "Enter the Johnny Good's city, state and zip code: " "Enter the number of Thin Mints (0-10): " "Enter the number of Lemon-Ups (0-10): "Enter the number of Lemonades (0-10): "Enter the number of Samoas (0-10): "Enter the number of Tagalongs (0-10): "Enter the number of Do-si-dos (0-10): "Enter the number of Trefoils (0-10): "Enter the number of Thanks-A-Lot (0-10): " "Enter the number of Toffee-tastic (0-10): "Enter the number of Caramel Chocolate Chip (0-10): " Program Calculation The program should calculate the cost of each type of cookie and a running total and display the current date. • The current date can be obtained by including the following header file: #include <ctime> Now, to get the current date, simply: time_t result time(NULL); dateStr = ctime(&result); • Girl Scout cookies are currently $5.00/box • The program will need to keep a count of the number orders and display the invoice in file named: ab_orders.txt (where a is the first letter of your first name and b is the first letter of your last name, all in lower case.) • To create a file, you will need to include the fstream header file: #include <fstream> The program will need to open the file for writing as in this example: // Open the output file ofstream outFile; outFile.open ("gd_orders.txt"); Page 2
Assignment 35-LO: 6 Before submitting, Refer to C++ Programming Coding Standards document. • In the above example the variable outFile was used to use the file stream object. Now, you can write the file: outFile << endl; The above example writes a blank line to the output file. Remember to close the file: outfile.close(); Program Notes You will need to create a function named getCookies(). This function will prompt the user for the numbers of cookies desired. As an example: Enter the number of Thin Mints (0-10): The function will loop until the user enters a valid count. In the above example, the user will need to enter a value of 0 to 10. The function should accept parameters of the prompt and the maximum cookies the user is allowed to order. It should return the quantity of the cookies desired. As a reminder, the main() function must appear first, followed by subsequent functions. Some helpful hints are: • Create a block of code for one type of cookie. Test the code and copy and modify the block for the other 9 cookies. • As a helpful hint, after using cin>> to some variable, you will need to clean out the new line character left in the buffer before doing a getline(cin, variable_name) by: cin.ignore(); cin.clear(); • Remember to do the cin.ignore() and cin.clear() before the next getline() and to open the output file before your loop and close the file after your loop. If you use the getline function, you can check the first character of the string for "q" by: if (customer == "q")
Assignment 35-LO: 6 Before submitting, Refer to C++ Programming Coding Standards document. Program Output Girl Scout Cookie Invoice Mon Jun 06 23:37:15 2022 Johnny Good 123 Main Street Batavia, IL 60542 Order Number: 1 Dear Johnny B Good: Your Girl Scout Cookie order has arrived. Your order consists of the following: I I Quantity | Cost Cookie | Thin Mints | Lemon-Up | Lemonades | Samoas | Tagalongs | Do-si-dos | Trefoils | Thanks-A-Lot | Toffee-tastic | Caramel Chocolate Chip | 1 $ 21 $ 31 $ 61 $ 71 $ 8 $ 91 $ 10 | $ Total Due: | $ Note: The above input was written to a file. 41 $ 51 $ 5.00 I 10.00 I 15.00 I 20.00 I 25.00 I 30.00 I 35.00 I 40.00 I 45.00 I 50.00 I 275.00 |
Assignment 35-LO: 6 Before submitting, Refer to C++ Programming Coding Standards document. The program output should display exactly as shown. The fields have the following character lengths" • Cookie - 21 characters. • Quantity - 8 characters • Cost-9 characters (1 for $,8 for the money field with 2 decimal points). • Each field begins with the I symbol followed by a space, then the field data, then finally a space and the I symbol. • The program can use the setw(n) to control the width of each field (remember to include the header file iomanip). • All of the fields have a space before and after the field. The program should display the following heading before prompting the user: "*** Welcome to Girl Scout Cookie Order Form **** "We promise to deliver excellent cookies to your doorstep." Submit Instructions • Refer to the C++ Programming Coding Standards document located on the Course Overview Page on Canvas. • Submit file via Canvas's submission tool.
Code in c++
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am