0% found this document useful (0 votes)
11 views

PC-Stack Class

This document describes a midterm online test problem that involves creating a Stack class with various member functions like push(), pop(), isEmpty(), etc. and using it to reverse an article. Students are asked to implement the Stack class, write a program that uses it to reverse the input article, and output the reversed article along with constructor/destructor messages. The input format specifies the initial stack size and resize size on the first two lines, followed by the article. The output format prints constructor/destructor messages along with the reversed article and any space/tab characters. An example input/output is provided.

Uploaded by

sheng.c.tan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

PC-Stack Class

This document describes a midterm online test problem that involves creating a Stack class with various member functions like push(), pop(), isEmpty(), etc. and using it to reverse an article. Students are asked to implement the Stack class, write a program that uses it to reverse the input article, and output the reversed article along with constructor/destructor messages. The input format specifies the initial stack size and resize size on the first two lines, followed by the article. The output format prints constructor/destructor messages along with the reversed article and any space/tab characters. An example input/output is provided.

Uploaded by

sheng.c.tan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Midterm online test: Fundamental Computer Programming- C++ Lab(II), Rung-Bin Lin

April 16, 2022, International Bachelor Program in Informatics, Yuan Ze University

Problem C: Stack Class

(25%, related to Lab 3)

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.

You might also like