0% found this document useful (0 votes)
46 views2 pages

Video 23

The document describes a Stack class implementation that stacks strings. It defines exception classes for a full or empty stack. The class constructor takes the stack size. Methods like push, pop and top interface with the stack and check for exceptions. Tests need to be implemented to validate the Stack class.

Uploaded by

abu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views2 pages

Video 23

The document describes a Stack class implementation that stacks strings. It defines exception classes for a full or empty stack. The class constructor takes the stack size. Methods like push, pop and top interface with the stack and check for exceptions. Tests need to be implemented to validate the Stack class.

Uploaded by

abu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Unix_C++_SYS_Mini_Project

Implement Stack class that stacks “strings” as per the specification given below:

class StackFull {}; // used as exception-type


class StackEmpty {}; // used as exception-type

Class Stack
{
public:
Stack(int n); // creates an array of “n” strings (C++ string type)
void push(const string& s) throw(StackFull);
// has to push string “s” onto the stack.
// in case stack is full, should throw StackFull exception
void pop(string& s) throw(StackEmpty);
// has to pop string from stack and return it through argument “s”
// in case stack is empty, should throw StackEmpty exception

void top(string& s) throw(StackEmpty);


// has to return the topmost element of the stack through argument “s”
// in case stack is empty, should throw StackEmpty exception
bool isEmpty(); // should return true if the stack is empty; otherwise false
bool isFull); // should return true if the stack is empty; otherwise false
~Stack(); // should perform cleanup
private:
string *arystr;
int top;
int stacksize;
};
a) Implement different test cases to test the correctness of the Stack class implementation.
Call the test functions in main().

---X---

You might also like