Advertisement
Guest User

SaleS build 1.1.0

a guest
Feb 7th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.77 KB | None | 0 0
  1. /*
  2. sales.cpp
  3. 2/7/2016, 1.1.0
  4. Steven Piper, Jordan Prokop, Jesse Winter
  5. */
  6. #include <iostream>
  7. #include <stdlib.h>
  8. #include <fstream>
  9. #include <iomanip>
  10. #include <cmath>
  11. #include <string>
  12.  
  13. using namespace std;
  14.  
  15. //conversion rates. Just multiply any usd amount by whatever currency, to convert it to that currency
  16. double const USD = 1.0;
  17. double const CAN = 1.39;
  18. double const BTC = 0.002664;
  19. double const GBP = 0.69;
  20. void add();
  21. //void convertUSD(double& curr, double conversionCurr);
  22.  
  23. //prototypes
  24. void welcomeScreen();
  25. char getMenuSelection();
  26. void menuExec(char control);
  27. int charToInt(char var);
  28.  
  29. int main()
  30. {
  31.     //Greets user
  32.     welcomeScreen();
  33.     do
  34.     {
  35.         //sets selection to what the user enters, after being prompted
  36.         char selection = getMenuSelection();
  37.  
  38.         //uses what the user enters in, to be ran through the switch statement
  39.         menuExec(selection);
  40.     }
  41.     while (1>0);
  42.  
  43.     system("pause");
  44.     return 0;
  45. }
  46.  
  47. /*************************************************
  48. Function: welcomeScreen
  49. Description:Greets the user
  50. Input: no input
  51. Precondition: no precondition
  52. Postcondition: prints out a greeting before returning
  53. *************************************************/
  54. void welcomeScreen()
  55. {
  56.     cout << "Welcome to the SaleS!\n\n";
  57.     return;
  58. }
  59.  
  60. /*************************************************
  61. Function:getMenuSelection
  62. Description: This will prompt the user with menu options
  63. Input: a single number char value
  64. Precondition: user input must be valid
  65. Postcondition: Returns selection, char value between 1-3, and char X
  66. *************************************************/
  67. char getMenuSelection()
  68. {
  69.     char selection = ' ';
  70.     do
  71.     {
  72.         cout.setf(ios::left);
  73.         cout << setw(40) << "What would you like to do?" << endl;
  74.         cout << setw(40) << "|Add a sales record" << setw(10) << "| 1" << endl;
  75.         cout << setw(40) << "|View a sales record" << setw(10) << "| 2" << endl;
  76.         cout << setw(40) << "|Options" << setw(10) << "| 3" << endl;
  77.         cout << setw(40) << "|Exit" << setw(10) << "| X" << endl;
  78.         cout << "-->|";
  79.         cin >> selection;
  80.         cout << endl;
  81.     }
  82.     //If an invalid char is entered, it will repeat. This allows for functions to not worry about values out of bounds
  83.     while (!(selection == '1' || selection == '2' || selection == '3' || selection == 'X' || selection == 'x'));
  84.    
  85.     return selection;
  86. }
  87.  
  88. /*************************************************
  89. Function: menuExec
  90. Description: This takes the char control, that the user entered, and runs it through a switch statement to carry out an action
  91. Input: char control
  92. Precondition: char control must be x, X, 1, 2, or 3
  93. Postcondition: Will run what the user selects
  94. *************************************************/
  95. void menuExec(char control)
  96. {
  97.     //converts the char values to int values, for use in switch statement. X = 0
  98.     int controlInt = charToInt(control);
  99.  
  100.  
  101.     //This allows for the switch statement to use Titles instead of numbers
  102.     enum menutitles{EXIT, ADD, VIEW, OPTIONS};
  103.     switch (controlInt)
  104.     {
  105.     case EXIT:
  106.         system("pause");
  107.         exit (1);
  108.         break;
  109.     case ADD:
  110.         add();
  111.         break;
  112.     case VIEW:
  113.         cout << "view";
  114.         //**********************************************
  115.         // insert your function here
  116.         //**********************************************
  117.         break;
  118.     case OPTIONS:
  119.         cout << "options";
  120.  
  121.         break;
  122.     }
  123.     return;
  124. }
  125.  
  126. /*************************************************
  127. Function: charToInt
  128. Description: Converts the user input to an int for the switch statement in menuExec
  129. Input: char control
  130. Precondition: char control must be x, X, 1, 2, or 3
  131. Postcondition: Converts 'x'||'X' = 0, '1' = 1, '2' = 2, '3' = 3
  132. *************************************************/
  133. int charToInt(char var)
  134. {
  135.     int control = 0;
  136.     if (var == 'X' || var == 'x')
  137.     {
  138.         control = 0;
  139.     }
  140.     else if (var == '1')
  141.     {
  142.         control = 1;
  143.     }
  144.     else if (var == '2')
  145.     {
  146.         control = 2;
  147.     }
  148.     else if (var == '3')
  149.     {
  150.         control = 3;
  151.     }
  152.     return control;
  153. }
  154.  
  155. void add()
  156. {
  157.  
  158.     string sellerName1;
  159.     string sellerName2;
  160.     double sellerTotalSale = 0;
  161.  
  162.     ofstream salesOutput;
  163.  
  164.     salesOutput.open("SalesStats.txt", fstream::app);
  165.  
  166.     cout << "Please Input First Then Last Name Of Salesperson: ";
  167.     cin >> sellerName1;
  168.     cin >> sellerName2;
  169.  
  170.     salesOutput << endl << sellerName1 << " " << sellerName2 << " - ";
  171.  
  172.     cout << "Please Input Total Sales Of Salesperson: ";
  173.     cin >> sellerTotalSale;
  174.  
  175.     salesOutput << sellerTotalSale;
  176.  
  177.     salesOutput.close();
  178.     return;
  179.  
  180. }
  181.  
  182. /**************************************************************************************
  183. =======================================================================================
  184.    _____                                      _      
  185.   / ____|                                    | |    
  186.  | (___  _ __   __ _ _ __ ___    ___ ___   __| | ___
  187.   \___ \| '_ \ / _` | '__/ _ \  / __/ _ \ / _` |/ _ \
  188.   ____) | |_) | (_| | | |  __/ | (_| (_) | (_| |  __/
  189.  |_____/| .__/ \__,_|_|  \___|  \___\___/ \__,_|\___|
  190.         | |                                          
  191.         |_|
  192. and experimentals
  193. =======================================================================================
  194. ***************************************************************************************/
  195.  
  196. /*************************************************
  197. Function: convertUSD
  198. Description: Converts any usd value to whatever currency (conversions at the top, as const ints)
  199. Input: usd, and amount constant. IE: convertUSD(usdAmount, CAN);
  200. Precondition: Must have US dollar amount as first parameter, and all caps constant as second parameter.
  201. Postcondition: Pass by reference first parameter. WARNING: REMEMBER TO CHANGE CURR SIGN,($, £, etc)
  202. *************************************************/
  203.  
  204. /*
  205.  
  206. void convertUSD(double& curr, double conversionCurr)
  207. {
  208.     curr = curr * conversionCurr;
  209.     cout << curr;
  210.     return;
  211. }
  212.  
  213. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement