Detyra (1) programim C++

Bashkengjitur gjendet nje program C++ ndertuar si detyre. Programi krijon nje  klase queue dhe teston operacionet SHTO dhe FSHI.

cqueue-array-class.rar

Tirana Center of Technology

—————driver.cpp—————————-
#include<iostream>
#include<fstream>
#include<string>
#include “Queue1.h”
using namespace std;

void printQue(ostream& fout, QueType<ItemType> q, string queName);
//pre: que has been initilized, fout is open for output
//post: each element of que has been written to datafile

void displayMenu(int& choice);
//pre: none
//post: displays the menu for the user to run operations on several queues

void addElement(QueType<ItemType>& q, string queName);
//pre: none
//post: if queue is not full, a user-entered item is added to queue
//        if queue is full a message is displayed

void deleteElement(QueType<ItemType>& q, string queName);
//pre: none
//post: if que is not empty deletes an item from the queue and displayed
//        if que is empty a “que is empty” message is displayed

int main()
{
int size;
int choice;
cout<<“Enter the size of the queue2″<<endl;
cin>>size;
QueType<ItemType> que2(size);
QueType<ItemType> que1;

do
{
displayMenu(choice);
switch(choice)
{
case 1: addElement(que1, “1”);
break;
case 2: addElement(que2, “2”);
break;
case 3: deleteElement(que1, “1”);
break;
case 4: deleteElement(que2, “2”);
break;
case 5: que1.MakeEmpty();
break;
case 6: if (que1.IsEmpty())
cout<<” Queue 1 is empty”<<endl;
else
cout<<” Queue 1 is not empty”<<endl;
break;
case 7: if (que1.IsFull())
cout<<“Queue 1 is full”<<endl;
else
cout<<“Queue 1 is not full”<<endl;
break;
case 8: que2 = que1;
break;
case 9: printQue(cout, que1, “1”);
printQue(cout, que2, “2”);
break;

}//end switch
}while (choice != 0);

if (choice == 0)
return 0;
}//end main

void printQue(ostream& fout, QueType<ItemType> q, string queName)
{
ItemType item;
if (q.IsEmpty())
{
cout<<“The queue “<<queName<<” is empty”<<endl;
return;
}
else
{
cout<<“Queue “<<queName<<” contains the following items:”<<endl;
while(q.Dequeue(item))
{
fout<<item<<endl;
}
fout<<endl;
}
}

void displayMenu(int& choice)
{
cout<<“Please select from the menu”<<endl<<endl;

cout<<“1\tAdd item onto the queue 1 “<<endl;
cout<<“2\tAdd item onto the queue 2 “<<endl;
cout<<“3\tRemove item from queue 1 “<<endl;
cout<<“4\tRemove item from queue 2 “<<endl;
cout<<“5\tDelete all items from queue 1″<<endl;
cout<<“6\tTest queue 1 if is empty”<<endl;
cout<<“7\tTest if queue 1 is full”<<endl;
cout<<“8\tCopy queue1 to queue 2″<<endl;
cout<<“9\tPrint all ques”<<endl;
cout<<“0\tExit program”<<endl<<endl;

cin>>choice;
while (choice < 0 || choice > 9)
{
cout<<“That is not a valid choice, please re-enter your choice”<<endl;
cin>>choice;
}
}

void addElement(QueType<ItemType>& q, string queName)
{
ItemType item;
cout<<“Please enter an item to insert “<<endl;
cin>>item;
if (q.Enqueue(item))
cout<<item<<“Item has been added to queue”<<queName<<endl;
else
cout<<queName<<” queue was full, not able to insert “<<item<<endl;
}
void deleteElement(QueType<ItemType>& q, string queName)
{
ItemType item;
if(q.Dequeue(item))
cout<<item<<” has been removed from queue “<<queName<<endl;
else
cout<<“Queue “<<queName<<” was empty”<<endl;
}

———————————————————