SHARE
TWEET

Untitled

a guest Nov 21st, 2019 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <fstream>
  3. #include "CSVReader2.h"
  4. #include "AVLTreeNode.h"
  5. #include "AVLTreeNode.cpp"
  6. #include <string>
  7.  
  8. /* run this program using the console pauser or add your own getch, system("pause") or input loop */
  9.  
  10. int main(int argc, char** argv) {
  11.    
  12.     int answer;
  13.     string name;
  14.  
  15.     int pID;
  16.     int quantity;
  17.     int price;
  18.     int Count=0;
  19.     int TotalQuantityCheck = 0;
  20.     int TotalPriceCheck = 0;
  21.     bool emptyTree = true;
  22.     int IDwMax;
  23.     int IDwMin = -1;
  24.    
  25.     //Step 1: load the entire StoreInventoryStock.csv into rd
  26.    
  27.     CSVReader *rd = new CSVReader("Inventory.csv",'|'); //maybe i should change this back to a ','
  28.     AVLTree *tree = new AVLTree();
  29.    
  30.  
  31.         for(int i=0; i<rd->getRowsCount(); i++)
  32.     {
  33.         tree->Insert(rd->getCellAsString(i,0),   //name
  34.         rd->getCellAsDouble(i,1), //price
  35.         rd->getCellAsInt(i,2), //quantity
  36.         rd->getCellAsInt(i,3));  //pID
  37.        
  38.        
  39.         TotalQuantityCheck = TotalQuantityCheck + rd->getCellAsInt(i,2);
  40.         TotalPriceCheck = TotalPriceCheck + (rd->getCellAsDouble(i,1) * rd->getCellAsInt(i,2));
  41.        
  42.             if(emptyTree)  //shouldn't happen because tree is never empty due to items in CSV
  43.       {
  44.         IDwMin = rd->getCellAsInt(i,3);
  45.         IDwMax = rd->getCellAsInt(i,3);
  46.       }//if
  47.       else{                                                         //if kills of player just inserted is < current lowest kills
  48.         if(rd->getCellAsInt(i,1) < tree->Find(IDwMin).price)   //then set the current lowest kills as the lowest kills                                                                   
  49.         {                                                           //and save the current lowest's kill for later
  50.           IDwMin = rd->getCellAsInt(i,3);
  51.         }
  52.         if(rd->getCellAsInt(i,1) > tree->Find(IDwMax).price)   //if kills of player just inserted is > current highest
  53.         {                                                           //then set the current highest kills as the highest kills of split
  54.           IDwMax = rd->getCellAsInt(i,3);                       //and save the current highest kills for later
  55.         }
  56.       }
  57.     emptyTree = false;
  58.    
  59.     }//for loop
  60.    
  61.     do{
  62.     cout<<"**********************************************************"<<endl;
  63.     cout<<"INVENTORY MANAGER"<<endl;
  64.     cout<<"Choose an option:"<<endl;
  65.     cout<<"[1] Add a new item to the inventory"<<endl;
  66.     cout<<"[2] Display the information for an item (given the pID)"<<endl;
  67.     cout<<"[3] Display the inventory"<<endl;
  68.     cout<<"[4] Display inventory statistics"<<endl;
  69.     cout<<"[5] Quit"<<endl;
  70.     cin>>answer;
  71.    
  72.     switch(answer)
  73.     {
  74.         case 1:{
  75.             cout<<"\nEnter the name of the Item: ";
  76.             cin>>name;
  77.             cout<<"\nEnter the price: ";
  78.             cin>>price;
  79.             cout<<"\nEnter the item's quantity: ";
  80.             cin>>quantity;
  81.             cout<<"\nEnter the item's ID: ";
  82.             cin>>pID;
  83.            
  84.             if(pID <= 0 || price <= 0 || quantity <= 0)
  85.             cout<<"***Error: Please enter a number greater than 0 for price, quantity and ID."<<endl;
  86.        
  87.             else { 
  88.             tree->Insert(name, price, quantity, pID);
  89.             Count++;
  90.            
  91.             if(emptyTree)
  92.       {
  93.         IDwMin = pID;
  94.         IDwMax = pID;
  95.       }
  96.      
  97.         else{
  98.         if(price < tree->Find(IDwMin).price)  //
  99.         {
  100.           IDwMin = pID;
  101.         }
  102.         if(price > tree->Find(IDwMax).price)
  103.         {
  104.           IDwMax = pID;
  105.         }
  106.       }//else
  107.       emptyTree = false;
  108.        
  109.         //  TotalQuantityCheck + TotalQuantityCheck + rd->getCellAsInt(i,2);
  110.         //  TotalPriceCheck = TotalPriceCheck + (rd->getCellAsDouble(i,1) * rd->getCellAsInt(i,2));
  111.            
  112.             cout<<"\nThank you. Item added sucessfully.";
  113.                 ofstream myfile;
  114.                 myfile.open("Inventory.csv");
  115.                 myfile <<name<<'|'<<price<<'|'<<quantity<<'|'<<pID<<endl;
  116.                 myfile.close();
  117.        
  118.         }//else
  119.     }  break;
  120.    
  121.         case 2: {
  122.             cout<<"\nEnter the item ID of the item to be displayed: ";
  123.             cin>>pID;
  124.    
  125.     AVLTreeNode foundNode = tree->Find(pID);
  126.            
  127.             if (foundNode.height == -1){
  128.            
  129.                 cout<<"***Error: Item with the ID = "<<pID<<" is not in the database."<<endl;
  130.             }
  131.            
  132.             else{
  133.                 cout<<"\nItem name: "<<foundNode.Name<<",  Item price: $"<<foundNode.price  
  134.                     <<",  Quantity: "<<foundNode.quantity<<", Item ID = "<<foundNode.PID<<endl;
  135.             }
  136.             } break;
  137.    
  138.         case 3: {
  139.             cout<<"Here is the Inventory database: "<<endl;
  140.             tree->PrintTreeInOrder();
  141.        
  142.                 }   break;
  143.        
  144.         case 4: {
  145.             cout<<"Database Statistics:"<<endl;
  146.             cout<<"\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<endl;
  147.         /*  cout<<"\tNumber of items: "<<Count+rd->getRowsCount()<<endl;
  148.              //this should track all user inputted items + ones in csv file
  149.             cout<<"\tTotal Number of items: "<<TotalQuantityCheck<<endl; //+ rd->getCellAsInt(i,3)<<endl;
  150.             //this should track all user inputted prices + ones in csv file then multiply by the the quantities
  151.            
  152.             cout<<"\tTotal Inventory Cost: $"<<TotalPriceCheck<<endl;// + (rd->getCellAsDouble(i,2) * rd->getCellAsInt(i,3))<<endl;
  153.            
  154.         //Name, price, quantity and ID are displayed but using a function from earlier in main
  155.             cout<<"\tCheapest Item: "<<endl;
  156.         //  cout<<"\n\t\tname: "<<tree->Find(IDwMin).description<<",  SKU: "<<tree->Find(skuOfMin).sku  
  157.         //          <<",  Quantity: "<<tree->Find(skuOfMin).quantity<<",  Price = $"<<tree->Find(skuOfMin).price<<endl;
  158.        
  159.         //  cout<<"\nMost Expensive Item: "<<endl;
  160.         //  cout<<"\n\t\tDescription: "<<tree->Find(skuOfMax).description<<",  SKU: "<<tree->Find(skuOfMax).sku  
  161.         //          <<",  Quantity: "<<tree->Find(skuOfMax).quantity<<",  Price = $"<<tree->Find(skuOfMax).price<<endl; */
  162.                            
  163.         } break;
  164.    
  165.         case 5: break;
  166.    
  167.         default: cout<<"Invalid option - please try again \n"; break;
  168.    
  169.     }//switch
  170.     }//do
  171.     while(answer!=5);
  172.    
  173.     ofstream myfile;
  174.     tree->SaveTreeInOrder(myfile);
  175.    
  176.     delete tree;  //just putting tree specifies that the tree is getting deleted
  177.                 //delete automatically calls the deconstructor
  178.                
  179.     return 0;
  180. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top