473,597 Members | 2,157 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

class stack&queue.ine ed some help

plz check what i have made wrong what is requierd her is to creat class
queue and class stack and run the push,pop operation .
#include<iostre am.h>
#include<conio. h>
#include<stdio. h>
class stack
{
public:

spop();
spush();
sout();
void s_Menu();
void Main_Menu();
private:
int list[];
int listsize,item,r ear,front;
};

class queue
{
public:
qpop();
qpush();
qout();
void q_Menu();
iempty();
private:
int list2[];
int listsize2,item2 ;
int rear;
int front;

};
int top=-1;
char ch;
void stack:: Main_Menu()
{

stack s;
queue q;
gotoxy(20,3);co ut<<"********** *************** *************** **";
gotoxy(20,4);co ut<<"* *";
gotoxy(20,5);co ut<<"* *";
gotoxy(20,6);co ut<<"********** *************** *************** **";
gotoxy(30,9);co ut<<"********** *************** ";
gotoxy(30,10);c out<<"* MAIN PROGRAM MENU *";
gotoxy(30,11);c out<<"*Stack Queue Operations *";
gotoxy(30,12);c out<<"*[S] Stack *";
gotoxy(30,13);c out<<"*[Q] Queue *";
gotoxy(30,14);c out<<"*[E] Exit *";
gotoxy(30,15);c out<<"********* *************** *";
//char ch='y';

while((ch!='E') &&(ch!='e'))
{
cout<<"\nEnter your selection : ";
// cin>>ch;
ch = getche();
switch(ch)

{
case 'S','s':

s.s_Menu();

break;
case 'Q','q':

q.q_Menu();
break;
}
} }
void stack:: s_Menu()
{
stack s;

gotoxy(30,9);co ut<<"********** *************** ";
gotoxy(30,10);c out<<"* Stack *";
gotoxy(30,11);c out<<"*[P] Stack push *";
gotoxy(30,12);c out<<"*[O] Stack pop *";
gotoxy(30,13);c out<<"*[D] stack Display *";
gotoxy(30,14);c out<<"*[R] Return *";
gotoxy(30,15);c out<<"********* *************** *";
//char ch;
while(ch!='R')

{
// cout<<"\n Enter your selection : ";
// cin>>ch;
ch = getche();
switch(ch)
{
case 'P','p':

s.spush();

break;

case 'O','o':
item=s.spop();
if(item!=-9999)

cout<<"\n The popped value is..."<<item;

break;

case 'D','d':
cout<<"\n The stack is...:";
s.sout();
break;

case 'R','r':
clrscr();
s.Main_Menu();
}
}

}
void queue::q_Menu()
{
queue q;
stack s;
gotoxy(30,9);co ut<<"********** *************** *";
gotoxy(30,10);c out<<"* Queue *";
gotoxy(30,11);c out<<"*[P] Queue push *";
gotoxy(30,12);c out<<"*[O] Queue pop *";
gotoxy(30,13);c out<<"*[D] Queue Display *";
gotoxy(30,14);c out<<"*[R] Return *";
gotoxy(30,15);c out<<"********* *************** **";

while(ch!='R')

{
// cout<<"\n Enter your selection : ";
// cin>>ch;
ch = getche();
switch(ch)
{
case 'p','p':

q.qpush();

break;

case 'o','o':
item2=q.qpop();
if(item2 !=-9999)
cout<<"\n The popped value is .."<<item2;
break;

case 'd','d':
cout<<"\n The queue is...:";
q.qout();
break;

case 'r','r':
clrscr();
s.Main_Menu();
}
}
}


void main()
{

stack s;

s.Main_Menu();

}


stack::spush ()
{

cout<<"\n Enter the valu to be pushed : ";
cin>>item;
if (top<listsize)
{
top++;
list[top]=item;
}
else
cout<<"\n The stack is full";
};

stack::spop()
{
int v;
if(top>=0)
{
v=list[top];
top--;
return v;
}
else
{
cout<<"\n stack is empty";

return(-9999);
}
};
stack::sout()
{
int i;
if(top>=0)
{
cout<<"\n";
for (i=top;i>=0;i--)
cout<<list[i]<<" ";
}

};
//*************** *************** *************** *******
queue::qpush()
{
cout<<"\n Enter the value to pushed : ";
cin>>item2;
if (rear+1%listsiz e2==front)
{
cout<<"\n The queue is full";
}
else
rear=(rear+1)%l istsize2;
list2[rear]=item2;
}

queue::qpop()
{
int v2;
if(front!=rear)

{
front=(front+1) %listsize2;
v2=list2[front];
return v2;
}
else
cout<<"\n queue is empty";
return(-9999);// returns a value -9999 if the queue is empty
}
queue::qout()
{
int i2;
i2=front;
while(i2!=rear)
{
i2=(i2+1)%lists ize2;
cout<<list2[i2]<<" ";
}
}

Nov 22 '05 #1
4 2142
alisaee wrote:
plz check what i have made wrong what is requierd her is to creat class
queue and class stack and run the push,pop operation .
#include<iostre am.h>
This header is deprecated. Use <iostream> (you may also want to add
"using namespace std;").

#include<conio. h>
Non-standard header.
#include<stdio. h>
Unnecessary and prefer iostreams.
class stack
{
public:

spop();
spush();
sout();
You should have return types for these functions. C defaults to int;
standard C++ doesn't. You're (perhaps unwittingly) using a compiler
extension that is best avoided.
void s_Menu();
void Main_Menu();
Main_Menu should not be a member function of stack. Just make it an
ordinary function, or at the very least make it a static member
function. Arguably, s_Menu should not be a member either since it mixes
the functionality of the stack class with the user interface. Prefer
one concept per class.
private:
int list[];
You need a limit here, or you need to use a pointer and allocate the
memory dynamically. If you choose the latter, prefer a smart pointer
like boost::scoped_a rray.
int listsize,item,r ear,front;
};

class queue
{
public:
qpop();
qpush();
qout();
void q_Menu();
iempty();
How about isEmpty() instead of iempty()? Also, add return types, and
make q_Menu() a non-member.
private:
int list2[];
int listsize2,item2 ;
int rear;
int front;

};
int top=-1;
char ch;

Avoid global variables like these two. Pass necessary parameters into
functions and minimize variable scope as much as possible. It makes
code easier to understand and debug.

void stack:: Main_Menu()
{

stack s;
queue q;
gotoxy(20,3);co ut<<"********** *************** *************** **";
gotoxy(20,4);co ut<<"* *";
gotoxy(20,5);co ut<<"* *";
gotoxy(20,6);co ut<<"********** *************** *************** **";
gotoxy(30,9);co ut<<"********** *************** ";
gotoxy(30,10);c out<<"* MAIN PROGRAM MENU *";
gotoxy(30,11);c out<<"*Stack Queue Operations *";
gotoxy(30,12);c out<<"*[S] Stack *";
gotoxy(30,13);c out<<"*[Q] Queue *";
gotoxy(30,14);c out<<"*[E] Exit *";
gotoxy(30,15);c out<<"********* *************** *";
//char ch='y';

while((ch!='E') &&(ch!='e'))
{
cout<<"\nEnter your selection : ";
// cin>>ch;
ch = getche();
Prefer cin.
switch(ch)

{
case 'S','s':

[snip]

This won't work. Try:

case 'S':
case 's':

I could make many more comments, but it is obvious that your program
has many issues. If you need more help, please ask specific questions.
Know, however, that we're not going to do your homework for you. You
might also be interested in the group alt.comp.lang.l earn.c-c++, which
is concerned with learning the language, the FAQ for this group which
answers many common questions (http://www.parashift.com/c++-faq-lite/),
and our favorite book for learning C++: _Acclerated C++_ by Koenig and
Moo. This forum is for discussions about the language itself (not
applications), so feel free to post again if you have questions about
the language itself.

Cheers! --M

Nov 22 '05 #2
alisaee wrote:
plz check what i have made wrong what is requierd her is to creat class
queue and class stack and run the push,pop operation .


Too much code, and none of it works.

You are doing this the wrong way, write small ammounts of code and get
that code working before writing any more code. You should throw this
code away, it's a waste of time.

Also you've put too much priority on menus and such, that isn't the
point of the exercise. Forgot about fancy menus and concentrate on
getting the queue and stack working.

And this should be obvious by now but do either the stack or the queue
first (your choice). Don't try to do both at once! Follow this advice
and it will be easier.

john
Nov 22 '05 #3
miimber & john ,thanx.

Nov 22 '05 #4
miimber & john ,thanx.

Nov 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
4200
by: WittyGuy | last post by:
Hi all, Though I know the concepts of both abstract class & virtual function (like derived class pointer pointing to base class...then calling the function with the pointer...), what is the real implementation usage of these concepts? Where these concepts will be used. Please provide some illustration (real-time), so that it can be easily comprehended. Thanks, wittyGuy
5
10224
by: herrcho | last post by:
int main() { printf("Input a line: "); wrt_it(); printf("\n\n"); return 0; } void wrt_it() {
2
1278
by: Jim Bancroft | last post by:
Hi all, I'm writing an exception handler for one of my VB.Net methods and wondered how best to dynamically put the class and method name in my message string. My code looks like this currently: Catch ex as Exception
12
2519
by: mast2as | last post by:
Hi everyone... I have a TExceptionHandler class that is uses in the code to thow exceptions. Whenever an exception is thrown the TExceptionHander constructor takes an error code (int) as an argument. I was hoping to create a map<int, const char*that would be used in the showError member function of the TExceptionHandler class where the key (int) would be the error code and const char* the message printed out to the console. My question...
0
970
by: Stan SR | last post by:
Hi, It's maybe a stupid question. I have a class that I call from each of my pages. I would like to know if it's possible to "instantiate" this class from my masterpage and call all the methods and properties from my page ?
8
1970
by: mast2as | last post by:
Hi guys, I think from what I found on the net that the code is correct and there's no problem when I compile the files. The problems occurs when I link them. I have a friend function which outputs points data to the ostream. Here is the error message: objs/generalpolygons.o(.text+0xf08): In function `GeneralPolygons::readObjFile(std::basic_string<char, std::char_traits<char>, std::allocator<char)': core/generalpolygons.cpp:222:...
4
4300
by: Donos | last post by:
Hi I have a HANDLE to an Event, like this.. HANDLE h = ::CreateEvent(NULL, FALSE, FALSE, NULL); This is running in one thread in one class. For example we will call that class as "Class A" Now i want to use this HANDLE in another thread in another class to
2
1137
by: mnarewec | last post by:
Forgive me if this is a silly question. I am looking for the option where you can set so that like in VB you can see the methods of controls you design on the form when you view its code. For example in VB if you have a button1 on the form in the design mode. When you in the code mode (Press F7) you will see two drop downs. One for the class and one for the method. If I select the Button1 class in class drop down List then I will be see...
0
1058
by: phanipep | last post by:
4 applications of stacks and queues. Justify your choices.
0
7965
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7885
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8380
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8031
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6686
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5847
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3923
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1493
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1231
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.