answersLogoWhite

0


Best Answer

#include<iostream.h>

#include<process.h>

#define SIZE 10

class Stack

{

private:

int a[SIZE];

int top;

public:

Stack();

void push(int);

int pop();

int isEmpty();

int isFull();

void display();

};

Stack::Stack()

{

top=0;

}

int Stack::isEmpty()

{

return (top==0?1:0);

}

int Stack::isFull()

{

return(top==SIZE?1:0);

}

void Stack::push(int i)

{

try

{

if(isFull())

{

throw "Full";

}

else

{

a[top]=i;

top++;

}

}

catch(char *msg)

{

cout<<msg;

}

}

int Stack::pop()

{

try

{

if(isEmpty())

{

throw "Empty";

}

else

{

return(a[--top]);

}

}

catch(char *msg)

{

cout<<msg;

}

return 0;

}

void Stack::display()

{

if(!isEmpty())

{

for(int i=top-1;i>=0;i--)

cout<<a[i]<<endl;

}

}

int main()

{

Stack s;

int ch=1;

int num;

while(ch!=0)

{

cout<<"1. push"<<endl

<<"2. pop"<<endl

<<"3. display"<<endl

<<"0. Exit"<<endl;

cout<<"Enter ur choice :";

cin>>ch;

switch(ch)

{

case 0: exit(1);

case 1: cout<<"Enter the number to push";

cin>>num;

s.push(num);

break;

case 2: cout<<"a number was popped from the stack"<<endl;

s.pop();

break;

case 3: cout<<"The numbers are"<<endl;

s.display();

break;

default:

cout<<"try again";

}

}

return 0;

}

#include<iostream.h>

#define SIZE 10

class Queue

{

private:

int rear;

int front;

int s[SIZE];

public:

Queue()

{

front=0;

rear=-1;

}

void insert(int);

void del();

int isEmpty();

int isFull();

void display();

};

int Queue::isEmpty()

{

return(front>rear?1:0);

}

int Queue::isFull()

{

return(rear==SIZE?1:0);

}

void Queue::insert(int item)

{

try

{

if(isFull())

{

throw "Full";

}

else

{

rear=rear+1;

s[rear]=item;

}

}

catch(char *msg)

{

cout<<msg;

}

}

void Queue::del()

{

int item;

try

{

if(isEmpty())

{

throw "Empty";

}

else

{

item=s[front];

front=front+1;

cout<<"\n DELETED ELEMENT IS %d\n\n"<<item;

}

}

catch(char *msg)

{

cout<<msg;

}

}

void Queue::display()

{

cout<<"\n";

for(int i=front;i<=rear;i++)

{

cout<<s[i]<<"\t";

}

}

int main()

{

int ch;

Queue q;

int item;

do

{

cout<<"\n\n1.INSERTION \n";

cout<<"2.DELETION \n";

cout<<"3.EXIT \n";

cout<<"\nENTER YOUR CHOICE : ";

cin>>ch;

switch(ch)

{

case 1:

cout<<"\n\t INSERTION \n";

cout<<"\nENTER AN ELEMENT : ";

cin>>item;

q.insert(item);

q.display();

break;

case 2:

cout<<"\n\t DELETION \n";

q.del();

q.display();

break;

}

}while(ch!=3);

return 0;

}

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Design stack and queue classes with necessary exception handling?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is defferred exceptional handling?

Deferred exception handling refers to a programming design pattern where individual class level methods do not handle exceptions using try catch blocks. They just cascade the exceptions to the calling methods using the "throw" keyword and all exceptions are handled centrally in one place. This is called deferred exception handling where the exceptions are deferred in the place where they occur and propagated to a parent class which handles it.


What are the FEM rules for the design of hoisting appliances?

RULES FROM European Mechanical Handling Confederation.


What courses are offered at interior design school?

Interior design students study drawing, design, and CAD. They also study the application of design skills to both residential and commercial properties. Most interior design schools have classes in art, architecture, design principles, textiles, and business.


What subjects need for an interior design course?

If you're asking the classes you should take to get into interior design school, all the art and business classes you can talke while in high school will help. If you're looking for a great interior design college, FIDM/Fashion Institute of Design &amp; Merchandising in LA is a great interior design college! The school has a great reputation and an awesome career center. If you want more information on FIDM's interior design program, check out their website :)and visit interior designing site.


Do you need a degree to work in landscape design?

No, you don't need a degree, but it does help. A degree with classes in architecture and design will help you learn the skills you need, and look good on your resume.

Related questions

What is defferred exceptional handling?

Deferred exception handling refers to a programming design pattern where individual class level methods do not handle exceptions using try catch blocks. They just cascade the exceptions to the calling methods using the "throw" keyword and all exceptions are handled centrally in one place. This is called deferred exception handling where the exceptions are deferred in the place where they occur and propagated to a parent class which handles it.


What classes are offered in the california design college?

"There are many classes offered in the california design college. Environmental design classes, art, painting, scultping and drama classes. Many different forms of design are availible."


What classes are required for interior design?

Classes on Fine Art, 3D Designs and Interior Architecture are important for interior designing.


Do you know of any interior design online classes?

Sheffield School offers excellent interior design online classes.


What colleges have business website design classes?

Most colleges these days offer classes in web design. Houston Community College offers web design courses and it's easy to enroll and supplement with any other classes.


How much does it cost to take web design classes?

The cost of web design classes various depending on where you go, but most schools require tuition ranging from $40,000 to $80,000 for web design classes. You can also learn web design online from various websites for free.


What in the average length of most interior design online classes?

Most interior design classes at community colleges last 6 months.


What type of classes are good for learning how to design a webpage?

The classes that are best to for learning website design include HTML, XHTML, Java, and CSS. It is best to also look into classes about Photoshop, using multimedia, basic web design and creating graphics.


What are the disadvantages of materials handling?

The primary disadvantage of materials handling is that the handler can be injured while doing it, especially if it is done manually and incorrectly or without adequate handling aids.Materials handling can result in costly damage to the items being handled, again if not done with care and appropriate aids.Materials handling can also be unnecessarily costly if the items are handled more often than absolutely necessary, even if not damaged and no one is injured.Careful planning, design and operation of the materials handling process can minimize or eliminate many of these disadvantages.


How can I find more information to learn about interior design training?

There are several good sites to go to when inquiring about interior design. I have found one called www.theinteriordesigninstitute.com. They offer classes on interior design. Home Depot does not do a course on interior design specifically, but they do have classes on paint and how to match certain color together. They also have classes on how to design with paint.


What websites offer design classes?

The Art Institute website offers a variety of design classes that you can take online. Devry University is another website that offers college courses to get your design degree.


How are aerodynamic design are used to improve cars?

Aerodynamic design improves fuel mileage, handling, and how quiet the car is when traveling.