Answered step by step
Verified Expert Solution
Question
1 Approved Answer
/ / Student ID: 2 0 5 3 7 0 1 6 / / TODO - Replace the number above with your actual student ID
Student ID:
TODO Replace the number above with your actual student ID
#ifndef Stacksh
#define Stacksh
#include
#include
class StackInt
private:
std::vector data;
public:
No explicit constructor or destructor
sizet size const
return data.size ;
bool isempty const
return data.size;
void pushint val
data.pushback val;
int topbool& success const
if isempty
success false;
return ;
else
success true;
return data.back;
bool pop
if isempty return false;
data.popback;
return true;
bool popint& val
if isempty
val ;
return false;
val data.back;
data.popback;
return true;
std::string tostring const
std::stringstream ss;
ss "Stack size elements: std::endl;
sizet count std::minsize staticcast;
for sizet i ; i count; i
ss datasize i std::endl;
if size
ss std::endl;
else
ss "Elements, if listed above, are in increasing order of age." std::endl;
return ssstr;
Don't remove the following line
friend class Tests;
;
class StackString
private:
std::vector data;
public:
No explicit constructor or destructor
sizet size const
return data.size ;
bool isempty const
return data.size;
void pushstd::string val
data.pushback val;
std::string topbool& success const
if isempty
success false;
return ;
else
success true;
return data.back;
bool pop
if isempty return false;
data.popback;
return true;
bool popstd::string& val
if isempty
val ;
return false;
val data.back;
data.popback;
return true;
std::string tostring const
std::stringstream ss;
ss "Stack size elements: std::endl;
sizet count std::minsize staticcast;
for sizet i ; i count; i
ss datasize i std::endl;
if size
ss std::endl;
else
ss "Elements, if listed above, are in increasing order of age." std::endl;
return ssstr;
Don't remove the following line
friend class Tests;
;
#endif Stacksh i wrote this code but still get an error it produces lines of ouput i dont know why this is the error Checkpoint failed. Your tostring said:
Stack elements:
But mine said:
Stack elements:
Elements, if listed above, are in increasing order of age.
Here is your stack:
Stack elements:
Elements, if listed above, are in increasing order of age.
And here is mine:
Stack elements:
Elements, if listed above, are in increasing order of age.
You think that's it
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started