Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <fstream>
- #include <cassert>
- #include <string>
- using namespace std;
- struct diffbin
- {
- string part;
- int amount;
- };
- void Display(diffbin diffbinarr[],int i);
- void RemoveParts(diffbin diffbinarr[],int i,string down,int number);
- void AddParts(diffbin diffbinarr[],int i,string down,int number);
- const int SIZE=10;
- int main()
- {
- diffbin diffbinarr[SIZE];
- ifstream myIn;
- myIn.open("inventory.dat");
- assert(myIn);
- string line;
- string down="";
- int number=0;
- bool flag=false;
- int i=0;
- while(getline(myIn,line))
- {
- if (flag==false)
- {
- down=line;
- flag=true;
- }
- else
- {
- getline(myIn,line);
- myIn>>number;
- flag=false;
- diffbinarr[i].part=down;
- diffbinarr[i].amount=number;
- i++;
- }
- }
- cout<<"Warehouse inventory before the operations"<<endl;
- cout<<endl;
- cout<<endl;
- Display(diffbinarr,i);
- ifstream infile;
- infile.open("operations.dat");
- assert(infile);
- string operation;
- int count=0;
- while(getline(infile,line))
- {
- if(count==0)
- {
- operation=line;
- count++;
- }
- else if(count==1)
- {
- down=line;
- count++;
- }
- else
- {
- getline(infile,line);
- infile>>number;
- if(operation=="Add")
- {
- AddParts(diffbinarr,i,down,number);
- }
- else
- {
- RemoveParts(diffbinarr,i,down,number);
- }
- count=0;
- }
- }
- cout<<"Warehouse inventory after the operations"<<endl;
- cout<<endl;
- cout<<endl;
- Display(diffbinarr,i);
- myIn.close();
- infile.close();
- return 0;
- }
- void Display(diffbin diffbinarr[],int i)
- {
- cout<<setw(20)<<left<<"Part"<<setw(10)<<left<<"Quantity"<<endl;
- cout<<endl;
- cout<<endl;
- for(int a=0;a<i;a++)
- {
- cout<<setw(20)<<left;
- cout<<diffbinarr[a].part;
- cout<<setw(10)<<left;
- cout<<diffbinarr[a].amount<<endl;
- }
- }
- void AddParts(diffbin diffbinarr[],int i,string down,int number)
- {
- for(int a=0;a<i;a++)
- {
- if(diffbinarr[a].part==down)
- {
- diffbinarr[a].amount+=number;
- break;
- }
- }
- }
- void RemoveParts(diffbin diffbinarr[],int i,string down,int number)
- {
- for(int a=0;a<i;a++)
- {
- if(diffbinarr[a].part==down)
- {
- if(diffbinarr[a].amount-number>0)
- {
- diffbinarr[a].amount-=number;
- }
- else
- {
- }
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement