In the lecture we studied IntStack, a class that implements a static stack of integers. Write a template that will create a static stack of any data type. Demonstrate the class with a driver program. #pragma once
In the lecture we studied IntStack, a class that implements a static stack of integers. Write a template that will create a static stack of any data type. Demonstrate the class with a driver program. #pragma once
In the lecture we studied IntStack, a class that implements a static stack of integers. Write a template that will create a static stack of any data type. Demonstrate the class with a driver program. #pragma once
In the lecture we studied IntStack, a class that implements a static stack of integers. Write a template that will create a static stack of any data type. Demonstrate the class with a driver program.
#pragma once
class IntStack { private: int *stackArray; int stackSize; int top;
Queue Exceptions: Modify the static queue class provided in our lecture as follows.
Make the isFull and isEmpty member functions private.
Define a queue overflow exception and modify enqueue so that it throws this exception when the queue runs out of space.
Define a queue underflow exception and modify dequeue so that it throws this exception when the queue is empty.
Rewrite the main program so that it catches overflow exceptions when they occur. The exception handler for queue overflow should print an appropriate error message and then terminate the program.
#include <iostream> #include "Data.h" using namespace std;
//******************************************** // Function enqueue inserts the value in num * // at the rear of the queue. * //********************************************
void IntQueue::enqueue(int num) { if (isFull()) cout << "The queue is full.\n"; else { // Calculate the new rear position rear = (rear + 1) % queueSize; // Insert new item queueArray[rear] = num; // Update item count numItems++; } }
//********************************************* // Function dequeue removes the value at the * // front of the queue, and copies t into num. * //*********************************************
void IntQueue::dequeue(int &num) { if (isEmpty()) cout << "The queue is empty.\n"; else { // Move front front = (front + 1) % queueSize; // Retrieve the front item num = queueArray[front]; // Update item count numItems--; } } //********************************************* // Function isEmpty returns true if the queue * // is empty, and false otherwise. * //*********************************************
bool IntQueue::isEmpty() { bool status;
if (numItems) status = false; else status = true;
return status; }
//******************************************** // Function isFull returns true if the queue * // is full, and false otherwise. * //********************************************
bool IntQueue::isFull() { bool status;
if (numItems < queueSize) status = false; else status = true;
return status; } //******************************************* // Function clear resets the front and rear * // indices, and sets numItems to 0. * //*******************************************
Recursive Member Test: Write a recursive boolean function named isMember. The function should accept three parameters: an array of integers, an integer indicating the number of elements in the array, and an integer value to be searched for. The function should return true if the value is found in the array, or false if the value is not found. Demonstrate the use of the function in a program that asks the user to enter an array of numbers and a value to be searched for.
#include <iostream> using namespace std;
int main() {
}
Transcribed Image Text:File
Edit
Find
View
Tools
Education
Help
* Compile & Run
O Debug Current File
MCABIGON
Project
File
Edit
Find
View
Tools
Education
Help
I Compile & Run
> Project Index (static)
O Debug Current File
Project Index (static)
MCAE
Main.cpp
Data.h
Implementat.
Problem 1 (S.
Main.cpp
Data.h
Implementat.
Problem 1 (S. x
#include <iostream>
36
#include "Data.h"
Collapse
2 (Mo...
37
Collapse
using namespace std;
38
void IntStack::pop (int &num)
{
if (isEmpty())
39 .
//****
// Constructor
Problem 1 (Stacks)
Problem 1 (Stacks)
40
{
cout << "The stack is empty.\n";
}
else
41-
Modules 4, 5, 6) (
1/***
42
In the lecture we studied IntStack, a
ect
43
In the lecture we studied IntStack, a
IntStack::IntStack(int size)
{
stackArray = new int[size];
stackSize = size;
top = -1;
}
9.
class that implements a static stack
Project
44
class that implements a static stack
10
of integers. Write a template that will
{
num = stackArray[top];
45 ,
11
of integers. Write a template that will
46
create a static stack of any data type.
12
47
top--;
create a static stack of any data type.
13
Demonstrate the class with a driver
48
Demonstrate the class with a driver
14
program.
}
//
// Member function isFull returns true if the stack
// is full, or false otherwise.
//****
49
15
program.
50
// Member function push pushes the argument onto
// the stack.
//**
16
51
52
53
To run / execute your program, click the button
54
void IntStack::push(int num)
{
if (isFull())
{
cout <« "The stack is full.\n";
}
else
20
To run / execute your program, click the button
below...
bool IntStack::isFull()
{
bool status;
21.
55
below...
22
56 •
23
TEST IT!
57
58
TEST IT
59
if (top == stackSize - 1)
26
Note: test.h contains the series of
60
status = true;
else
status = false;
27.
{
61
commands neccesasry to compile
Note: test.h contains the series of
28
62
top++;
stackArray[top] = num;
}
and run your program in a linux
terminal. Should you make changes
29
63
return status;
commands neccesasry to compile
30
64
and run your program in a linux
31
}
//*
// Member function isEmpty returns true if the stack *
// is empty, or false otherwise.
//***********
to your C++ files, you must also
65
terminal. Should you make changes
32
66
update test.sh.
// Member function pop pops the value at the top
// of the stack off, and copies it into the variable
// passed as an argument.
33
to your C++ files, you must also
67
34
68
update test.sh.
35
69
bool IntStack::isEmpty ()
70, {
0% (1:0)
C++
Edit
Find
View
Tools
Education
Help
Compile & Run
> Project Index (static)
O Debug Current File
MCABIGON
0% (1:0)
Main.cpp
Data.h
Implementat.
Problem 1 (S.
Education
O Debug Current File
MCABIGON
Edit
Find
View
Tools
Help
A Compile & Run
> Project Index (static)
// Member function isFull returns true if the stack
// is full, or false otherwise.
//****
51
in.cpp
Data.h
Implementat. x
Problem 2 (Q. x
Collapse
52
53
#include <iostream>
Problem 1 (Stacks)
Collapse
54
#include "Data.h"
3
using namespace std;
bool IntStack::isFull()
{
bool status;
55
56 .
4
Problem 2 (Queues)
57
//********
// Constructor
In the lecture we studied IntStack, a
58
6
59
if (top == stackSize - 1)
class that implements a static stack
//*
IntQueue::IntQueue (int s)
{
7
60
status = true;
of integers. Write a template that will
8
61
else
Queue Exceptions: Modify the static
create a static stack of any data type.
62
status = false;
return status;
Demonstrate the class with a driver
queue class provided in our lecture
queueArray = new int[s];
queueSize = s;
front = -1;
10
63
11
as follows.
64
program.
65
12
// Member function isEmpty returns true if the stack
// is empty, or false otherwise.
//***
bool IntStack::isEmpty ()
{
bool status;
13
rear = -1;
numItems = 0;
66
1. Make the isFull and isEmpty
67
14
member functions private.
68
15
}
69
To run / execute your program, click the button
16
2. Define a queue overflow
70 .
below.
17
71
exception and modify enqueue
// Destructor
//*
18
72
19
so that it throws this exception
73
if (top == -1)
TEST IT!
20
when the queue runs out of
74
status = true;
IntQueue::-IntQueue ()
{
delete [] queueArray;
}
75
else
21
space.
76
status = false;
Note: test.h contains the series of
22
77
commands neccesasry to compile
23
3. Define a queue underflow
78
return status;
24
exception and modify dequeue
and run your program in a linux
terminal. Should you make changes
79
}
25
so that it throws this exception
80
//*
// Function enqueue inserts the value in num *
// at the rear of the queue.
1/******
26
81
to your C++ files, you must also
27
when the queue is empty.
82
update test.sh.
28
4. Rewrite the main program so
29
that it catches overflow
30
31
void IntQueue::enqueue (int num)
exceptions when they occur.
0% (1:0)
32. {
C++
The excention handler for
Transcribed Image Text:Education
Compile & Run
Project Index (static)
O Debug Current File
Main.cpp
Implementat. x
Problem 2 (Q.
Data.h
Main.cpp
Data.h
Implementat.
Problem 2 (Q. X
36 .
70
71.
bool IntQueue::isEmpty )
{
bool status;
37
// Calculate the new rear position
Collapse
38
Collapse
rear = (rear + 1) % queueSize;
// Insert new item
queueArray[rear] = num;
// Update item count
numItems++;
72
39
73
40
Problem 2 (Queues)
if (numItems)
status = false:
else
Problem 2 (Queues)
74
41
75
42
5, 6)(
76
}
}
43
Queue Exceptions: Modify the static
77
status = true;
44
Queue Exceptions: Modify the static
45
queue class provided in our lecture
queue class provided in our lecture
79
return status;
46
as follows.
as follows.
// Function dequeue removes the value at the *
// front of the queue, and copies t into num. *
//***
47
81
48
82
1. Make the isFull and isEmpty
// Function isFull returns true if the queue *
// is full, and false otherwise.
//****
49
83
1. Make the isFull and isEmpty
50
member functions private.
84
member functions private.
void IntQueue::dequeue (int &num)
52 .
51
85
2. Define a queue overflow
2. Define a queue overflow
86
if (isEmpty ())
cout <« "The queue is empty. \n";
bool IntQueue::isFull ()
exception and modify enqueue
so that it throws this exception
53
exception and modify enqueue
87
54
so that it throws this exception
88 .
55
else
89
bool status;
when the queue runs out of
when the queue runs out of
56
90
{
// Move front
front = (front + 1) % queueSize;
// Retrieve the front item
num = queueArray[front];
// Update item count
if (numItems < queueSize)
status = false;
else
space.
91
space.
57
92
58
3. Define a queue underflow
3. Define a queue underflow
93
59
exception and modify dequeue
94
status = true;
exception and modify dequeue
60
so that it throws this exception
95
so that it throws this exception
61
96
return status;
}
//****
// Function clear resets the front and rear *
// indices, and sets numItems to 0.
62
numItems--;
when the queue is empty.
when the queue is empty.
97
63
4. Rewrite the main program so
98
4. Rewrite the main program so
64
99
that it catches overflow
65
that it catches overflow
100
exceptions when they occur.
// Function isEmpty returns true if the queue *
// is empty, and false otherwise.
//****
66
exceptions when they occur.
101
//*****
67
The exception handler for
102
The exception handler for
68
void IntQueue::clear ()
queue overflow should print an
103
69
queue overflow should print an
104 , {
appropriate error message and
70
bool IntQueue::isEmpty()
appropriate error message and
- uunsi
then terminate the program.
then terminate the proaram
odio- roect
EUUcaDon
tompile & Run
Project Index (static)
O DEbug Curren FIe
TIng
VIew
TOOS
Heip
81
Filetree
Main.cpp
Problem 3 (R. x
//**
// Function isFull returns true if the queue *
// is full, and false otherwise.
82
Problem 2 (Queues)
83
MCABIGON
1.
#include <iostream>
4,5, 6)(
84
Summative 2 (Mo...
2
using namespace std;
Collapse
85
//*****
3
Problem 3 (Recursion)
4
Queue Exceptions: Modify the static
int main()
bool IntQueue::isFull()
{
bool status;
87
queue class provided in our lecture
6-
A Summative 2 (Modules 4, 5, 6)(
Queue Project
RecursionProject
Stack Project
O settings
D README.md
88 .
7
as follows.
8
Recursive Member Test: Write a
recursive boolean function named
if (numItems < queuesize)
status = false;
else
91
1. Make the isFull and isEmpty
isMember. The function should accept
member functions private.
three parameters: an array of
integers, an integer indicating the
status = true;
2. Define a queue overflow
number of elements in the array, and
95
exception and modify enqueue
so that it throws this exception
an integer value to be searched for.
96
return status:
The function should return true if the
97
when the queue runs out of
value is found in the array, or false if
//***
// Function clear resets the front and rear
// indices, and sets numItems to 0.
98
the value is not found. Demonstrate
99
space.
100
the use of the function in a program
101
3. Define a queue underflow
that asks the user to enter an array of
102
exception and modify dequeue
numbers and a value to be searched
void IntQueue::clear ()
103
for.
so that it throws this exception
104
when the queue is empty.
front = queueSize - 1;
rear = queueSize - 1;
numItems = 0;
105
106
4. Rewrite the main program so
107
that it catches overflow
To run / execute your program, click the button
108
}
below..
109
exceptions when they occur.
110
The exception handler for
111
TEST M
queue overflow should print an
appropriate error message and
Note: test.h contains the series of
then terminate the program
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.