2012-05-06 28 views
-3

私は優先度のキューとreqularキューを持つプロジェクトを持っています。 優先度の高いキューを使用して、最小から最大までのIDで製品を整理する必要があります。C++のキュー、出力エラー

次に、reqularキューを使用して、これらを3つのカテゴリに入れる必要があります。 (在庫超過、在庫不足、制限内)。したがって、出力は次のようになります。

UnderStock

14887 $ 10 14

15678 $ 1 298

セール

12565 $ 4 539

18967 $ 12 401

StockWithinLimits

19847は$ 2 220

私はこのコードを書いたが、何かが、私はないと確信していることをオフで、私のアウトプットは、次のようになります。

セール

12565 $ 4 539

UnderStock

14887 $ 10 14

UnderStock

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; 
} 
+2

は、私たちはあなたのコードがどのように見えるかを推測することになっていますか? –

+0

私のコードが間違っているのを見て、出力もそうです。しかし、それが正しくこれをどのように設定しているかまだ分かりません。 誰でも私にヒントを与えることができますか?してください:-) –

答えて

0

プライオリティキューのための奇妙な使用が、私はそれがあるとし要求事項。

(1)pqueueにすべてを入れます。それは良い。次に、pqueueを空にし、under/over/withinロジックを使用して、項目を3つの通常キューのいずれかに入れます。その後、各キューを読み( "上"、 "下"、 "内"のヘッダーを最初に印刷し)、それらを印刷します。

(2)

QueueADT <int> que; 

que.Enqueue (n); 

間違って見えます。なぜあなたはアイテムではなくintをキューに入れていますか?なぜ3つではなく1つのキューを持っていますか?これは、que.Deque(n)文にも適用されます。

(3)実際には複合IF文は必要ありません。おそらく、最小値を下回るものが最大値を下回る場合もあります。

ので

if belowMin 
    put in lowQ 
    readagain 

if aboveMax 
    put in highQ 
    readagain 

put in withinQ 

のようなものはまた、あなたがスペックの言うことに応じて、アイテム<最大ではなく、アイテム< =最大にしたいことを確認するように注意してください。これらは外現在のwhileループであることをneeed

EDIT

outFile << "UnderStock" << endl; 
while (!lowQ.IsEmpty()) 
{ 
    lowQ.Dequeue (item); 
    item.printProduct (outFile); 
} 

outFile << "WithINLimits:" << endl; 
while (!withinQ.IsEmpty()) 
{ 
    withinQ.Dequeue (item); 
    item.printProduct (outFile); 
} 

outFile << "Overstock:" << endl; 
while (!highQ.IsEmpty()) 
{ 
    highQ.Dequeue (item); 
    item.printProduct (outFile); 
} 
+0

2)はい、これは間違っていますが、どのようにする必要がありますか.QueueADT que; que.Enqueue(n); 3つのキューを設定する方法がわかりません。 –

+0

変更(2)QueueADT que; que.Enqueue(n); –

+0

私が持っている唯一の質問は、3つのキューを設定する方法です:)ありがとう! –

-1
include<iostream.h> 
#include<conio.h> 

#define g_per_f 7.481 

void main(void) 
{ 
    cout<<"### Programmed By Amahdy(MrJava) ,right restricted.~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"; 
    cout<<"-------------------------------------------------------------------------------\n\n"; 

    float n_gallons; 

    do{ 
     cout<<"Enter the number of gallons : \xdb\t"; 
     cin >>n_gallons; 
     cout<<"The equivalent in cubic feet : \xdb\t"<<n_gallons/
      g_per_f<<endl; 
     cout<<"\n !Press c to continue or any key to exit."<<endl<<endl; 
    } while(getch()=='c'); 
}