Hi..Iwant change this program to char

I want to chang this program to char and the user continue to input and it is full, Display a message, "It's Full!". also
Allow the user to choose an option, to delete an item or not, if the user delete an item, display the item deleted. If the user choose not to delete, display all the items.

this is the program:

# include<iostream.h>
# include<conio.h>
# define SIZE 3

class queue
{
int a[SIZE];
int front;
int rear;
public:
queue();
~queue();
void insert(int i);
int remove();
int isempty();
int isfull();
};

queue::queue()
{
front=0;
rear=0;
}
queue::~queue()
{
delete []a;
}
void queue::insert(int i)
{
if(isfull())
{
cout<<"\n******Queue is FULL !!!No insertion allowed further.******";
return;
}
a[rear] = i;
rear++;
}
int queue::remove()
{


if(isempty())
{
cout<<"\n******Queue Empty !!!Value returned will be garbage.******\n";

return (-9999);
}

return(a[front++]);

}

int queue::isempty()
{
if(front == rear)
return 1;
else
return 0;
}

int queue::isfull()
{
if(rear == SIZE)
return 1;
else
return 0;
}

void main()
{
clrscr();
queue q;
int item;

while (!q.isfull())
{
cin>>item;
q.insert(item);
}

while(!q.isempty())

cout<<"\n "<<q.remove();
cout<<"\n"<<q.remove();
getch();
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# include<iostream.h>
# include<conio.h>
# define SIZE 3


class queue
{
	private:
			int a[SIZE];
			int front;
			int rear;
	public:	
			queue();
			~queue();
			void insert(int i);
			int remove();
			int isempty();
			int isfull();
			int display(int n);
};

queue::queue()
{
	front=0;
	rear=0;
}
queue::~queue()
{
	
}
void queue::insert(int i)
{
	if(isfull())
	{
		cout<<"\n******Queue is FULL !!!No insertion allowed further.******";
		return;
	}
		a[rear] = i;
		rear++;
}
int queue::remove()
{


	if(isempty())
	{
			cout<<"\n******Queue Empty !!!Value returned will be garbage.******\n";

			return ;
	}
	int i = SIZE ; 
	while( i--)
	{
		a[i] = 0;
	};

	return(a[0]);

}

int queue::isempty()
{
	if(front == rear)
		return 1;
	else
	return 0;
}

int queue::isfull()
{
	if(rear == SIZE)
		return 1;
	else
		return 0;
}
int queue::display( int n )
{
	int i = a[n];
	return i; 
}

void main()
{
	clrscr();
	queue q;
	int item;

	while (!q.isfull())
	{
		cin>>item;
		q.insert(item);
	}

	while(!q.isempty())
	{
		int n = SIZE ; 
		cout << display( n) ;
		n--;
	}

	cout<<"\n "<<q.remove();
	cout<<"\n"<<q.remove();
	getch();
}
Thank you alot..But I want to know how to chang this program to make it enter character..
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# include<iostream>
using namespace std;
# define SIZE 3


class queue
{
	private:
			int a[SIZE];
			int front;
			int rear;
	public:	
			queue();
			~queue();
			void insert(int i);
			int remove();
			int isempty();
			int isfull();
			int display(int n);
};

queue::queue()
{
	front=0;
	rear=0;
}
queue::~queue()
{
	
}
void queue::insert(int i)
{
	if(isfull())
	{
		cout<<"\n******Queue is FULL !!!No insertion allowed further.******";
		return;
	}
		a[rear] = i;
		rear++;
}
int queue::remove()
{


	if(isempty())
	{
			cout<<"\n******Queue Empty !!!Value returned will be garbage.******\n";

			return (-9999);
	}
	int i = SIZE ; 
	while( i--)
	{
		a[i] = 0;
	};

	return(a[0]);

}

int queue::isempty()
{
	if(front == rear)
		return 1;
	else
	return 0;
}

int queue::isfull()
{
	if(rear == SIZE)
		return 1;
	else
		return 0;
}
int queue::display( int n )
{
	int i = a[n];
	return i; 
}

void main()
{
	
	queue q;
	int item;

	while (!q.isfull())
	{
		cin>>item;
		q.insert(item);
	}

	while(!q.isempty())
	{
		int n = SIZE ;
		
		cout<<q.display(n);
		n--;
	}

	cout<<"\n "<<q.remove();
	cout<<"\n"<<q.remove();
	
}
Last edited on
If you mean changing it to a queue of strings of characters, you can use std::string:

http://cplusplus.com/reference/string/string/

which can be read from std::in and written to std::out just like an int.
Last edited on
I mean insted of int i use want to use char..
Then just replace the int's by char's

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class queue
{
	private:
		char a[SIZE];
		int front;
		int rear;
	public:	
		queue();
		~queue();
		void insert(char i);
		char remove();
		int isempty();
		int isfull();
		char display(int n);
};

and make the appropriate changes on the method definitions. Or consider using templates: http://cplusplus.com/doc/tutorial/templates

Also, the return value of isempty and isfull is better represented as a bool value.
I have another problem when I compile it I have so many 0000000 with no end to this process..


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# include<iostream>
using namespace std;
# define SIZE 3


class queue
{
	private:
			char a[SIZE];
			int front;
			int rear;
	public:	
			queue();
			~queue();
			void insert(int i);
			char remove();
			int isempty();
			int isfull();
			char display(int n);
};

queue::queue()
{
	front=0;
	rear=0;
}
queue::~queue()
{
	
}
void queue::insert(int i)
{
	if(isfull())
	{
		cout<<"\n******Queue is FULL !!!No insertion allowed further.******";
		return;
	}
		a[rear] = i;
		rear++;
}
int queue::remove()
{


	if(isempty())
	{
			cout<<"\n******Queue Empty !!!Value returned will be garbage.******\n";

			return (-9999);
	}
	int i = SIZE ; 
	while( i--)
	{
		a[i] = 0;
	};

	return(a[0]);

}

int queue::isempty()
{
	if(front == rear)
		return 1;
	else
	return 0;
}

int queue::isfull()
{
	if(rear == SIZE)
		return 1;
	else
		return 0;
}
int queue::display( int n )
{
	int i = a[n];
	return i; 
}

void main()
{
	
	queue q;
	int item;

	while (!q.isfull())
	{
		cin>>item;
		q.insert(item);
	}

	while(!q.isempty())
	{
		int n = SIZE ;
		
		cout<<q.display(n);
		n--;
	}

	cout<<"\n "<<q.remove();
	cout<<"\n"<<q.remove();
	
}
Last edited on
just use trim function on the string .
How can i use trim function
Topic archived. No new replies allowed.