Question: / / Student ID: 2 0 5 3 7 0 1 6 / / TODO - Replace the number above with your actual student ID

// Student ID: 20537016
// TODO - Replace the number above with your actual student ID
//
#ifndef Stacks_h
#define Stacks_h
#include
#include
class Stack_Int {
private:
std::vector _data;
public:
// No explicit constructor or destructor
size_t size() const {
return _data.size ();
}
bool is_empty() const {
return (_data.size()==0);
}
void push(int val){
_data.push_back (val);
}
int top(bool& success) const {
if (is_empty()){
success = false;
return 0;
}
else {
success = true;
return _data.back();
}
}
bool pop(){
if (is_empty()) return false;
_data.pop_back();
return true;
}
bool pop(int& val){
if (is_empty()){
val =0;
return false;
}
val =_data.back();
_data.pop_back();
return true;
}
std::string to_string() const {
std::stringstream ss;
ss << "Stack ("<< size()<<" elements):"<< std::endl;
size_t count = std::min(size(), static_cast(10));
for (size_t i =0; i < count; ++i){
ss <<_data[size()-1- i]<< std::endl;
}
if (size()>10){
ss <<"..."<< std::endl;
}
ss << "Elements, if listed above, are in increasing order of age." << std::endl;
return ss.str();
}
// Don't remove the following line
friend class Tests;
};
class Stack_String {
private:
std::vector _data;
public:
// No explicit constructor or destructor
size_t size() const {
return _data.size ();
}
bool is_empty() const {
return (_data.size()==0);
}
void push(std::string val){
_data.push_back (val);
}
std::string top(bool& success) const {
if (is_empty()){
success = false;
return "";
}
else {
success = true;
return _data.back();
}
}
bool pop(){
if (is_empty()) return false;
_data.pop_back();
return true;
}
bool pop(std::string& val){
if (is_empty()){
val ="";
return false;
}
val =_data.back();
_data.pop_back();
return true;
}
std::string to_string() const {
std::stringstream ss;
ss << "Stack ("<< size()<<" elements):"<< std::endl;
size_t count = std::min(size(), static_cast(10));
for (size_t i =0; i < count; ++i){
ss <<_data[i]<< std::endl;
}
if (size()>10){
ss <<"..."<< std::endl;
}
ss << "Elements, if listed above, are in increasing order of age." << std::endl;
return ss.str();
}
// Don't remove the following line
friend class Tests;
};
#endif /* Stacks_h */ Checkpoint failed. Your to_string said:
Stack (1989 elements):
1289105539
2109407019
542309084
2126243185
112262320
1354330947
1538886138
2048598061
32488267
1816344617
...
Elements, if listed above, are in increasing order of age.
But mine said:
Stack (1989 elements):
1289105539
2109407019
542309084
2126243185
112262320
1354330947
1538886138
2048598061
32488267
1816344617
...
Elements, if listed above, are in increasing order of age.
Here is your stack:
Stack (1989 elements):
1289105539
2109407019
542309084
2126243185
112262320
1354330947
1538886138
2048598061
32488267
1816344617
932565085
2041732611
...
Elements, if listed above, are in increasing order of age.
And here is mine:
Stack (1989 elements):
1289105539
2109407019
542309084
2126243185
112262320
1354330947
1538886138
2048598061
32488267
1816344617
...
Elements, if listed above, are in increasing order of age.
You think that's it? in this i want 10 lines of code but i dont know why it is giving me 12 lines in output i need 10 please help me

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!