5 Replies - 2679 Views - Last Post: 16 March 2012 - 11:26 PM Rate Topic: -----

#1 cieru  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 16-January 12

Circular Queue Implementation

Posted 14 March 2012 - 11:08 PM

Hello, :)

We're having a problem about Circular Queue Implementation,
We are directed to create any small system that will use the solution circular queue that will act like a linked list. So far my we had edited the Circular queue code that our teacher given us, but the code she had given only use int types and can only manipulate one data only. We don't have any clue on how to pass numerous data to every array of the circular queue that will act like a node storage. We're trying to pass a structure to the enqueue function, but we can only insert 1 char only...instead of a whole string...
this is the code we formulated but can only input one characters at every needed data..we are having problems also on the deletion and display...


THANK YOU...we are really trying our best to finish this...not just for the requirement but our priority is to learn the algorithm behind for our future field in programming :D
WE will appreciate all of the help and suggestions thank you :)


#include<iostream>
#define SIZE 10
using namespace std;

struct info{

	int month[SIZE];
	int day[SIZE];
	int year[SIZE];
	char ownername[SIZE];
	char petname[SIZE];
	char specie[SIZE];
	char breed[SIZE];
};

void insert(char y[],char z[],char a[],char b[],int m[],int d[],int yr[]);
//void del(char y[],char z[],char a[],char b[],int m[],int d[],int yr[]);
void update(char y[],char z[],char a[],char b[],int m[],int d[],int yr[]);
void searchanddisplay(char y[],char z[],char a[],char b[],int m[],int d[],int yr[]);
//void display(char y[],char z[],char a[],char b[],int m[],int d[],int yr[]);

int front=-1;
int rear=-1;

int main()
{
	info a;
	while(1)
	{
		int choice;
		system("cls");

		cout<<"*****Pet's GROOMING CENTER*****\n\n"
			<<"MENU: \n"
			<<"[1] INSERT\n"
			<<"[2] DELETE\n"
			<<"[3] UPDATE\n"
			<<"[4] SEARCH AND DISPLAY\n"
			<<"[5] DISPLAY ALL DATA\n"
			<<"[6] EXIT\n"
			<<"------------------------------------------\n\n"
			<<"Please Enter Your Choice: ";
		cin>>choice;

		switch(choice)
		{
		case 1:
			{
				insert(a.ownername,a.petname,a.specie,a.breed,a.month,a.day,a.year);
				break;
			}
		/*case 2:
			{
				del(a.ownername,a.petname,a.specie,a.breed,a.month,a.day,a.year);
				break;
			}*/
		case 3:
			{
				update(a.ownername,a.petname,a.specie,a.breed,a.month,a.day,a.year);
				break;
			}
		case 4:
			{
				searchanddisplay(a.ownername,a.petname,a.specie,a.breed,a.month,a.day,a.year);
				break;
			}
		/*case 5:
			{
				display(a.ownername,a.petname,a.specie,a.breed,a.month,a.day,a.year);
				break;
			}*/
		case 6:
			{
				exit(1);
			}
		default:
			{
				cout<<"Sorry. You have entered a wrong value.\n";
			}
		}
		cout<<endl;
		system("pause>0");
	}
	return 0;

}

void insert(char y[],char z[],char a[],char b[],int m[],int d[],int yr[])
{
	int t=0;
	if(front==-1)
	{
		front=0;
		rear=0;
		cout<<"Welcome! You are costumer no. "<<rear;
		cout<<"\nOwner's name: ";
		cin>>y[rear];
		cin.ignore();
		cout<<"Pet's name: ";
		cin>>z[rear];
		cin.ignore();
		cout<<"Specie: ";
		cin>>a[rear];
		cin.ignore();
		cout<<"Breed: ";
		cin>>b[rear];
		cin.ignore();
		cout<<"\nDate of consultation: ";
		while(t==0)
		{
			cout<<"\nmonth: ";
			cin>>m[rear];
			if(m[rear]>12)
			{
				cout<<"\nmonth entered doesn't exist.";
				system("pause>0");
			}
			else
				t=1;
		}
		t=0;
		while(t==0)
		{
			cout<<"\nday: ";
			cin>>d[rear];
			if(d[rear]>31)
			{
				if(m[rear]==2){
					if(d[rear]>29){
						cout<<"\nday entered doesn't exist.";
						system("pause>0");
					}
				}
				cout<<"\nday entered doesn't exist.";
				system("pause>0");
			}
			else
				t=1;
		}
		t=0;
		cout<<"\nYear:";
		cin>>yr[rear];

	}
	else if((rear+1)%SIZE==front)
		cout<<"Sorry, system is already full.";

	else
	{
		rear=(rear+1)%SIZE;
		cout<<"Welcome! You are costumer no. "<<rear;
		cout<<"\nOwner's name: ";
		cin>>y[rear];
		cin.ignore();
		cout<<"Pet's name: ";
		cin>>z[rear];
		cin.ignore();
		cout<<"Specie: ";
		cin>>a[rear];
		cin.ignore();
		cout<<"Breed: ";
		cin>>b[rear];
		cin.ignore();
		cout<<"\nDate of consultation: ";
		while(t==0)
		{
			cout<<"\nmonth: ";
			cin>>m[rear];
			if(m[rear]>12)
			{
				cout<<"\nmonth entered doesn't exist.";
				system("pause>0");
			}
			else
				t=1;
		}
		t=0;
		while(t==0)
		{
			cout<<"\nday: ";
			cin>>d[rear];
			if(d[rear]>31)
			{
				if(m[rear]==2){
					if(d[rear]>29){
						cout<<"\nday entered doesn't exist.";
						system("pause>0");
					}
				}
				cout<<"\nday entered doesn't exist.";
				system("pause>0");
			}
			else
				t=1;
		}
		t=0;
		cout<<"\nYear:";
		cin>>yr[rear];

	}
}

//void del(char y[],char z[],char a[],char b[],int m[],int d[],int yr[])
//{
//}
void update(char y[],char z[],char a[],char b[],int m[],int d[],int yr[])
{
	int edit;
	int t=0;
	cout<<"Please Enter The Costumer no. of the data you want to update: ";
	cin>>edit;

	if(edit>rear)
		cout<<"Data doesn't exist.";
	cout<<"\nOwner's name: ";
		cin>>y[edit];
		cin.ignore();
		cout<<"Pet's name: ";
		cin>>z[edit];
		cin.ignore();
		cout<<"Specie: ";
		cin>>a[edit];
		cin.ignore();
		cout<<"Breed: ";
		cin>>b[edit];
		cin.ignore();
		cout<<"\nDate of consultation: ";
		while(t==0)
		{
			cout<<"\nmonth: ";
			cin>>m[edit];
			if(m[edit]>12)
			{
				cout<<"month entered doesn't exist.";
				system("pause>0");
			}
			else
				t=1;
		}
		t=0;
		while(t==0)
		{
			cout<<"\nday: ";
			cin>>d[edit];
			if(d[edit]>31)
			{
				if(m[edit]==2){
					if(d[edit]>29){
						cout<<"\nday entered doesn't exist.";
						system("pause>0");
					}
				}
				cout<<"\nday entered doesn't exist.";
				system("pause>0");
			}
			else
				t=1;
		}
		t=0;
		cout<<"\nYear:";
		cin>>yr[edit];

		cout<<"You have successfully updated the data.";
}
void searchanddisplay(char y[],char z[],char a[],char b[],int m[],int d[],int yr[])
{
	int search;
	cout<<"Please enter the costumer number you want to search and display: ";
	cin>>search;

	if(search>rear)
		cout<<"\n\nData doesn't exist.";
	
	cout<<"Data found: \n";
	cout<<"\nOwner's Name: "<<y[search];
	cout<<"\nPet's Name: "<<z[search];
	cout<<"\nSpecie: "<<a[search];
	cout<<"\nBreed: "<<b[search];
	cout<<"\nDate of consultation: "<<m[search]<<"/"<<d[search]<<"/"<<yr[search];
	

}
//void display(char y[],char z[],char a[],char b[],int m[],int d[],int yr[])





Is This A Good Question/Topic? 0
  • +

Replies To: Circular Queue Implementation

#2 cieru  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 16-January 12

Re: Circular Queue Implementation

Posted 14 March 2012 - 11:21 PM

bump
Was This Post Helpful? 0
  • +
  • -

#3 cieru  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 16-January 12

Re: Circular Queue Implementation

Posted 15 March 2012 - 01:48 AM

bump
Was This Post Helpful? 0
  • +
  • -

#4 simeesta  Icon User is offline

  • Deadly Ninja


Reputation: 219
  • View blog
  • Posts: 592
  • Joined: 04-August 09

Re: Circular Queue Implementation

Posted 15 March 2012 - 02:25 AM

Try having an array of struct's instead of a structure with lots of arrays in. That way you only have to pass one argument to each function instead of 7.
Was This Post Helpful? 0
  • +
  • -

#5 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5932
  • View blog
  • Posts: 12,855
  • Joined: 16-October 07

Re: Circular Queue Implementation

Posted 15 March 2012 - 06:16 AM

Parallel arrays?!? Usually a bad idea. Also, you seem unclear on if you're using string or not. Since you've got std, use the string.

e.g.
#include<iostream>

using namespace std;

struct info{
	int month, day, year;
	string ownername, petname, specie, breed;
};


#define QUEUE_MAX_SIZE 10

struct MyQueue {
	int front, rear;
	info items[QUEUE_MAX_SIZE];
	MyQueue() : front(-1), rear(-1) { } 
};

void insert(MyQueue &, const info &);
void update(MyQueue &, const info &);
void searchanddisplay(MyQueue &, const info &);
info getFromUser();
void optInsert(MyQueue &);

int menu() {
	int choice;

	cout<<"*****Pet's GROOMING CENTER*****\n\n"
		<<"MENU: \n"
		<<"[1] INSERT\n"
		<<"[2] DELETE\n"
		<<"[3] UPDATE\n"
		<<"[4] SEARCH AND DISPLAY\n"
		<<"[5] DISPLAY ALL DATA\n"
		<<"[6] EXIT\n"
		<<"------------------------------------------\n\n"
		<<"Please Enter Your Choice: ";
	cin>>choice;
	return choice;
}

int main() {
	MyQueue q;
	bool done = false;
	while(!done) {
		switch(menu()) {
		case 1: 
			optInsert(q);
			break;
		/* ... */
		case 6:
			done = true;
			break;
		default:
			cout<<"Sorry. You have entered a wrong value.\n";
		}
	}
	return 0;
}



Hope this helps.
Was This Post Helpful? 0
  • +
  • -

#6 cieru  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 16-January 12

Re: Circular Queue Implementation

Posted 16 March 2012 - 11:26 PM

thanks I'll try to edit my code and see if it comes okay :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1