c++ queue

queue problem!

Page 1 of 1

1 Replies - 1643 Views - Last Post: 20 December 2009 - 05:09 AM Rate Topic: -----

#1 asideli   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 20-December 09

c++ queue

Posted 20 December 2009 - 03:50 AM

hi, i have a project about queue but i m beginner , im trying and it doesnt work.i need your help!

Implement a queuematic system that has 3 queues with different priorities. The system calls 5 from VIP queue, 3 from normal queue, and 1 from other queue.
When the program runs, the following menu appears.
1. VIP Custemer comes
2. Normal Custemer comes
3. Other Custemer comes
4. Call next customer
5. Number of customers in the queue
When 1, 2, or 3 is selected, the corresponding customer is added to the queue with a number (1+the number of the last customer in the given queue) generated. When 4 is selected, the next customer to be served is deleted from the queue. The queue selection bases on the rule mentioned above. (5 from VIP, 3 from Normal, 1 from other). When 5 is selected, it reports the number of customers waiting in each queue.

my codes:
--------------------
// kuyruk1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>//i-output stream
using namespace std;

#define MAX 10		   // MAXIMUM CONTENTS IN QUEUE


class queue
{
 private:
		int t[MAX];
		int al;	  // Addition End
		int dl;	  // Deletion End

 public:
  queue()
  {
		dl=-1;
		al=-1;
  }

  void del()
  {
	 int tmp;
	 if(dl==-1)
	 {
			cout<<"Queue is Empty";
	 }
	 else
	 {
				for(int j=0;j<=al;j++)
				{
						if((j+1)<=al)
						{
								tmp=t[j+1];
								t[j]=tmp;
						}
						else
						{
								al--;

						if(al==-1)
								dl=-1;
						else
								dl=0;
						}
				}
	 }
  }

void add(int item)
{
		if(dl==-1 && al==-1)
		{
				dl++;
				al++;
		}
   else
   {
				al++;
				if(al==MAX)
		{
						cout<<"Queue is Full\n";
						al--;
						return;
				}
		}
		t[al]=item;

}

  void display()
  {
		if(dl!=-1)
   {
		for(int iter=0; iter<=al; iter++)
		cout<<t[iter]<<" ";
   }
   else
		cout<<"EMPTY";
  }

};

int main()
{
	do{
	int secim;
	cout<<"\nLutfen Yapmak istediginiz islemi seciniz:\n-------------------------------------------\n";
	cout<<"[0]Clean Screen\n[1]VIP Custemer comes \n[2]Normal Custemer comes \n[3]Other Customer comes \n[4]Call next customer \n[5]Number of customers in the queue\n[6]Exit\n-------------------------------------------\n";
	cin>>secim;
	queue v,n,o;
	int i=0;
	int vData[10];
	int sayac=1;
	switch(secim)
	{
	case 0:
		system("cls");
		break;
	case 1:
		cin>>i;
		v.add(vData[i]);
		v.display();
		i++;
		break;
	case 2:
		/*n.add(i);
		n.display();
		i++;*/
		break;
	case 3:
		
		break;
	case 4:
		int sayi;
		cout<<"Lutfen silmek istediginiz musteri sayisini giriniz: ";
		cin>>sayi;
		/*if(sayi<6)
		{
			v.del();
			
		}
		else*/


		break;
	case 5:
		cout<<"VIP customer:"<<"?"<<endl;
		cout<<"Normal customer:"<<"?"<<endl;
		cout<<"Other customer:"<<"?"<<endl;
		break;
	case 6:
		return 0;
		break;
	default:
		break;
	}	
	}while(true);//işlem tekrar soruluyor..

 return EXIT_SUCCESS;
}


**Mod Edit: added code tags: :code:

This post has been edited by NickDMax: 20 December 2009 - 06:01 AM


Is This A Good Question/Topic? 0
  • +

Replies To: c++ queue

#2 janotte   User is offline

  • code > sword
  • member icon

Reputation: 991
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: c++ queue

Posted 20 December 2009 - 05:09 AM

Welcome to DIC!

Please edit your posting (see the "EDIT" button in lower right).
( a ) Delete all your code.
( b ) Get a fresh copy of the code with formatting in place from your editor / IDE.
( c ) Paste the formatted code between code tags like this :code:
( d ) Use the "Preview Post" button to check it's all good.
( e ) Use the "Submit Modified Post" button to finish the editing.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1