Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /************************************
- * NAME: Warehouse
- * AUTHOR: Alex Newport
- * SINCE: 4/3/19
- * PURPOSE: 1111 Final Project
- * VERSION: 1.0
- ************************************/
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <cmath>
- using namespace std;
- short menu();
- void fileOutput(fstream &);
- void fileInput(fstream &);
- void overloadedMain();
- short overloaded(short, short);
- float overloaded(float, float);
- bool overloaded(bool, bool);
- int main()
- {
- cout << "\t\tWelcome to the warehouse program!" << endl << endl;
- cout << "Use this to enter the quantities of the four items we store here: basketballs, baseballs," << endl <<
- "baseball bats, and footballs. This information will be stored in a file so the info is retained" << endl;
- bool resetti_spaghetti = 0;
- short num;
- fstream file;
- while (resetti_spaghetti == 0)
- {
- num = menu();
- switch (num)
- {
- case 1:
- file.open("C:\\Users\\newport53494\\Desktop\\warehouse.txt", ios::out);
- fileOutput(file);
- file.close();
- break;
- case 2:
- file.open("C:\\Users\\newport53494\\Desktop\\warehouse.txt", ios::in);
- if (!file.is_open())
- {
- cout << "No warehouse file has been created" << endl;
- break;
- }
- else
- fileInput(file);
- file.close();
- break;
- case 3:
- overloadedMain();
- break;
- default:
- cout << "Press enter 5 times to exit...." << endl;
- cin.ignore(10, '\n');
- cin.get();
- for (short exitSequence = 4; exitSequence > 0; exitSequence--) //really hunting down those points aren't I?
- {
- cout << "Press enter " << exitSequence << " more times to exit...." << endl;
- cin.get();
- }
- resetti_spaghetti = 1;
- break;
- }
- cout << endl << endl;
- }
- }
- short menu()
- {
- short choice;
- cout << "\n\n\n\n\t\tWarehouse Menu" << endl << endl << endl;
- cout << "1.) Write onto the file" << endl;
- cout << "2.) Check quantities of items stored" << endl;
- cout << "3.) Overloaded function demonstration" << endl;
- cout << "4.) Exit program" << endl;
- cout << "Your choice: ";
- while (!(cin >> choice) || cin.fail() || choice > 4 || choice < 1)
- {
- cout << "Please enter a number 1 through 4" << endl;
- cin.clear();
- cin.sync();
- cin.ignore(100, '\n');
- }
- return choice;
- }
- void fileOutput(fstream &out)
- {
- int items;
- cout << "How many basketballs are stored?" << endl;
- while (!(cin >> items) || cin.fail() || items < 0)
- {
- cout << "Please enter a positive number" << endl;
- cin.clear();
- cin.sync();
- cin.ignore(100, '\n');
- }
- out << items << " ";
- cout << "How many baseballs are stored?" << endl;
- while (!(cin >> items) || cin.fail() || items < 0)
- {
- cout << "Please enter a positive number" << endl;
- cin.clear();
- cin.sync();
- cin.ignore(100, '\n');
- }
- out << items << " ";
- cout << "How many baseball bats are stored?" << endl;
- while (!(cin >> items) || cin.fail() || items < 0)
- {
- cout << "Please enter a positive number" << endl;
- cin.clear();
- cin.sync();
- cin.ignore(100, '\n');
- }
- out << items << " ";
- cout << "How many footballs are stored?" << endl;
- while (!(cin >> items) || cin.fail() || items < 0)
- {
- cout << "Please enter a positive number" << endl;
- cin.clear();
- cin.sync();
- cin.ignore(100, '\n');
- }
- out << items << " ";
- }
- void fileInput(fstream &in)
- {
- cout << endl << endl << endl;
- int itemsArr[2][2];
- in >> itemsArr[0][0];
- in >> itemsArr[0][1];
- in >> itemsArr[1][0];
- in >> itemsArr[1][1];
- cout << "Basketballs: " << itemsArr[0][0] << endl << "Baseballs: " << itemsArr[0][1] << endl;
- cout << "Baseball bats: " << itemsArr[1][0] << endl << "Footballs: " << itemsArr[1][1] << endl;
- cout << "Press enter to proceed....." << endl;
- cin.ignore(100, '\n');
- cin.get();
- }
- void overloadedMain()
- {
- short choice;
- cout << endl << "Select one of the following data types to use for the overloaded exponent function" << endl;
- cout << "1.) Short Int" << endl;
- cout << "2.) Float" << endl;
- cout << "3.) Bool" << endl;
- cout << "Your choice: ";
- while (!(cin >> choice) || cin.fail() || choice > 3 || choice < 1)
- {
- cout << "Please enter a choice 1 through 3" << endl;
- cin.clear();
- cin.sync();
- cin.ignore(100, '\n');
- }
- long float num1;
- long float num2;
- cout << endl << endl;
- cout << "Enter a number. Keep in mind that for the purposes of demonstrating that the function uses" << endl;
- cout << "multiple data types, it will be intentionally possible to overflow data" << endl;
- cout << "Base number: ";
- while (!(cin >> num1) || cin.fail())
- {
- cout << "Please enter a numeric value" << endl;
- cin.clear();
- cin.sync();
- cin.ignore(100, '\n');
- }
- cout << "Exponent: ";
- while (!(cin >> num2) || cin.fail())
- {
- cout << "Please enter a numeric value" << endl;
- cin.clear();
- cin.sync();
- cin.ignore(100, '\n');
- }
- cout << endl << endl << endl;
- if (choice == 1)
- cout << "The short data type answer to " << num1 << " to the power of " << num2 << " is " << overloaded((short)num1, (short)num2);
- else if (choice == 2)
- cout << "The float data type answer of " << num1 << " to the power of " << num2 << " is " << overloaded((float)num1, (float)num2);
- else
- 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";
- cout << "\n\nPress enter to proceed....." << endl;
- cin.ignore(100, '\n');
- cin.get();
- }
- short overloaded(short num1, short num2)
- {
- return pow(num1, num2);
- }
- float overloaded(float num1, float num2)
- {
- return pow(num1, num2);
- }
- bool overloaded(bool num1, bool num2)
- {
- return pow(num1, num2);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement