Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 24.63 KB | None | 0 0
  1.  
  2.  
  3. //Comments before submission: check the ordering of inputted variables to function, procedure calls
  4. //Look at the change_due integers
  5.  
  6. #include <iostream>
  7. #include <cmath>
  8. #include <fstream>
  9. #include <string>
  10. using namespace std;
  11.  
  12. /*
  13. Read initial inventory from: inventory.txt
  14. Read list of transactions from: transactions.txt
  15.  
  16. Results should be outputted to:
  17. report_log.txt - reports transactions
  18. final_inventory.txt - contains what's left and current moeny
  19. */
  20.  
  21. /*Transaction IDs
  22. 'I' - Insert cash in demonations of quarters, dimes, and nickels
  23. 'S' - Select an item to buy, calculate/dispense change (if needed), dispense the time
  24. 'L' - list the machine's current inventory
  25. 'O' - order items running low and replenish stock to the machine's inventory
  26. 'Q' - quit the program
  27. */
  28.  
  29. /* Note:
  30. If something other than 25, 10, or 5 is inserted, display message and quit.
  31. Inventory file will be in this format
  32.  
  33. <Quarters> <dimes> <nickels>
  34. <item>      <quantity>
  35. <item>      <quantity>
  36. ...
  37.  
  38. <item> is expressed as an integer
  39. <quanitity> is the intial quantity of the corresponding item, expressed as an integer
  40.  
  41. Initialize all items to quantity of 0.
  42. Text file may contain no items
  43. */
  44.  
  45.  
  46. ifstream transaction("transaction.txt");   
  47. ifstream inventory("inventory.txt");
  48. ofstream report("report_log.txt");
  49. ofstream final("final_inventory.txt");
  50.  
  51. const int pop = 1; 
  52. const int iced_tea = 2;
  53. const int water = 3;
  54. const int cereal_bar = 4;
  55. const int chips = 5;
  56. const int gum = 6;
  57.  
  58.  
  59. /*Function to calculate cost of item
  60. *******************************************************************************************/
  61. int cost_of_item (int item_number){
  62. int item_cost = 0;
  63.  
  64. if (item_number == 1 or item_number == 2 or item_number == 3)
  65. item_cost = 140;
  66. else if (item_number == 4)
  67. item_cost = 80;
  68. else if (item_number == 5)
  69. item_cost = 75;
  70. else if (item_number == 6)
  71. item_cost = 50;
  72. else
  73. exit(0);
  74.  
  75.  
  76. return item_cost;
  77. }
  78. /*******************************************************************************************
  79.  
  80.  
  81.  
  82.  
  83. /*Transaction 'I'
  84. **************************************************************************************************************/
  85. void transaction_I (int integer, int & nickels, int & dimes, int & quarters, int & nickels_c, int & dimes_c, int & quarters_c){
  86. if ( integer / 5 == 1){ //Adds to total amount of Qs,Ns, and Ds available, as well as add total to Qs, Ns, and Ds user inputted himself
  87. nickels++;
  88. nickels_c++;}
  89. else if (integer / 10 == 1){
  90. dimes++;
  91. dimes_c++;}
  92. else if (integer / 25 == 1){
  93. quarters++;
  94. dimes_c++;}
  95. else {
  96. cout << "Error: Machine only accepts quarters, dimes, and nickels!";
  97. exit(0);}
  98.  
  99. return;
  100. }
  101. /*************************************************************************************************************
  102.  
  103. /*Transaction 'S'
  104. *****************************************************************************************/
  105. void transaction_S (int integer, int & money_inserted, int & number_of_pop, int & number_of_iced_tea, int & number_of_water,
  106.            int & number_of_cereal_bar, int & number_of_chips, int & number_of_gum, int & available_change,
  107.            int & quarters, int & nickels, int & dimes, int & quarters_c, int & dimes_c, int & nickels_c){
  108. int cost;
  109.  
  110. double money_inserted_dollars = money_inserted / 100.0;     //converts into dollar amount
  111. cost = cost_of_item (integer);  //Calculates cost of item
  112.  
  113. //This serves as the example of functions each item must go through
  114. if (integer == 1){
  115.     if (number_of_pop = 0){     //If # of item in stock is 0, consumer is requested to make another selection. This gets reported to report file
  116.     report<<"Item out of stock!"<<endl<<"Please make another selection."<<endl;}
  117.     if (number_of_pop > 0){     //If # of item in stock is greater than 0, then it goes through a long list of alogrithms...
  118.         if (cost > money_inserted){     //If the cost is greater than the money the consumer put in, they are request to make another selection
  119.         report<<"Money inserted: $"<<money_inserted_dollars<<endl;
  120.         report<<"Item selected for purchase: Pop"<<endl;
  121.         report<<"Insufficient funds!"<<endl;
  122.         report<<"Please make another selection."<<endl;}
  123.         else if (cost = money_inserted){        //If the cost of item equals the money the consumer put in, then exact change is made
  124.         report<<"Money inserted: $"<<money_inserted_dollars<<endl;  //No change is neccessary. One unit of the item is subtracted from stock
  125.         report<<"Item selected for purchase: Pop"<<endl;
  126.         report<<"Exact change"<<endl;
  127.         money_inserted = 0;
  128.         number_of_pop--;}
  129.         else if (cost < money_inserted){        //If the cost of the item is less than the money inserted, then a list of algorithms are initiated...
  130.             if ( (money_inserted - cost) > available_change){   //If the difference between money inserted by consumer and the item cost
  131.             report<<"Money inserted: $"<<money_inserted_dollars<<endl; //is greater than the available amount of change. Then vending machine will
  132.             report<<"Item selected for purchase: Pop"<<endl;       //report that it is unable to make the correct amount of change and ask the
  133.             report<<"Unable to return correct change!"<<endl;      //consumer to make another selection.
  134.             report<<"Please make another selection."<<endl;}
  135.            
  136.             else if ((money_inserted - cost) < available_change){   //If the difference between the money inserted by the consumer and the item cost
  137.                                         //is less than the available change, yet another list of alogorithms are initiated...
  138.                                
  139.             int change_due = money_inserted - cost;         //The best combination of change that can be made from the available amount of change
  140.             int change_in_quarters = change_due / 25;       //in stock is calculated and determined here.
  141.             while (change_in_quarters >= quarters) {
  142.             change_in_quarters--;}
  143.             change_due = change_due - (change_in_quarters * 25);
  144.            
  145.             int change_in_dimes = change_due / 10;
  146.             while (change_in_dimes >= dimes){
  147.             change_in_dimes--;}
  148.             change_due = change_due - (change_in_dimes * 10) ;
  149.  
  150.             int change_in_nickels = change_due / 5;
  151.             while (change_in_nickels >= nickels){
  152.             change_in_nickels--;}
  153.             change_due = change_due - (change_in_nickels * 25);
  154.  
  155.                 if (change_due > 0){                //If the amount of change that is due is greater than 0, the vending machine will know that
  156.                                         //it could not give exact change and ask the consumer to make another selection
  157.                 report<<"Money inserted: $"<<money_inserted_dollars<<endl;
  158.                 report<<"Item selected for purchase: Pop"<<endl;
  159.                 report<<"Unable to return correct change!"<<endl;
  160.                 report<<"Please make another selection."<<endl;}
  161.                 else {                      //Otherwise, quarters, dimes, and nickels available in the machine is updated, and consumer
  162.                 quarters = quarters - change_in_quarters;   //is told how much he or she got back in change
  163.                 dimes = dimes - change_in_dimes;       
  164.                 nickels = nickels - change_in_nickels;
  165.                 report<<"Money inserted: $"<<money_inserted_dollars<<endl;
  166.                 report<<"Item selected for pruchase: Pop"<<endl;
  167.                 report<<"Change dispensed: "<<change_in_quarters<<" "
  168.                 <<change_in_dimes<<" "<<change_in_nickels<<" "<<endl;
  169.                 number_of_pop--;}}}}}               //The amount of the item in stock is subtracted by one.
  170.  
  171. if (integer == 2){
  172.     if (number_of_iced_tea = 0){
  173.     report<<"Item out of stock!"<<endl<<"Please make another selection."<<endl;}
  174.     if (number_of_iced_tea > 0){
  175.         if (cost > money_inserted){
  176.         report<<"Money inserted: $"<<money_inserted_dollars<<endl;
  177.         report<<"Item selected for purchase: Iced Tea"<<endl;
  178.         report<<"Insufficient funds!"<<endl;
  179.         report<<"Please make another selection."<<endl;}
  180.         else if (cost = money_inserted){
  181.         report<<"Money inserted: $"<<money_inserted_dollars<<endl;
  182.         report<<"Item selected for purchase: Iced Tea"<<endl;
  183.         report<<"Exact change"<<endl;
  184.         money_inserted = 0;
  185.         number_of_iced_tea--;}
  186.         else if (cost < money_inserted){
  187.             if ( (money_inserted - cost) > available_change){
  188.             report<<"Money inserted: $"<<money_inserted_dollars<<endl;
  189.             report<<"Item selected for purchase: Iced Tea"<<endl;
  190.             report<<"Unable to return correct change!"<<endl;
  191.             report<<"Please make another selection."<<endl;}
  192.            
  193.             else if ((money_inserted - cost) < available_change){
  194.             int change_due = money_inserted - cost;
  195.             int change_in_quarters = change_due / 25;
  196.             while (change_in_quarters >= quarters) {
  197.             change_in_quarters--;}
  198.             change_due = change_due - (change_in_quarters * 25);
  199.            
  200.             int change_in_dimes = change_due / 10;
  201.             while (change_in_dimes >= dimes){
  202.             change_in_dimes--;}
  203.             change_due = change_due - (change_in_dimes * 10) ;
  204.  
  205.             int change_in_nickels = change_due / 5;
  206.             while (change_in_nickels >= nickels){
  207.             change_in_nickels--;}
  208.             change_due = change_due - (change_in_nickels * 25);
  209.  
  210.                 if (change_due > 0){
  211.                 report<<"Money inserted: $"<<money_inserted_dollars<<endl;
  212.                 report<<"Item selected for purchase: Iced Tea"<<endl;
  213.                 report<<"Unable to return correct change!"<<endl;
  214.                 report<<"Please make another selection."<<endl;}
  215.                 else {
  216.                 quarters = quarters - change_in_quarters;
  217.                 dimes = dimes - change_in_dimes;
  218.                 nickels = nickels - change_in_nickels;
  219.                 report<<"Money inserted: $"<<money_inserted_dollars<<endl;
  220.                 report<<"Item selected for pruchase: Iced Tea"<<endl;
  221.                 report<<"Change dispensed: "<<change_in_quarters<<" "
  222.                 <<change_in_dimes<<" "<<change_in_nickels<<" "<<endl;
  223.                 number_of_iced_tea--;}}}}}
  224.  
  225. if (integer == 3){
  226.     if (number_of_water = 0){
  227.     report<<"Item out of stock!"<<endl<<"Please make another selection."<<endl;}
  228.     if (number_of_water > 0){
  229.         if (cost > money_inserted){
  230.         report<<"Money inserted: $"<<money_inserted_dollars<<endl;
  231.         report<<"Item selected for purchase: Water"<<endl;
  232.         report<<"Insufficient funds!"<<endl;
  233.         report<<"Please make another selection."<<endl;}
  234.         else if (cost = money_inserted){
  235.         report<<"Money inserted: $"<<money_inserted_dollars<<endl;
  236.         report<<"Item selected for purchase: Water"<<endl;
  237.         report<<"Exact change"<<endl;
  238.         money_inserted = 0;
  239.         number_of_water--;}
  240.         else if (cost < money_inserted){
  241.             if ( (money_inserted - cost) > available_change){
  242.             report<<"Money inserted: $"<<money_inserted_dollars<<endl;
  243.             report<<"Item selected for purchase: Water"<<endl;
  244.             report<<"Unable to return correct change!"<<endl;
  245.             report<<"Please make another selection."<<endl;}
  246.            
  247.             else if ((money_inserted - cost) < available_change){
  248.             int change_due = money_inserted - cost;
  249.             int change_in_quarters = change_due / 25;
  250.             while (change_in_quarters >= quarters) {
  251.             change_in_quarters--;}
  252.             change_due = change_due - (change_in_quarters * 25);
  253.            
  254.             int change_in_dimes = change_due / 10;
  255.             while (change_in_dimes >= dimes){
  256.             change_in_dimes--;}
  257.             change_due = change_due - (change_in_dimes * 10) ;
  258.  
  259.             int change_in_nickels = change_due / 5;
  260.             while (change_in_nickels >= nickels){
  261.             change_in_nickels--;}
  262.             change_due = change_due - (change_in_nickels * 25);
  263.  
  264.                 if (change_due > 0){
  265.                 report<<"Money inserted: $"<<money_inserted_dollars<<endl;
  266.                 report<<"Item selected for purchase: Water"<<endl;
  267.                 report<<"Unable to return correct change!"<<endl;
  268.                 report<<"Please make another selection."<<endl;}
  269.                 else {
  270.                 quarters = quarters - change_in_quarters;
  271.                 dimes = dimes - change_in_dimes;
  272.                 nickels = nickels - change_in_nickels;
  273.                 report<<"Money inserted: $"<<money_inserted_dollars<<endl;
  274.                 report<<"Item selected for pruchase: Water"<<endl;
  275.                 report<<"Change dispensed: "<<change_in_quarters<<" "
  276.                 <<change_in_dimes<<" "<<change_in_nickels<<" "<<endl;
  277.                 number_of_water--;}}}}}
  278. if (integer == 4){
  279.     if (number_of_cereal_bar = 0){
  280.     report<<"Item out of stock!"<<endl<<"Please make another selection."<<endl;}
  281.     if (number_of_cereal_bar > 0){
  282.         if (cost > money_inserted){
  283.         report<<"Money inserted: $"<<money_inserted_dollars<<endl;
  284.         report<<"Item selected for purchase: Cereal Bar"<<endl;
  285.         report<<"Insufficient funds!"<<endl;
  286.         report<<"Please make another selection."<<endl;}
  287.         else if (cost = money_inserted){
  288.         report<<"Money inserted: $"<<money_inserted_dollars<<endl;
  289.         report<<"Item selected for purchase: Cereal Bar"<<endl;
  290.         report<<"Exact change"<<endl;
  291.         money_inserted = 0;
  292.         number_of_cereal_bar--;}
  293.         else if (cost < money_inserted){
  294.             if ( (money_inserted - cost) > available_change){
  295.             report<<"Money inserted: $"<<money_inserted_dollars<<endl;
  296.             report<<"Item selected for purchase: Cereal Bar"<<endl;
  297.             report<<"Unable to return correct change!"<<endl;
  298.             report<<"Please make another selection."<<endl;}
  299.            
  300.             else if ((money_inserted - cost) < available_change){
  301.             int change_due = money_inserted - cost;
  302.             int change_in_quarters = change_due / 25;
  303.             while (change_in_quarters >= quarters) {
  304.             change_in_quarters--;}
  305.             change_due = change_due - (change_in_quarters * 25);
  306.            
  307.             int change_in_dimes = change_due / 10;
  308.             while (change_in_dimes >= dimes){
  309.             change_in_dimes--;}
  310.             change_due = change_due - (change_in_dimes * 10) ;
  311.  
  312.             int change_in_nickels = change_due / 5;
  313.             while (change_in_nickels >= nickels){
  314.             change_in_nickels--;}
  315.             change_due = change_due - (change_in_nickels * 25);
  316.  
  317.                 if (change_due > 0){
  318.                 report<<"Money inserted: $"<<money_inserted_dollars<<endl;
  319.                 report<<"Item selected for purchase: Cereal Bar"<<endl;
  320.                 report<<"Unable to return correct change!"<<endl;
  321.                 report<<"Please make another selection."<<endl;}
  322.                 else {
  323.                 quarters = quarters - change_in_quarters;
  324.                 dimes = dimes - change_in_dimes;
  325.                 nickels = nickels - change_in_nickels;
  326.                 report<<"Money inserted: $"<<money_inserted_dollars<<endl;
  327.                 report<<"Item selected for pruchase: Cereal Bar"<<endl;
  328.                 report<<"Change dispensed: "<<change_in_quarters<<" "
  329.                 <<change_in_dimes<<" "<<change_in_nickels<<" "<<endl;
  330.                 number_of_cereal_bar--;}}}}}
  331.  
  332. if (integer == 5){
  333.     if (number_of_chips = 0){
  334.     report<<"Item out of stock!"<<endl<<"Please make another selection."<<endl;}
  335.     if (number_of_chips > 0){
  336.         if (cost > money_inserted){
  337.         report<<"Money inserted: $"<<money_inserted_dollars<<endl;
  338.         report<<"Item selected for purchase: Chips"<<endl;
  339.         report<<"Insufficient funds!"<<endl;
  340.         report<<"Please make another selection."<<endl;}
  341.         else if (cost = money_inserted){
  342.         report<<"Money inserted: $"<<money_inserted_dollars<<endl;
  343.         report<<"Item selected for purchase: Chips"<<endl;
  344.         report<<"Exact change"<<endl;
  345.         money_inserted = 0;
  346.         number_of_chips--;}
  347.         else if (cost < money_inserted){
  348.             if ( (money_inserted - cost) > available_change){
  349.             report<<"Money inserted: $"<<money_inserted_dollars<<endl;
  350.             report<<"Item selected for purchase: Chips"<<endl;
  351.             report<<"Unable to return correct change!"<<endl;
  352.             report<<"Please make another selection."<<endl;}
  353.            
  354.             else if ((money_inserted - cost) < available_change){
  355.             int change_due = money_inserted - cost;
  356.             int change_in_quarters = change_due / 25;
  357.             while (change_in_quarters >= quarters) {
  358.             change_in_quarters--;}
  359.             change_due = change_due - (change_in_quarters * 25);
  360.            
  361.             int change_in_dimes = change_due / 10;
  362.             while (change_in_dimes >= dimes){
  363.             change_in_dimes--;}
  364.             change_due = change_due - (change_in_dimes * 10) ;
  365.  
  366.             int change_in_nickels = change_due / 5;
  367.             while (change_in_nickels >= nickels){
  368.             change_in_nickels--;}
  369.             change_due = change_due - (change_in_nickels * 25);
  370.  
  371.                 if (change_due > 0){
  372.                 report<<"Money inserted: $"<<money_inserted_dollars<<endl;
  373.                 report<<"Item selected for purchase: Chips"<<endl;
  374.                 report<<"Unable to return correct change!"<<endl;
  375.                 report<<"Please make another selection."<<endl;}
  376.                 else {
  377.                 quarters = quarters - change_in_quarters;
  378.                 dimes = dimes - change_in_dimes;
  379.                 nickels = nickels - change_in_nickels;
  380.                 report<<"Money inserted: $"<<money_inserted_dollars<<endl;
  381.                 report<<"Item selected for pruchase: Chips"<<endl;
  382.                 report<<"Change dispensed: "<<change_in_quarters<<" "
  383.                 <<change_in_dimes<<" "<<change_in_nickels<<" "<<endl;
  384.                 number_of_chips--;}}}}}
  385.  
  386. if (integer == 6){
  387.     if (number_of_gum = 0){
  388.     report<<"Item out of stock!"<<endl<<"Please make another selection."<<endl;}
  389.     if (number_of_gum > 0){
  390.         if (cost > money_inserted){
  391.         report<<"Money inserted: $"<<money_inserted_dollars<<endl;
  392.         report<<"Item selected for purchase: Gum"<<endl;
  393.         report<<"Insufficient funds!"<<endl;
  394.         report<<"Please make another selection."<<endl;}
  395.         else if (cost = money_inserted){
  396.         report<<"Money inserted: $"<<money_inserted_dollars<<endl;
  397.         report<<"Item selected for purchase: Gum"<<endl;
  398.         report<<"Exact change"<<endl;
  399.         money_inserted = 0;
  400.         number_of_gum--;}
  401.         else if (cost < money_inserted){
  402.             if ( (money_inserted - cost) > available_change){
  403.             report<<"Money inserted: $"<<money_inserted_dollars<<endl;
  404.             report<<"Item selected for purchase: Gum"<<endl;
  405.             report<<"Unable to return correct change!"<<endl;
  406.             report<<"Please make another selection."<<endl;}
  407.            
  408.             else if ((money_inserted - cost) < available_change){
  409.             int change_due = money_inserted - cost;
  410.             int change_in_quarters = change_due / 25;
  411.             while (change_in_quarters >= quarters) {
  412.             change_in_quarters--;}
  413.             change_due = change_due - (change_in_quarters * 25);
  414.            
  415.             int change_in_dimes = change_due / 10;
  416.             while (change_in_dimes >= dimes){
  417.             change_in_dimes--;}
  418.             change_due = change_due - (change_in_dimes * 10) ;
  419.  
  420.             int change_in_nickels = change_due / 5;
  421.             while (change_in_nickels >= nickels){
  422.             change_in_nickels--;}
  423.             change_due = change_due - (change_in_nickels * 25);
  424.  
  425.                 if (change_due > 0){
  426.                 report<<"Money inserted: $"<<money_inserted_dollars<<endl;
  427.                 report<<"Item selected for purchase: Gum"<<endl;
  428.                 report<<"Unable to return correct change!"<<endl;
  429.                 report<<"Please make another selection."<<endl;}
  430.                 else {
  431.                 quarters = quarters - change_in_quarters;
  432.                 dimes = dimes - change_in_dimes;
  433.                 nickels = nickels - change_in_nickels;
  434.                 report<<"Money inserted: $"<<money_inserted_dollars<<endl;
  435.                 report<<"Item selected for pruchase: Gum"<<endl;
  436.                 report<<"Change dispensed: "<<change_in_quarters<<" "
  437.                 <<change_in_dimes<<" "<<change_in_nickels<<" "<<endl;
  438.                 number_of_gum--;}}}}}
  439.  
  440.        
  441.  
  442. return;
  443. }
  444. /**************************************************************************************************
  445.  
  446. /*Transaction 'L'
  447. ******************************************************************************************************************************/
  448. int transaction_L (int quarters, int dimes, int nickels, int number_of_pop, int number_of_iced_tea, int number_of_water,
  449.            int number_of_cereal_bar, int number_of_chips, int number_of_gum){
  450. report<<quarters<<" "<<dimes<<" "<<nickels<<endl;   //Reports the number of quarters, dimes, and nickels to report_log.txt in this format:
  451.                             //<quarter>_<dimes>_<nickels> where "_" is a space
  452.  
  453. report<<pop<<" "<<number_of_pop<<endl;          //Reports the item number and number of item that is currently stock
  454.  
  455. report<<iced_tea<<" "<<number_of_iced_tea<<endl;
  456.  
  457. report<<water<<" "<<number_of_water<<endl;
  458.  
  459. report<<cereal_bar<<" "<<number_of_cereal_bar<<endl;
  460.  
  461. report<<chips<<" "<<number_of_chips<<endl;
  462.  
  463. report<<gum<<" "<<number_of_gum<<endl;
  464.  
  465. return 0;
  466. }
  467. /*Transaction 'O'
  468. ******************************************************************************************************************************/
  469. void transaction_O  (int request_stock_number, int & number_of_pop, int & number_of_iced_tea, int & number_of_water,
  470.                int & number_of_cereal_bar, int & number_of_chips, int & number_of_gum){
  471.  
  472. int amount1=0, amount2=0, amount3=0, amount4=0, amount5=0, amount6=0; //Initialize the amount of stock that needs to be ordered per item
  473.  
  474. if (request_stock_number > number_of_pop){  //if requested stock is greater than what's in the inventory is, amount that needs to be request is calculated
  475. amount1 = request_stock_number - number_of_pop; //Then the amount of inventory will equal the requested stock, as it is being updated.
  476. number_of_pop = request_stock_number;}
  477.  
  478. if (request_stock_number > number_of_iced_tea){
  479. amount2 = request_stock_number - number_of_iced_tea;
  480. number_of_iced_tea = request_stock_number;}
  481.  
  482. if (request_stock_number > number_of_water){
  483. amount3 = request_stock_number - number_of_water;
  484. number_of_water = request_stock_number;}
  485.  
  486. if (request_stock_number > number_of_cereal_bar){
  487. amount4 = request_stock_number - number_of_cereal_bar;
  488. number_of_cereal_bar = request_stock_number;}
  489.  
  490. if (request_stock_number > number_of_chips){
  491. amount5 = request_stock_number - number_of_chips;
  492. number_of_chips = request_stock_number;}
  493.  
  494. if (request_stock_number > number_of_gum){
  495. amount6 = request_stock_number - number_of_gum;
  496. number_of_gum = request_stock_number;}
  497.  
  498. report<<amount1<<" Pop "<<amount2<<" Iced Tea "<<amount3<<" Water "<<amount4<<" Cereal Bar "<<amount5   //Report the amount of inventory that was requested to restock to certain
  499. <<" Chips "<<amount6<<" Gum "<<endl;                                    //amount
  500.  
  501.  
  502. return;
  503. }
  504. /*********************************************************************************************************************************
  505.  
  506. /*Main function
  507. ************************************************************************************************************************/
  508. int main (){
  509.  
  510.  
  511.  
  512.  
  513. int number_of_pop=0;    //Declare containers for number of certain items
  514. int number_of_iced_tea=0;
  515. int number_of_water=0;
  516. int number_of_cereal_bar=0;
  517. int number_of_chips=0;
  518. int number_of_gum=0;
  519.  
  520.  
  521. int nickels = 0;    //Declare containers of number of certain coins
  522. int dimes = 0;
  523. int quarters = 0;
  524.  
  525. int nickels_c=0;    //Declare containers for the number of inserted coins by consumer
  526. int dimes_c=0;
  527. int quarters_c=0;
  528.  
  529. inventory>>nickels; //insert number of coins to containers from inventory.txt
  530. inventory>>dimes;
  531. inventory>>quarters;
  532.  
  533. int item, number_of_item;           //Delcared container file for what inventory.txt will be inputting information to
  534. while (inventory>>item>>number_of_item){    //While loop to input the items that are in stock and how much of it there is
  535. if (item == 1)                 
  536. number_of_pop = number_of_item;
  537.  
  538. else if(item == 2)
  539. number_of_iced_tea = number_of_item;
  540.  
  541. else if(item == 3)
  542. number_of_water = number_of_item;
  543.  
  544. else if(item == 4)
  545. number_of_cereal_bar = number_of_item;
  546.  
  547. else if(item == 5)
  548. number_of_chips = number_of_item;
  549.  
  550. else if(item == 6)
  551. number_of_gum = number_of_item;
  552.  
  553. else
  554. ;
  555. }
  556.  
  557.  
  558. int money_inserted = 0;     //Delcare container for the money that has been inserted by consumer
  559. char type;  //container for type of transaction
  560. int coin_inserted;  //container for current coin that is inserted. Info will come from trasnaction I lines
  561.  
  562. while (transaction>>type){  //start while loop for figuring transactions
  563. while (type == 'I'){    //Repeat transaction I until there are no more transaction I's in the transaction.txt  
  564. transaction>>coin_inserted;
  565. transaction_I(coin_inserted, nickels, dimes, quarters, nickels_c, dimes_c, quarters_c);//Go through Transaction I
  566.     transaction>>type>>coin_inserted;
  567. }
  568.  
  569.  
  570.  
  571. money_inserted = (nickels_c * 5) + (dimes_c*10) + (quarters_c*25); //Calculates total money inserted by consumer
  572.  
  573. int available_change = 0;   //Declare container for change the vending machine has available
  574. available_change = (nickels * 5) + (dimes * 5) + (quarters * 25); //Calculates total available change
  575.  
  576.  
  577. int item_number;    //Declare container for item number
  578.  
  579. while (type == 'S'){   
  580. transaction>>item_number;
  581. transaction_S(item_number, money_inserted, number_of_pop, number_of_iced_tea, number_of_water,
  582.            number_of_cereal_bar, number_of_chips, number_of_gum, available_change, quarters,
  583.            dimes,nickels, quarters_c, dimes_c, nickels_c);  //Go through Transaction S
  584.  
  585. }
  586. //////////////
  587. cout<<endl<<quarters_c<<" "<<dimes_c<<" "<<nickels_c<<endl;
  588. //////////////
  589.         //Start of transaction I
  590. while (type == 'L'){
  591. transaction_L(quarters, dimes, nickels, number_of_pop, number_of_iced_tea, number_of_water,
  592.            number_of_cereal_bar, number_of_chips, number_of_gum);
  593. }
  594.  
  595. int request_stock_number;       //Start of transaction O
  596. while (type == 'O'){
  597. transaction>>request_stock_number;
  598. transaction_O(request_stock_number, number_of_pop, number_of_iced_tea, number_of_water,
  599.            number_of_cereal_bar, number_of_chips, number_of_gum);
  600.  
  601. }
  602.  
  603. while (type == 'Q'){
  604. report<<"End";          //"End" is entered in report log
  605. final<<quarters<<" "<<dimes<<" "<<nickels<<endl;    //Final amount of quarters, dimes, nickels, and invetory is entered in final_stock.txt
  606. final<<pop<<" "<<number_of_pop<<endl;
  607. final<<iced_tea<<" "<<number_of_iced_tea<<endl;
  608. final<<water<<" "<<number_of_water<<endl;
  609. final<<cereal_bar<<" "<<number_of_cereal_bar<<endl;
  610. final<<chips<<" "<<number_of_chips<<endl;
  611. final<<gum<<" "<<number_of_gum<<endl;
  612. transaction>>type;
  613. }
  614. }
  615.  
  616. transaction.close();    //Close textfiles.
  617. inventory.close();
  618. report.close();
  619. final.close();
  620.  
  621. return 0;
  622. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement