プライオリティ キューとレギュラー キューを含むプロジェクトがあります。プライオリティ キューを使用して最小から最大までの ID で製品を整理する必要があります。
次に、通常のキューを使用して、それらを 3 つのカテゴリに分類する必要があります。(在庫過剰、在庫不足、制限内)。したがって、出力は次のようになります。
在庫不足
14887 $10 14
15678 $1 298
過剰在庫
12565 $4 539
18967 $12 401
StockWithinLimits
19847 $2 220
私はこのコードを書きましたが、よくわからない何かがずれており、出力は次のようになります。
過剰在庫
12565 $4 539
在庫不足
14887 $10 14
在庫不足
15678 $1 298
過剰在庫
18967 $12 401
StockWithInLimits
19847 $2 220
int main()
{
ifstream inFile; // file containing operations
ofstream outFile; // file containing output
string inFileName = "product.txt";
string outFileName = "result.txt";
inFile.open (inFileName.c_str());
outFile.open (outFileName.c_str());
ItemType item;//declare a temp item that trows into pQue
PQType<ItemType> pqueue(50);//priority queue that sorts items by ID
QueueADT <ItemType> que;
QueueADT <ItemType> lowQ;
QueueADT <ItemType> highQ;
QueueADT <ItemType> withinQ;
while ( item.readProduct (inFile) )
{
pqueue.Enqueue(item);
}
while (!pqueue.IsEmpty())
{
pqueue.Dequeue (item);
int tempcurinvent = item.getcurrentInventory ();
int tempmax = item.getMax ();
int tempmin =item.getMin ();
if ((tempcurinvent < tempmin) && (tempcurinvent < tempmax))//UnderStock
{
lowQ.Enqueue (item);
}
if ((tempcurinvent < tempmax) && ( tempcurinvent > tempmin)) //WithINLimits
{
withinQ.Enqueue (item);
}
else if ((tempcurinvent > tempmin) && (tempcurinvent > tempmax))//OverStock
{
highQ.Enqueue (item);
}
outFile << "UnderStock" << endl;
item.printProduct (outFile);
lowQ.Dequeue (item);
outFile << "WithINLimits:" << endl;
item.printProduct (outFile);
withinQ.Dequeue (item);
outFile << "OverStock" << endl;
item.printProduct (outFile);
highQ.Dequeue (item);
}
inFile.close ();
outFile.close ();
return 0;
}