From 9d53d8857eaa1c9405894a88ca75bc4657e42f35 Mon Sep 17 00:00:00 2001 From: msglm Date: Sat, 14 Jan 2023 05:31:48 -0600 Subject: Inital Commit --- .../Take Order Program Instructions (v2).docx | Bin 0 -> 126444 bytes C++/TakeOrderV2/TakeOrderV2.cpp | 203 +++++++++++++++++++++ C++/TakeOrderV2/instructions.txt | 7 + 3 files changed, 210 insertions(+) create mode 100644 C++/TakeOrderV2/Take Order Program Instructions (v2).docx create mode 100644 C++/TakeOrderV2/TakeOrderV2.cpp create mode 100644 C++/TakeOrderV2/instructions.txt (limited to 'C++/TakeOrderV2') diff --git a/C++/TakeOrderV2/Take Order Program Instructions (v2).docx b/C++/TakeOrderV2/Take Order Program Instructions (v2).docx new file mode 100644 index 0000000..29e32de Binary files /dev/null and b/C++/TakeOrderV2/Take Order Program Instructions (v2).docx differ diff --git a/C++/TakeOrderV2/TakeOrderV2.cpp b/C++/TakeOrderV2/TakeOrderV2.cpp new file mode 100644 index 0000000..8aafdc2 --- /dev/null +++ b/C++/TakeOrderV2/TakeOrderV2.cpp @@ -0,0 +1,203 @@ +// Name: msglm +// Date: +// Program Name: +// Description: + + +#include +#include +#include +using namespace std; + +// Named constants + + +/* + * Not using header files for this project + * So there's no reason to define below main + */ + +/* cleans up input problems relating to invalid input + * + * This is of high utility + * I might use this function in other projects + * + * I swear I will end up writing my own input/output funcs for C++ + * I cannot stand input validation with cin and cout + */ +void fixCin() { + cin.clear(); + cin.ignore(1000, '\n'); + cout << "===ERROR: Invalid Input!===" << endl; +} + + +/* + * Main has incredibly low amounts of code repitition, thus + * splitting it up into functions would be fragmented and unmaintainable code + * + * technically, if I wished to follow the requirements to the letter, I could write something like: + * + * void TakeOrder() { + * all actual processing of code + * ... + * } + * + * int main() { + * takeOrder() + * } + * + * + * for an incredibly low SLOC count in a function + * named main, but that'd serve almost no purpose at all + * and would just pollute this codebase with an unneeded function. + * + * An explanation like this should, in spirit, achieve the purpose of the "low SLOC in main" requirement: + * showing understanding of functions and displaying an ability to use them. + */ +int main() { + + //Variable declaration + bool wrongOrder = false; + char satisfied; + char size = 's'; + float price; + int items = 0; + int menuNum = 1; + string curItem; + string curSize; + + //Program title and description for the user + cout << "Welcome to Anonymous's Dine and Shine" << endl << endl; + + //User Information + cout << "Menu: \n"; + cout << "1 - Burger\n"; + cout << "2 - Fries\n"; + cout << "3 - Drink\n"; + + cout << "Sizes: \n"; + cout << "S - Small $4.25\n"; + cout << "M - Medium $5.50\n"; + cout << "L - Large $7.50\n"; + + // User input + + //Order number handling + do { + if ( !cin ) { + fixCin(); + } + + cout << "How many items would you like to buy?: "; + cin >> items; + } while ( !cin ); + + //For the amount of items requested, offer the user the shop menu + for (int itemNum = 1; itemNum <= items; itemNum++) { + do { + //Just so the user knows what order the program is writing about + cout << "Order Number " << itemNum << endl; + + + //User input + //Menu item handling + do { + + if ( !cin || menuNum < 1 || menuNum > 3 ) { + fixCin(); + } + + cout << "Enter the menu number for your item: \n"; + cin >> menuNum; + + } while ( !cin || menuNum < 1 || menuNum > 3 ); + + + //Size of item handling + do { + + if ( !cin || !(size == 's' || size == 'S' || size == 'm' || size == 'M' || size == 'l' || size == 'L') ) { //This line is gross, there's probably a better way to do this + fixCin(); + } + + cout << "Enter the size of that item: \n"; + cin >> size; + + } while ( !cin || !(size == 's' || size == 'S' || size == 'm' || size == 'M' || size == 'l' || size == 'L') ); + + //Price and String Output figuring + + /* + * In a big project, string comparision like + * shown here would not be done at all + * instead, some form of ENUM could be used instead + * + * The only reason I went with string comparision was for + * easy debugging when developing. I would never allow + * code like this to ever touch any production branches. + */ + + + switch(menuNum) { + case 1: + curItem = "Burger"; + break; + case 2: + curItem = "Fries"; + break; + case 3: + curItem = "Drink"; + break; + default: + cout << "Invalid Entry. Terminating"; + return 1; + } + + switch(size) { + case 's': + case 'S': + curSize = "Small"; + price = price + 4.25; + break; + case 'm': + case 'M': + curSize = "Medium"; + price = price + 5.50; + break; + case 'l': + case 'L': + curSize = "Large"; + price = price + 7.50; + break; + default: + cout << "Invalid Entry. Terminating"; + return 1; + } + cout << "For Order " << itemNum << " you ordered a " << curSize << " " << curItem << endl; + cout << "Are you satisfied with this order? (Y/n): "; + cin >> satisfied; + + if (satisfied == 'n' || satisfied == 'N') { + wrongOrder = true; + } else { + wrongOrder = false; + } + + } while(wrongOrder); + + wrongOrder = false; + + } + //Output Prices + cout << "Sub Total: $" << setprecision(3) << price << endl; + cout << "Tax: $" << setprecision(3) << price*0.10 << endl; + cout << "Total: $" << setprecision(3) << price+(price*0.10) << endl; +} + +/*This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * You should have received a copy of the GNU General Public License along with this program. If not, see . + */ + diff --git a/C++/TakeOrderV2/instructions.txt b/C++/TakeOrderV2/instructions.txt new file mode 100644 index 0000000..6fe1592 --- /dev/null +++ b/C++/TakeOrderV2/instructions.txt @@ -0,0 +1,7 @@ +The focus of this version/iteration is error checking. All user input should be checked to ensure it is valid input! If they enter an incorrect order, your program should allow them to redo the order. So, TEST, TEST, TEST!! +When this iteration is graded, here is what I will be looking for: + + That all invalid input is caught, the user is told, and allowed to redo input + You have utilized function when needed (at least once) + Subtotal, tax, and total are still calculating correctly + Anything that stands out to me as inefficient or incorrect -- cgit v1.2.3