Advertisement
Guest User

Untitled

a guest
Dec 7th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.45 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstdlib>
  4. #include <iomanip>
  5. #include <string>
  6. using namespace std;
  7.  
  8. class item
  9. {
  10.     public:
  11.     item();
  12.     string name;
  13.     double price;
  14.     double profit;
  15. };
  16.  
  17. item::item()
  18. {
  19.     name = " ";
  20.     price = 0;
  21.     profit = 0;
  22. }
  23.  
  24. int main()
  25. {
  26.     item a[50];
  27.     string b;
  28.     string c;
  29.     string d;
  30.     string dump;
  31.    
  32.     ifstream x;
  33.     cout << "What file to load?" << endl;
  34.     cin >> dump;
  35.     x.open(dump.c_str());
  36.    
  37.     for(int i=0; i<50; i++)
  38.     {
  39.         x >> b;
  40.    
  41.         if(b.substr(0, 1) == "I")
  42.         {          
  43.             x >> a[i].name >> a[i].price;
  44.         }
  45.        
  46.         if(b.substr(0, 1) == "R") //recipe
  47.         {
  48.             x >> c;
  49.            
  50.             if(x.eof())
  51.             {
  52.                 break;
  53.             }
  54.  
  55.             for(int j=0; j<50; j++) //connects first string c with a[].name (creation)
  56.             {
  57.                 if(c == a[j].name)
  58.                 {
  59.                     do
  60.                     {
  61.                         x >> dump;
  62.                        
  63.                         if(dump == ";")
  64.                         {
  65.                             break;
  66.                         }
  67.                        
  68.                         x >> d;
  69.                         for(int k=0; k<50; k++) //connects the = + strings with a[].name (recipe ingredient) and adds their price to the first one's profit
  70.                         {
  71.                             if(d == a[k].name)
  72.                             {
  73.                                 a[j].profit += a[k].price;
  74.                             }
  75.                         }  
  76.                     }while(!(dump == ";"));
  77.                 }
  78.             }
  79.         }  
  80.     }
  81.    
  82.     for(int i=0; i<50; i++)
  83.     {
  84.         if(!(a[i].profit == 0))
  85.         {
  86.             a[i].profit = a[i].price - a[i].profit;
  87.         }
  88.         if(a[i].name == " ")
  89.         {
  90.             break;
  91.         }
  92.         cout << "Making " << a[i].name << ", profit=" << a[i].profit << endl;
  93.     }
  94.    
  95.    
  96.    
  97.    
  98.    
  99.    
  100.     return 0;
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement