Advertisement
Guest User

compsci

a guest
Oct 23rd, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <fstream>
  4. #include <cassert>
  5. #include <string>
  6. using namespace std;
  7.  
  8. struct diffbin
  9. {
  10. string part;
  11. int amount;
  12. };
  13.  
  14. void Display(diffbin diffbinarr[],int i);
  15. void RemoveParts(diffbin diffbinarr[],int i,string down,int number);
  16. void AddParts(diffbin diffbinarr[],int i,string down,int number);
  17. const int SIZE=10;
  18.  
  19. int main()
  20. {
  21. diffbin diffbinarr[SIZE];
  22. ifstream myIn;
  23. myIn.open("inventory.dat");
  24. assert(myIn);
  25. string line;
  26.  
  27. string down="";
  28. int number=0;
  29. bool flag=false;
  30. int i=0;
  31. while(getline(myIn,line))
  32. {
  33. if (flag==false)
  34. {
  35. down=line;
  36. flag=true;
  37. }
  38. else
  39. {
  40.  
  41. getline(myIn,line);
  42. myIn>>number;
  43. flag=false;
  44. diffbinarr[i].part=down;
  45. diffbinarr[i].amount=number;
  46. i++;
  47. }
  48.  
  49. }
  50.  
  51.  
  52. cout<<"Warehouse inventory before the operations"<<endl;
  53. cout<<endl;
  54. cout<<endl;
  55. Display(diffbinarr,i);
  56.  
  57.  
  58. ifstream infile;
  59. infile.open("operations.dat");
  60. assert(infile);
  61. string operation;
  62.  
  63. int count=0;
  64. while(getline(infile,line))
  65. {
  66. if(count==0)
  67. {
  68. operation=line;
  69. count++;
  70. }
  71. else if(count==1)
  72. {
  73. down=line;
  74. count++;
  75.  
  76. }
  77. else
  78. {
  79. getline(infile,line);
  80. infile>>number;
  81. if(operation=="Add")
  82. {
  83. AddParts(diffbinarr,i,down,number);
  84. }
  85. else
  86. {
  87. RemoveParts(diffbinarr,i,down,number);
  88. }
  89. count=0;
  90. }
  91.  
  92. }
  93.  
  94.  
  95. cout<<"Warehouse inventory after the operations"<<endl;
  96. cout<<endl;
  97. cout<<endl;
  98. Display(diffbinarr,i);
  99. myIn.close();
  100. infile.close();
  101. return 0;
  102. }
  103.  
  104. void Display(diffbin diffbinarr[],int i)
  105. {
  106. cout<<setw(20)<<left<<"Part"<<setw(10)<<left<<"Quantity"<<endl;
  107. cout<<endl;
  108. cout<<endl;
  109. for(int a=0;a<i;a++)
  110. {
  111. cout<<setw(20)<<left;
  112. cout<<diffbinarr[a].part;
  113. cout<<setw(10)<<left;
  114. cout<<diffbinarr[a].amount<<endl;
  115. }
  116. }
  117.  
  118.  
  119.  
  120. void AddParts(diffbin diffbinarr[],int i,string down,int number)
  121. {
  122. for(int a=0;a<i;a++)
  123. {
  124. if(diffbinarr[a].part==down)
  125. {
  126. diffbinarr[a].amount+=number;
  127. break;
  128. }
  129. }
  130. }
  131.  
  132.  
  133. void RemoveParts(diffbin diffbinarr[],int i,string down,int number)
  134. {
  135. for(int a=0;a<i;a++)
  136. {
  137. if(diffbinarr[a].part==down)
  138. {
  139. if(diffbinarr[a].amount-number>0)
  140. {
  141. diffbinarr[a].amount-=number;
  142. }
  143. else
  144. {
  145.  
  146. }
  147. break;
  148. }
  149. }
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement