Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I don\'t know how to implement the following project with a Print function to an

ID: 3561761 • Letter: I

Question

I don't know how to implement the following project with a Print function to an output file using an input file. Please help and be as detailed in your help as possible.

In this project, you will implement a Stack based on Array. The program consists of one class, Stack. The logical description of the class is as follows:

1. Stack

(a) The stack in this project is based on array in "int" type.

(b) The Stack class has two member variables;

(i) int top: this indicates the index of item on the top of the stack

(ii) int item[]: this is an array that holds actual integer data

(c) Operations

(i) Stack()

*This is a constructor of the Stack class.

(ii) bool IsEmpty() const

*This function checks if the stack is empty.

(iii) void IsFull() const

*This function checks if the stack is full.

(iv) void push( int item)

*This function pushes new item(integer type) in the stack if the stack is not full.

*Stack can have duplicate data in it; please refer to the sample output.

(v) void Pop()

*This function pops the item on the top of the stack.

(vi) int Top() const

*THis function returns the item (data in int type) on the top of the stack.

(vii) Bool CheckItem(int item)

*THis function checks if item is in the Stack. If it is, return true. Else, return false.

(viii) Void PrintStack (ofstream& outfile)

*This function prints the contents of the Stack from top to bottom (in vertical manner); please refer to the sample output.

To run your program, there will be an input file that contains the sequence of operations. When your program gets started, it should ask its user the input file name so that your program reads the contents of that input file. The following is input-output examples.

input output

Push 3 Operation: Push 3

Push 13 3

Push 26 --------------

Pop Operation: Push 13

Top 13

3

-------------------

Operation: Push 3

3

13

3

-----------------------

Operations: Push 26

26

3

13

3

-------------------

Operation: Pop

3

13

3

-----------------------

Operation: Top

3 is on the top of the stack.

3

13

3

----------------------

Explanation / Answer

First, we must inform the LEDA error handler that it shall throw an exception on the occurrence of an error, which we then will catch. This is carried out by the statement

The exception thrown by LEDA is of the type leda_exception. An object of this type contains an error number corresponding to the exception and an error message. These contents can be accessed by the methods

Thereby, if a catch possibly must catch several exceptions at the same position, the type of the exception can be found out. This makes a handling adapted to the respective exception possible.[24]

Let us now test the above insufficient input once again:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote