PC-Stack Class
PC-Stack Class
Problem Description
You are asked to develop a class called Stack which has the following private data
members:
int size; // size of a stack
int count; //number of characters in the stack.
char * charStack; // a pointer pointing to a character array created
// dynamically using new statement
and the following public member functions:
Stack(int =10); // Constructor with default stack size equal to 10
void push(char ); // insert a character on the top of a stack
char pop(); // remove a character from the top of a stack
bool isEmpty(); // return true if a stack is empty
bool isFull();// return true if a stack is full
void resize(int s); // increase the size of a stack by s bytes. If s<0, ignore resizing
~Stack(); // Destructor should use delete[] to release the allocated memory.
When the constructor is called, print out a message “A stack is created.” When the
destructor is called, print out a message “A stack is destroyed.” An instance of Stack
class can store characters which can only be popped out in the reverse order of being
pushed into the stack. You must first implement Stack class and then a program using
the Stack class to reverse an article. Below is an example where the upper part is the
input and the lower part is the output. Space and tap characters should be printed.
Input:
{
// place digits of argument into array
digits = 0;
long tempValue = value;
while (tempValue != 0)
{
digits++;
tempValue = tempValue / 10;
}
Output:
}
;01 / eulaVpmet = eulaVpmet
;++stigid
{
)0 =! eulaVpmet( elihw
;eulav = eulaVpmet gnol
;0 = stigid
yarra otni tnemugra fo stigid ecalp //
{
Midterm online test: Fundamental Computer Programming- C++ Lab(II), Rung-Bin Lin
April 16, 2022, International Bachelor Program in Informatics, Yuan Ze University
Input format:
The first line contains a number specifying the number of test cases. For each test case,
the first line gives the initial stack size and the second line gives the size for resizing.
It is then followed by the article input to each case. Terminate the input of each test
case by pressing control z. The inputs for the example below is given in a file called
PC.txt.
Output format:
The first line should be a message printed out by the constructor. The second line
printed by main() is a message about the times a stack being resized. The third line is
an empty line. The last line should be a message printed out by the destructor. In
between is the article whose content is printed in the reverse order. The output should
look exactly the same as that shown in the example.
Examples:
Input Output
Note there are some tap and space characters even at the end of an input line. These
space and tap characters should also appear in the output.