SHARE
TWEET

Warehouse

a guest May 25th, 2019 195 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /************************************
  2. * NAME: Warehouse
  3. * AUTHOR: Alex Newport
  4. * SINCE: 4/3/19
  5. * PURPOSE: 1111 Final Project
  6. * VERSION: 1.0
  7. ************************************/
  8.  
  9. #include <iostream>
  10. #include <string>
  11. #include <fstream>
  12. #include <cmath>
  13.  
  14. using namespace std;
  15.  
  16. short menu();
  17. void fileOutput(fstream &);
  18. void fileInput(fstream &);
  19.  
  20. void overloadedMain();
  21.  
  22. short overloaded(short, short);
  23. float overloaded(float, float);
  24. bool overloaded(bool, bool);
  25.  
  26. int main()
  27. {
  28.     cout << "\t\tWelcome to the warehouse program!" << endl << endl;
  29.     cout << "Use this to enter the quantities of the four items we store here: basketballs, baseballs," << endl <<
  30.         "baseball bats, and footballs. This information will be stored in a file so the info is retained" << endl;
  31.     bool resetti_spaghetti = 0;
  32.     short num;
  33.     fstream file;
  34.     while (resetti_spaghetti == 0)
  35.     {
  36.             num = menu();
  37.             switch (num)
  38.             {
  39.             case 1:
  40.                 file.open("C:\\Users\\newport53494\\Desktop\\warehouse.txt", ios::out);
  41.                 fileOutput(file);
  42.                 file.close();
  43.                 break;
  44.             case 2:
  45.                 file.open("C:\\Users\\newport53494\\Desktop\\warehouse.txt", ios::in);
  46.                 if (!file.is_open())
  47.                 {
  48.                     cout << "No warehouse file has been created" << endl;
  49.                     break;
  50.                 }
  51.                 else
  52.                     fileInput(file);
  53.                 file.close();
  54.                 break;
  55.             case 3:
  56.                 overloadedMain();
  57.                 break;
  58.             default:
  59.                 cout << "Press enter 5 times to exit...." << endl;
  60.                 cin.ignore(10, '\n');
  61.                 cin.get();
  62.                 for (short exitSequence = 4; exitSequence > 0; exitSequence--) //really hunting down those points aren't I?
  63.                 {
  64.                     cout << "Press enter " << exitSequence << " more times to exit...." << endl;
  65.                     cin.get();
  66.                 }
  67.                 resetti_spaghetti = 1;
  68.                 break;
  69.             }
  70.             cout << endl << endl;
  71.     }
  72. }
  73. short menu()
  74. {
  75.     short choice;
  76.     cout << "\n\n\n\n\t\tWarehouse Menu" << endl << endl << endl;
  77.     cout << "1.) Write onto the file" << endl;
  78.     cout << "2.) Check quantities of items stored" << endl;
  79.     cout << "3.) Overloaded function demonstration" << endl;
  80.     cout << "4.) Exit program" << endl;
  81.     cout << "Your choice: ";
  82.     while (!(cin >> choice) || cin.fail() || choice > 4 || choice < 1)
  83.     {
  84.         cout << "Please enter a number 1 through 4" << endl;
  85.         cin.clear();
  86.         cin.sync();
  87.         cin.ignore(100, '\n');
  88.     }
  89.     return choice;
  90. }
  91.  
  92. void fileOutput(fstream &out)
  93. {
  94.     int items;
  95.     cout << "How many basketballs are stored?" << endl;
  96.     while (!(cin >> items) || cin.fail() || items < 0)
  97.     {
  98.         cout << "Please enter a positive number" << endl;
  99.         cin.clear();
  100.         cin.sync();
  101.         cin.ignore(100, '\n');
  102.     }
  103.     out << items << " ";
  104.     cout << "How many baseballs are stored?" << endl;
  105.     while (!(cin >> items) || cin.fail() || items < 0)
  106.     {
  107.         cout << "Please enter a positive number" << endl;
  108.         cin.clear();
  109.         cin.sync();
  110.         cin.ignore(100, '\n');
  111.     }
  112.     out << items << " ";
  113.     cout << "How many baseball bats are stored?" << endl;
  114.     while (!(cin >> items) || cin.fail() || items < 0)
  115.     {
  116.         cout << "Please enter a positive number" << endl;
  117.         cin.clear();
  118.         cin.sync();
  119.         cin.ignore(100, '\n');
  120.     }
  121.     out << items << " ";
  122.     cout << "How many footballs are stored?" << endl;
  123.     while (!(cin >> items) || cin.fail() || items < 0)
  124.     {
  125.         cout << "Please enter a positive number" << endl;
  126.         cin.clear();
  127.         cin.sync();
  128.         cin.ignore(100, '\n');
  129.     }
  130.     out << items << " ";
  131. }
  132.  
  133. void fileInput(fstream &in)
  134. {
  135.     cout << endl << endl << endl;
  136.     int itemsArr[2][2];
  137.     in >> itemsArr[0][0];
  138.     in >> itemsArr[0][1];
  139.     in >> itemsArr[1][0];
  140.     in >> itemsArr[1][1];
  141.     cout << "Basketballs: " << itemsArr[0][0] << endl << "Baseballs: " << itemsArr[0][1] << endl;
  142.     cout << "Baseball bats: " << itemsArr[1][0] << endl << "Footballs: " << itemsArr[1][1] << endl;
  143.     cout << "Press enter to proceed....." << endl;
  144.     cin.ignore(100, '\n');
  145.     cin.get();
  146. }
  147.  
  148. void overloadedMain()
  149. {
  150.     short choice;
  151.     cout << endl << "Select one of the following data types to use for the overloaded exponent function" << endl;
  152.     cout << "1.) Short Int" << endl;
  153.     cout << "2.) Float" << endl;
  154.     cout << "3.) Bool" << endl;
  155.     cout << "Your choice: ";
  156.     while (!(cin >> choice) || cin.fail() || choice > 3 || choice < 1)
  157.     {
  158.         cout << "Please enter a choice 1 through 3" << endl;
  159.         cin.clear();
  160.         cin.sync();
  161.         cin.ignore(100, '\n');
  162.     }
  163.     long float num1;
  164.     long float num2;
  165.     cout << endl << endl;
  166.     cout << "Enter a number. Keep in mind that for the purposes of demonstrating that the function uses" << endl;
  167.     cout << "multiple data types, it will be intentionally possible to overflow data" << endl;
  168.     cout << "Base number: ";
  169.     while (!(cin >> num1) || cin.fail())
  170.     {
  171.         cout << "Please enter a numeric value" << endl;
  172.         cin.clear();
  173.         cin.sync();
  174.         cin.ignore(100, '\n');
  175.     }
  176.     cout << "Exponent: ";
  177.     while (!(cin >> num2) || cin.fail())
  178.     {
  179.         cout << "Please enter a numeric value" << endl;
  180.         cin.clear();
  181.         cin.sync();
  182.         cin.ignore(100, '\n');
  183.     }
  184.     cout << endl << endl << endl;
  185.     if (choice == 1)
  186.         cout << "The short data type answer to " << num1 << " to the power of " << num2 << " is " << overloaded((short)num1, (short)num2);
  187.     else if (choice == 2)
  188.         cout << "The float data type answer of " << num1 << " to the power of " << num2 << " is " << overloaded((float)num1, (float)num2);
  189.     else
  190.         cout << "The bool data type answer of " << num1 << " to the power of " << num2 << " is " << overloaded((bool)num1, (bool)num2) << "\nObviously, the answer will only be one for bools";
  191.     cout << "\n\nPress enter to proceed....." << endl;
  192.     cin.ignore(100, '\n');
  193.     cin.get();
  194. }
  195.  
  196. short overloaded(short num1, short num2)
  197. {
  198.     return pow(num1, num2);
  199. }
  200.  
  201. float overloaded(float num1, float num2)
  202. {
  203.     return pow(num1, num2);
  204. }
  205.  
  206. bool overloaded(bool num1, bool num2)
  207. {
  208.     return pow(num1, num2);
  209. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top