Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- sales.cpp
- 2/8/2016, 1.3.2
- Steven Piper, Jordan Prokop, Jesse Winter
- */
- #include <iostream>
- #include <stdlib.h>
- #include <fstream>
- #include <iomanip>
- #include <cmath>
- #include <string>
- #include <assert.h>
- using namespace std;
- //conversion rates. Just multiply any usd amount by whatever currency, to convert it to that currency
- double const USD = 1.0;
- double const CAN = 1.39;
- double const BTC = 0.002664;
- double const GBP = 0.69;
- void add();
- //void convertUSD(double& curr, double conversionCurr);
- //prototypes
- void welcomeScreen();
- char getMenuSelection();
- void menuExec(char control);
- int charToInt(char var);
- int getOptionSelection();
- void options();
- void optionMenuExec(int selection);
- int main()
- {
- //Greets user
- welcomeScreen();
- do
- {
- //sets selection to what the user enters, after being prompted
- char selection = getMenuSelection();
- //uses what the user enters in, to be ran through the switch statement
- menuExec(selection);
- } while (1>0);
- system("pause");
- return 0;
- }
- /*************************************************
- Function: welcomeScreen
- Description:Greets the user
- Input: no input
- Precondition: no precondition
- Postcondition: prints out a greeting before returning
- *************************************************/
- void welcomeScreen()
- {
- cout << "Welcome to the SaleS!\n\n";
- return;
- }
- /*************************************************
- Function:getMenuSelection
- Description: This will prompt the user with menu options
- Input: a single number char value
- Precondition: user input must be valid
- Postcondition: Returns selection, char value between 1-3, and char X
- *************************************************/
- char getMenuSelection()
- {
- char selection = ' ';
- do
- {
- cout.setf(ios::left);
- cout << setw(40) << "What would you like to do?" << endl;
- cout << setw(40) << "|Add a sales record" << setw(10) << "| 1" << endl;
- cout << setw(40) << "|View a sales record" << setw(10) << "| 2" << endl;
- cout << setw(40) << "|Options" << setw(10) << "| 3" << endl;
- cout << setw(40) << "|Exit" << setw(10) << "| X" << endl;
- cout << "-->|";
- cin >> selection;
- cout << endl;
- }
- //If an invalid char is entered, it will repeat. This allows for functions to not worry about values out of bounds
- while (!(selection == '1' || selection == '2' || selection == '3' || selection == 'X' || selection == 'x'));
- return selection;
- }
- /*************************************************
- Function: menuExec
- Description: This takes the char control, that the user entered, and runs it through a switch statement to carry out an action
- Input: char control
- Precondition: char control must be x, X, 1, 2, or 3
- Postcondition: Will run what the user selects
- *************************************************/
- void menuExec(char control)
- {
- //converts the char values to int values, for use in switch statement. X = 0
- int controlInt = charToInt(control);
- //This allows for the switch statement to use Titles instead of numbers
- enum menutitles{ EXIT, ADD, VIEW, OPTIONS };
- switch (controlInt)
- {
- case EXIT:
- system("pause");
- exit(1);
- break;
- case ADD:
- add();
- break;
- case VIEW:
- cout << "view";
- //**********************************************
- // insert your function here
- //**********************************************
- break;
- case OPTIONS:
- getOptionSelection();
- cout << "options";
- break;
- }
- return;
- }
- /*************************************************
- Function: charToInt
- Description: Converts the user input to an int for the switch statement in menuExec
- Input: char control
- Precondition: char control must be x, X, 1, 2, or 3
- Postcondition: Converts 'x'||'X' = 0, '1' = 1, '2' = 2, '3' = 3
- *************************************************/
- int charToInt(char var)
- {
- int control = 0;
- if (var == 'X' || var == 'x')
- {
- control = 0;
- }
- else if (var == '1')
- {
- control = 1;
- }
- else if (var == '2')
- {
- control = 2;
- }
- else if (var == '3')
- {
- control = 3;
- }
- return control;
- }
- /*************************************************
- Function: add
- Description: adds names and salary to txt
- Input: 2 strings and an int
- Precondition:called when add is selected by user
- Postcondition: adds entries to text
- *************************************************/
- //void add()
- //{
- //
- //
- //
- // string sellerName1;
- // string sellerName2;
- // double sellerTotalSale = 0;
- //
- // ofstream salesOutput;
- //
- // salesOutput.open("SalesStats.txt", fstream::app);
- //
- // cout << "Please Input First Then Last Name Of Salesperson: ";
- //
- // cin.ignore();
- // getline(cin, sellerName1);
- //
- // salesOutput << endl << sellerName1 << "\n";
- //
- // cout << "Please Input Total Sales Of Salesperson: ";
- // cin >> sellerTotalSale;
- // cin.ignore();
- //
- //
- // salesOutput << sellerTotalSale;
- // cout << endl;
- // salesOutput.close();
- // return;
- //
- //}
- /*************************************************
- Function: add
- Description: adds names and salary to txt
- Input: 2 strings and an int
- Precondition:called when add is selected by user
- Postcondition: adds entries to text
- *************************************************/
- void add()
- {
- //Revised Jesse's function
- //Declare stream
- ofstream nameOutput;
- ofstream salaryOutput;
- //Open file SalesStats.txt
- nameOutput.open("names.txt", fstream::app);
- salaryOutput.open("Sales.txt", fstream::app);
- //defining Arrays with 100 spaces
- string name[100];
- double salary[100];
- int entryAmt = 0;
- cout << "|How many entries are to be added?\n-->|";
- cin >> entryAmt;
- cout << endl;
- //This loop will store the values in the arrays, and read them out to two seperate files. When read, it should read in the same values at the same index. IE name[6] corresponds to salary[6]
- for (int c = 0; c < entryAmt; c++)
- {
- cout << "Please Input First Then Last Name Of Salesperson: ";
- //I dont know what the fuck this does, but it is needed
- cin.ignore();
- //This allows for a whole line (including whitespaces) to be stored
- getline(cin, name[c]);
- //prints out an end line character
- nameOutput << name[c] << '\n';
- cout << "Please Input Total Sales Of Salesperson: ";
- cin >> salary[c];
- salaryOutput << salary[c] << '\n';
- cout << endl;
- }
- }
- /*************************************************
- Function: Option
- Description: gets user input for options
- Input: char selection
- Precondition:must be called before optionMenuExec
- Postcondition: calls charToInt, and passes parameter to execOptionMenu
- *************************************************/
- void options()
- {
- int selection = getOptionSelection();
- optionMenuExec(selection);
- return;
- }
- /*************************************************
- Function: getOptionSelection
- Description: gets user input for options
- Input: char selection
- Precondition:must be called before optionMenuExec
- Postcondition: calls charToInt, and passes parameter to execOptionMenu
- *************************************************/
- int getOptionSelection()
- {
- char selection = ' ';
- do
- {
- cout.setf(ios::left);
- cout << setw(40) << "What would you like to do?" << endl;
- cout << setw(40) << "|Change Currency" << setw(10) << "| 1" << endl;
- cout << setw(40) << "|Change system color" << setw(10) << "| 2" << endl;
- cout << setw(40) << "|Change language" << setw(10) << "| 3" << endl;
- cout << setw(40) << "|Exit" << setw(10) << "| X" << endl;
- cout << "-->|";
- cin >> selection;
- cout << endl;
- }
- //If an invalid char is entered, it will repeat. This allows for functions to not worry about values out of bounds
- while (!(selection == '1' || selection == '2' || selection == '3' || selection == 'X' || selection == 'x'));
- //converts to int before returning
- charToInt(selection);
- return selection;
- }
- /*************************************************
- Function: optionsMenuExec
- Description: Prompts for options
- Input: Int selection
- Precondition: Must be called
- Postcondition: Calls option stuff
- *************************************************/
- void optionMenuExec(int selection)
- {
- enum menutitles{ EXIT, CURR, SYS_COLOR, LANG };
- switch (selection)
- {
- case EXIT:
- exit(1);
- break;
- case CURR:
- cout << "curr";
- break;
- case SYS_COLOR:
- cout << "system color";
- break;
- case LANG:
- cout << "language";
- break;
- }
- return;
- }
- /**************************************************************************************
- =======================================================================================
- _____ _
- / ____| | |
- | (___ _ __ __ _ _ __ ___ ___ ___ __| | ___
- \___ \| '_ \ / _` | '__/ _ \ / __/ _ \ / _` |/ _ \
- ____) | |_) | (_| | | | __/ | (_| (_) | (_| | __/
- |_____/| .__/ \__,_|_| \___| \___\___/ \__,_|\___|
- | |
- |_|
- and experimentals
- =======================================================================================
- ***************************************************************************************/
- /*************************************************
- Function: convertUSD
- Description: Converts any usd value to whatever currency (conversions at the top, as const ints)
- Input: usd, and amount constant. IE: convertUSD(usdAmount, CAN);
- Precondition: Must have US dollar amount as first parameter, and all caps constant as second parameter.
- Postcondition: Pass by reference first parameter. WARNING: REMEMBER TO CHANGE CURR SIGN,($, £, etc)
- *************************************************/
- void convertUSD(double& curr, double conversionCurr)
- {
- curr = curr * conversionCurr;
- cout << curr;
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement