Advertisement
Guest User

SaleS build 1.3.3

a guest
Feb 8th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.55 KB | None | 0 0
  1. /*
  2. sales.cpp
  3. 2/8/2016, 1.3.2
  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. #include <assert.h>
  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. int getOptionSelection();
  29. void options();
  30. void optionMenuExec(int selection);
  31.  
  32. int main()
  33. {
  34.     //Greets user
  35.     welcomeScreen();
  36.     do
  37.     {
  38.         //sets selection to what the user enters, after being prompted
  39.         char selection = getMenuSelection();
  40.  
  41.         //uses what the user enters in, to be ran through the switch statement
  42.         menuExec(selection);
  43.     } while (1>0);
  44.  
  45.     system("pause");
  46.     return 0;
  47. }
  48.  
  49. /*************************************************
  50. Function: welcomeScreen
  51. Description:Greets the user
  52. Input: no input
  53. Precondition: no precondition
  54. Postcondition: prints out a greeting before returning
  55. *************************************************/
  56. void welcomeScreen()
  57. {
  58.     cout << "Welcome to the SaleS!\n\n";
  59.     return;
  60. }
  61.  
  62. /*************************************************
  63. Function:getMenuSelection
  64. Description: This will prompt the user with menu options
  65. Input: a single number char value
  66. Precondition: user input must be valid
  67. Postcondition: Returns selection, char value between 1-3, and char X
  68. *************************************************/
  69. char getMenuSelection()
  70. {
  71.     char selection = ' ';
  72.     do
  73.     {
  74.         cout.setf(ios::left);
  75.         cout << setw(40) << "What would you like to do?" << endl;
  76.         cout << setw(40) << "|Add a sales record" << setw(10) << "| 1" << endl;
  77.         cout << setw(40) << "|View a sales record" << setw(10) << "| 2" << endl;
  78.         cout << setw(40) << "|Options" << setw(10) << "| 3" << endl;
  79.         cout << setw(40) << "|Exit" << setw(10) << "| X" << endl;
  80.         cout << "-->|";
  81.         cin >> selection;
  82.         cout << endl;
  83.     }
  84.     //If an invalid char is entered, it will repeat. This allows for functions to not worry about values out of bounds
  85.     while (!(selection == '1' || selection == '2' || selection == '3' || selection == 'X' || selection == 'x'));
  86.  
  87.     return selection;
  88. }
  89.  
  90. /*************************************************
  91. Function: menuExec
  92. Description: This takes the char control, that the user entered, and runs it through a switch statement to carry out an action
  93. Input: char control
  94. Precondition: char control must be x, X, 1, 2, or 3
  95. Postcondition: Will run what the user selects
  96. *************************************************/
  97. void menuExec(char control)
  98. {
  99.     //converts the char values to int values, for use in switch statement. X = 0
  100.     int controlInt = charToInt(control);
  101.  
  102.  
  103.     //This allows for the switch statement to use Titles instead of numbers
  104.     enum menutitles{ EXIT, ADD, VIEW, OPTIONS };
  105.     switch (controlInt)
  106.     {
  107.     case EXIT:
  108.         system("pause");
  109.         exit(1);
  110.         break;
  111.     case ADD:
  112.         add();
  113.         break;
  114.     case VIEW:
  115.         cout << "view";
  116.         //**********************************************
  117.         // insert your function here
  118.         //**********************************************
  119.         break;
  120.     case OPTIONS:
  121.         getOptionSelection();
  122.         cout << "options";
  123.  
  124.         break;
  125.     }
  126.     return;
  127. }
  128.  
  129. /*************************************************
  130. Function: charToInt
  131. Description: Converts the user input to an int for the switch statement in menuExec
  132. Input: char control
  133. Precondition: char control must be x, X, 1, 2, or 3
  134. Postcondition: Converts 'x'||'X' = 0, '1' = 1, '2' = 2, '3' = 3
  135. *************************************************/
  136. int charToInt(char var)
  137. {
  138.     int control = 0;
  139.     if (var == 'X' || var == 'x')
  140.     {
  141.         control = 0;
  142.     }
  143.     else if (var == '1')
  144.     {
  145.         control = 1;
  146.     }
  147.     else if (var == '2')
  148.     {
  149.         control = 2;
  150.     }
  151.     else if (var == '3')
  152.     {
  153.         control = 3;
  154.     }
  155.     return control;
  156. }
  157.  
  158. /*************************************************
  159. Function: add
  160. Description: adds names and salary to txt
  161. Input: 2 strings and an int
  162. Precondition:called when add is selected by user
  163. Postcondition: adds entries to text
  164. *************************************************/
  165. //void add()
  166. //{
  167. //
  168. //
  169. //
  170. //  string sellerName1;
  171. //  string sellerName2;
  172. //  double sellerTotalSale = 0;
  173. //
  174. //  ofstream salesOutput;
  175. //
  176. //  salesOutput.open("SalesStats.txt", fstream::app);
  177. //
  178. //  cout << "Please Input First Then Last Name Of Salesperson: ";
  179. //
  180. //  cin.ignore();
  181. //  getline(cin, sellerName1);
  182. //
  183. //  salesOutput << endl << sellerName1 << "\n";
  184. //
  185. //  cout << "Please Input Total Sales Of Salesperson: ";
  186. //  cin >> sellerTotalSale;
  187. //  cin.ignore();
  188. //
  189. //
  190. //  salesOutput << sellerTotalSale;
  191. //  cout << endl;
  192. //  salesOutput.close();
  193. //  return;
  194. //
  195. //}
  196.  
  197. /*************************************************
  198. Function: add
  199. Description: adds names and salary to txt
  200. Input: 2 strings and an int
  201. Precondition:called when add is selected by user
  202. Postcondition: adds entries to text
  203. *************************************************/
  204. void add()
  205. {
  206.     //Revised Jesse's function
  207.     //Declare stream
  208.     ofstream nameOutput;
  209.     ofstream salaryOutput;
  210.     //Open file SalesStats.txt
  211.     nameOutput.open("names.txt", fstream::app);
  212.     salaryOutput.open("Sales.txt", fstream::app);
  213.     //defining Arrays with 100 spaces
  214.     string name[100];
  215.     double salary[100];
  216.  
  217.     int entryAmt = 0;
  218.  
  219.  
  220.     cout << "|How many entries are to be added?\n-->|";
  221.     cin >> entryAmt;
  222.     cout << endl;
  223.     //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]
  224.     for (int c = 0; c < entryAmt; c++)
  225.     {
  226.         cout << "Please Input First Then Last Name Of Salesperson: ";
  227.         //I dont know what the fuck this does, but it is needed
  228.         cin.ignore();
  229.         //This allows for a whole line (including whitespaces) to be stored
  230.         getline(cin, name[c]);
  231.         //prints out an end line character
  232.         nameOutput << name[c] << '\n';
  233.         cout << "Please Input Total Sales Of Salesperson: ";
  234.         cin >> salary[c];
  235.         salaryOutput << salary[c] << '\n';
  236.         cout << endl;
  237.     }
  238. }
  239. /*************************************************
  240. Function: Option
  241. Description: gets user input for options
  242. Input: char selection
  243. Precondition:must be called before optionMenuExec
  244. Postcondition: calls charToInt, and passes parameter to execOptionMenu
  245. *************************************************/
  246. void options()
  247. {
  248.     int selection = getOptionSelection();
  249.     optionMenuExec(selection);
  250.     return;
  251. }
  252.  
  253. /*************************************************
  254. Function: getOptionSelection
  255. Description: gets user input for options
  256. Input: char selection
  257. Precondition:must be called before optionMenuExec
  258. Postcondition: calls charToInt, and passes parameter to execOptionMenu
  259. *************************************************/
  260. int getOptionSelection()
  261. {
  262.     char selection = ' ';
  263.     do
  264.     {
  265.         cout.setf(ios::left);
  266.         cout << setw(40) << "What would you like to do?" << endl;
  267.         cout << setw(40) << "|Change Currency" << setw(10) << "| 1" << endl;
  268.         cout << setw(40) << "|Change system color" << setw(10) << "| 2" << endl;
  269.         cout << setw(40) << "|Change language" << setw(10) << "| 3" << endl;
  270.         cout << setw(40) << "|Exit" << setw(10) << "| X" << endl;
  271.         cout << "-->|";
  272.         cin >> selection;
  273.         cout << endl;
  274.     }
  275.     //If an invalid char is entered, it will repeat. This allows for functions to not worry about values out of bounds
  276.     while (!(selection == '1' || selection == '2' || selection == '3' || selection == 'X' || selection == 'x'));
  277.     //converts to int before returning
  278.     charToInt(selection);
  279.     return selection;
  280. }
  281.  
  282. /*************************************************
  283. Function: optionsMenuExec
  284. Description: Prompts for options
  285. Input: Int selection
  286. Precondition: Must be called
  287. Postcondition: Calls option stuff
  288. *************************************************/
  289. void optionMenuExec(int selection)
  290. {
  291.     enum menutitles{ EXIT, CURR, SYS_COLOR, LANG };
  292.     switch (selection)
  293.     {
  294.     case EXIT:
  295.         exit(1);
  296.         break;
  297.     case CURR:
  298.  
  299.         cout << "curr";
  300.         break;
  301.     case SYS_COLOR:
  302.         cout << "system color";
  303.  
  304.         break;
  305.     case LANG:
  306.         cout << "language";
  307.  
  308.         break;
  309.     }
  310.     return;
  311. }
  312.  
  313. /**************************************************************************************
  314. =======================================================================================
  315. _____                                      _
  316. / ____|                                    | |
  317. | (___  _ __   __ _ _ __ ___    ___ ___   __| | ___
  318. \___ \| '_ \ / _` | '__/ _ \  / __/ _ \ / _` |/ _ \
  319. ____) | |_) | (_| | | |  __/ | (_| (_) | (_| |  __/
  320. |_____/| .__/ \__,_|_|  \___|  \___\___/ \__,_|\___|
  321. | |
  322. |_|
  323. and experimentals
  324. =======================================================================================
  325. ***************************************************************************************/
  326.  
  327. /*************************************************
  328. Function: convertUSD
  329. Description: Converts any usd value to whatever currency (conversions at the top, as const ints)
  330. Input: usd, and amount constant. IE: convertUSD(usdAmount, CAN);
  331. Precondition: Must have US dollar amount as first parameter, and all caps constant as second parameter.
  332. Postcondition: Pass by reference first parameter. WARNING: REMEMBER TO CHANGE CURR SIGN,($, £, etc)
  333. *************************************************/
  334.  
  335. void convertUSD(double& curr, double conversionCurr)
  336. {
  337.     curr = curr * conversionCurr;
  338.     cout << curr;
  339.     return;
  340. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement