The Greedy Ringy Manufacturing Company CEO called again wanting more functionali
ID: 3766933 • Letter: T
Question
The Greedy Ringy Manufacturing Company CEO called again wanting more functionality added to your program. BEORE you begin implementing this new functionality it is time to re-organize your program using functions. Your main function has grown large and it is time to make your program more modular by breaking it into functions. The named constant you used for the sales tax should now be made global so you won't have to pass that value to any of your functions.
Use the Divide and Conquer approach described in Section 6.1 of your textbook. Think about all the different tasks your program is doing and make a list. Make sure each task doesn't include multiple tasks. If it does, break it into subtasks. Once you have your list of tasks and subtasks, you'll know what functions you'll need to write. For this project, you will need (at a minimum) a function to display the menu, a function to get the order information, a function to create a shipping manifest, a function to create a purchase receipt and a function that implements the new required functionality explained later in this document. You may design the functions any way you wish, but you must have at least one function that returns a value that is used in another part of the program and you must have a different function that accepts parameters. Global variables are prohibited.
You are strongly advised to start with a fresh file and use the Stubs and Drivers approach the author of your book talks about in Section 6.16. Write stubs for each of your functions so you can concentrate on writing the parts of the program that call the functions. When the parts of the program that call the stubs are debugged to your satisfaction, then you can move on to writing the actual functions themselves. It is recommended that you create a driver program to thoroughly test your functions before adding them to your project. Add them one at a time thoroughly testing one before adding another. This will isolate any errors to just one block of code making your program much easier to debug.
The Greedy Ringy Manufacturing Company's efficiency has improved so much from using the application you built for them that the business has grown. They have opened a satellite office in Ringtown, IN as a base for their sales people. No manufacturing will be done at this facility. Instead, the sales staff will travel around soliciting orders. The orders will be collected and sent to the Ringold plant once daily in a text file format. Your program needs to be able to read a text file named DoflingyOrder.txt and display to the console all the information that was displayed in Project 2 for each order in the file. (To simplify things for this assignment, you do not need to create any text files for these orders.) Another option to read the text file will need to be added to your menu. When the user selects this option, the required information should be calculated and displayed for every order in the file without the user needing to do anything else.
dooThe format of the file your program will be expected to process is identical to DoflingyOrder.txt which has been provided for you. This file contains 10 orders, but your program must be able to process a file with any number of orders.
Instructions:
Make your program more modular by breaking it into functions.
Make the sales tax named constant global.
Add the new Menu item to process a text file.
Allow the user to make new choices until they are finished.
Properly handle an invalid menu choice.
Calculate and display purchase and shipping information to console for every order in the text file.
Bonus Pts (5pts). Add validation code that rejects an order in the text file if the number of doflingies is not at least 10 and no more than 1000. Do not display purchase or shipping information to the console for these invalid orders. Instead create a rejected orders text file that contains the order information in the DoflingOrder.txt file for all the rejected orders.
#include
#include
#include
#include
using namespace std;
int main()
{
//Numeric variables needed for containers, zipcode, mathematical operations
int doflingy, huge, large, medium, small, zipcode, hremain, lremain, customers = 1;
double doflingyTotal, shippingTotal, taxTotal, orderTotal;
//Shipping information entered by user
string name, address, city, state;
//char for user to enter another customer
char moreCustomers = 'Y';
//sales tax, doflingy cost, and shipping constants
const double SALES_TAX = .0775;
const double HUGE_SHIPPING = 4.0, LARGE_SHIPPING = 2.0, MED_SHIPPING = 0.75, SMALL_SHIPPING = 0.2;
const double _500_PLUS_COST = 15.95, _250_TO_499_COST = 17.50, _100_TO_249_COST = 18.95, TO_99_COST = 19.95;
int printChoice;
do
{
//Prompt for order receipt or shipping invoice
cout << "Please select from the following options:" << endl;
cout << "-----------------------------------------" << endl << endl;
cout << "1.) Enter Order information." << endl;
cout << "2.) Create a shipping manifest." << endl;
cout << "3.) Createa purchase receipt." << endl;
cout << "4.) Quit" << endl << endl;
cout << "Select what you would like: ";
cin >> printChoice;
cout << endl;
if(printChoice == 4)
break;
if(printChoice == 1)
do
{
cin.ignore(1000, ' ');
//Series of prompts for the user to enter customer shipping info
cout << "Enter the name of the purchaser: ";
getline(cin, name);
cout << "Enter street address: ";
getline(cin, address);
cout << "Enter city: ";
getline(cin, city);
cout << "Enter state: ";
getline(cin, state);
cout << "Enter zipcode: ";
cin >> zipcode;
//Prompt for number of doflingies ordered, validates order size
cout << "Enter the number of doflingies ordered: ";
cin >> doflingy;
cout << endl;
if(doflingy < 10 || doflingy > 1000)
cout << " Orders less than 10 or greater than 1000 will not be accepted." << endl;
}while(doflingy < 10 || doflingy > 1000);
//variable declaration for printing options
if (printChoice == 4)
break;
else if (printChoice == 2)
{
//Output of entered shipping information and number of doflingies ordered
//Beginning of customer invoice/receipt
ofstream outputFile;
outputFile.open("Shipping_Mainifest.txt");
outputFile << "----------------------------------------" << endl;
outputFile << " Shipping Manifest " << endl;
outputFile << "----------------------------------------" << endl << endl;
outputFile << left << setw(17) << " Ship To:" << name << endl;
outputFile << " " << address << endl;
outputFile << " " << city << ", " << state << " " << zipcode << endl << endl;
outputFile << "No. of Doflingies: " << doflingy << endl << endl;
//Calculations for each size of container needed for shipping
huge = doflingy / 50;
hremain = doflingy%50;
large = hremain/20;
lremain = hremain%20;
medium = lremain/5;
small = lremain%5;
//Output of number of each container required for this shipment
outputFile << "Container Size Number Required" << endl;
outputFile << "-------------- ---------------" << endl;
outputFile << " Huge " << setw(15) << right << huge << endl;
outputFile << " Large " << setw(15) << right << large << endl;
outputFile << " Medium " << setw(15) << right << medium << endl;
outputFile << " Small " << setw(15) << right << small << endl;
outputFile << "----------------------------------------" << endl << endl << endl;
outputFile.close();
cout << "Your shippig manifest file has been created." << endl;
cout << "*****************************************" << endl << endl;
}
else if (printChoice == 3)
{
//Calculating doflingy cost
if(doflingy>=500)
doflingyTotal = doflingy * _500_PLUS_COST;
else if(doflingy>=250)
doflingyTotal = doflingy * _250_TO_499_COST;
else if(doflingy>=100)
doflingyTotal = doflingy * _100_TO_249_COST;
else
doflingyTotal = doflingy * TO_99_COST;
//Calculating shipping
shippingTotal = (huge*HUGE_SHIPPING)+(large*LARGE_SHIPPING)+(medium*MED_SHIPPING)+(small*SMALL_SHIPPING);
//Calculating sales tax
taxTotal = (doflingyTotal) * SALES_TAX;
//Calculating order total
orderTotal = doflingyTotal + shippingTotal + taxTotal;
//Customer receipt
ofstream outputFile;
outputFile.open("Customer_receipt.txt");
outputFile << "----------------------------------------" << endl;
outputFile << " RECEIPT " << endl;
outputFile << "----------------------------------------" << endl << endl;
outputFile << left << setw(17) << "Sold To:" << name << endl;
outputFile << " " << address << endl;
outputFile << " " << city << ", " << state << " " << zipcode << endl << endl;
outputFile << "No. of Doflingies: " << doflingy << endl << endl;
outputFile << "------------------Cost------------------" << endl << endl;
outputFile << setprecision(2) << fixed;
outputFile << "Doflingies $" << setw(14) << right << doflingyTotal << endl;
outputFile << "Sales Tax $" << setw(14) << right << taxTotal << endl;
outputFile << "Shipping & Handling $" << setw(14) << right << shippingTotal << endl;
outputFile << " _______________" << endl;
outputFile << "Total $" << setw(14) << right << orderTotal << endl;
outputFile.close();
cout << "Your purchase receipt file has been created." << endl;
cout << "*****************************************" << endl << endl;
}
}while (printChoice != 4);
cout << "Thank You. Closing program ";
return 0;
}
Explanation / Answer
#include #include #include #include using namespace std; int main() { //Numeric variables needed for containers, zipcode, mathematical operations int doflingy, huge, large, medium, small, zipcode, hremain, lremain, customers = 1; double doflingyTotal, shippingTotal, taxTotal, orderTotal; //Shipping information entered by user string name, address, city, state; //char for user to enter another customer char moreCustomers = 'Y'; //sales tax, doflingy cost, and shipping constants const double SALES_TAX = .0775; const double HUGE_SHIPPING = 4.0, LARGE_SHIPPING = 2.0, MED_SHIPPING = 0.75, SMALL_SHIPPING = 0.2; const double _500_PLUS_COST = 15.95, _250_TO_499_COST = 17.50, _100_TO_249_COST = 18.95, TO_99_COST = 19.95; do { //Series of prompts for the user to enter customer shipping info coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.