Question: C++ problem, please help me out! The question require me to read the txt file and count how many times file read,array search and array
C++ problem, please help me out!
The question require me to read the txt file and count how many times file read,array search and array shift.

I have already set int fileCounter = 0; int searchCounter = 0; int shiftCounter = 0; and answer is 100,1506,276 but I don't know how to get it.
Here is my code:
struct Board{ string type; int price; int statue;
};
void itemLeft(Board itemList[],int index){ int cnt2 = 0; for(int i=0;i int main(){ Board itemList[200]; int loopCnt = 0; int fileCounter = 0; int searchCounter = 0; int shiftCounter = 0; int itemSold = 0; #include ifstream ifs; ifs.open(fileName.c_str()); //ifs.open("cjj.txt"); if(ifs.fail()){ cout>a>>c>>value; itemList[cnt].price = value; }else if(item.find("sale")!= string::npos){ itemList[cnt].statue = 1; stringstream ss(item); ss>>a>>b>>c>> value; itemList[cnt].price = value; } //For efficiency purpose,I will find what item will be sold inside this while loop and count the number for(int h =0;h itemList[y] = itemList[(y+1)]; } cnt-=1;//itemList[cnt] has been shifted over 1 itemList[cnt] = {}; //delete it and because cnt-=1 last line so just like remove last item cnt-=1;//start at the empty cell in the next iteration itemSold++; break; ///Finish sold process here===================== }else{continue;} }else if(itemList[cnt].statue == 0){ ///wanted if(itemList[cnt].price >= itemList[h].price){ cout } cnt-=1;//itemList[cnt] has been shifted over 1 itemList[cnt] = {}; //delete it and because cnt-=1 last line so just like remove last item cnt-=1;//start at the empty cell in the next iteration itemSold++; break; ///Finish sold process here===================== }else{continue;} }else{cout }///find match end here cnt++; }///while end here ifs.close(); cout } ============txt file:================ chicken, for sale, 60 microwave, wanted, 201 bike, for sale, 60 bike, wanted, 50 microwave, for sale, 200 chicken, for sale, 25 chicken, wanted, 25 microwave, wanted, 10 microwave, for sale, 2 chicken, for sale, 100 bike, wanted, 100 chicken, for sale, 5 truck, wanted, 1000 bike, for sale, 50 chicken, for sale, 5 bike, for sale, 500 chicken, for sale, 1 chicken, for sale, 25 bike, wanted, 60 truck, wanted, 2000 truck, for sale, 2500 bike, wanted, 100 truck, for sale, 300 bike, for sale, 100 chicken, for sale, 10000 truck, for sale, 2000 truck, wanted, 1000 dresser, for sale, 20 truck, wanted, 9000 truck, wanted, 8000 truck, for sale, 4000 dresser, for sale, 2 dresser, wanted, 800 microwave, wanted, 70 truck, for sale, 2000 truck, for sale, 2000 truck, wanted, 1000 microwave, for sale, 60 dresser, for sale, 2000 dresser, wanted, 60 dresser, wanted, 50 truck, wanted, 1000 truck, for sale, 500 truck, for sale, 1500 dresser, for sale, 100 dresser, wanted, 200 dresser, for sale, 450 truck, for sale, 2000 truck, wanted, 1000 truck, for sale, 500 dresser, for sale, 500 dresser, wanted, 200 chicken, wanted, 5 chicken, for sale, 5 truck, wanted, 1000 chicken, for sale, 1 chicken, for sale, 25 chicken, wanted, 16 truck, wanted, 2000 chicken, for sale, 15 chicken, wanted, 5 chicken, for sale, 2 microwave, wanted, 15 microwave, wanted, 75 microwave, for sale, 65 chicken, for sale, 5 bike, for sale, 50 chicken, for sale, 1 chicken, for sale, 25 bike, for sale, 50 chicken, wanted, 25 microwave, wanted, 10 microwave, for sale, 2 chicken, for sale, 1 chicken, for sale, 25 bike, for sale, 50 chicken, wanted, 25 bike, wanted, 30 chicken, wanted, 16 chicken, for sale, 15 microwave, wanted, 70 microwave, for sale, 60 microwave, wanted, 50 bike, wanted, 75 truck, wanted, 1000 microwave, wanted, 201 microwave, for sale, 200 truck, wanted, 1000 chicken, for sale, 25 chicken, wanted, 25 truck, wanted, 1000 microwave, wanted, 10 bike, for sale, 10 truck, for sale, 2000 microwave, for sale, 2 truck, wanted, 4000 truck, for sale, 2000 microwave, for sale, 2 truck, wanted, 4000 bike, for sale, 10
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
