Answered step by step
Verified Expert Solution
Link Copied!

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: 20537016// TODO - Replace the number above with your actual student ID //
#ifndef Stacks_h
#define Stacks_h
#include
#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[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;
};
#endif /* Stacks_h */ i use this code but stiil i got the error please give me correct code Hooray! 2 Rogues from Rombarchia befriended (Basic Stack)
Hooray! 2 Light Emitting Weevils adopted (Push)
Hooray! 3 Qubits of Inner Space leased (Top)
Hooray! 2 Golden Rhinoceri won in a duel (Pop 1)
Hooray! 2 Sprinchots of Smoltassium insufflated... dangerous! (Pop 2)
Checkpoint failed. Your to_string said:
Stack (1723 elements):
2076646061
1630012730
1047190855
1858576442
304434849
889303625
1925144872
1642872926
1155427214
685444788
......
Elements, if listed above, are in increasing order of age.
But mine said:
Stack (1723 elements):
2076646061
1630012730
1047190855
1858576442
304434849
889303625
1925144872
1642872926
1155427214
685444788
...
Elements, if listed above, are in increasing order of age.
Here is your stack:
Stack (1723 elements):
2076646061
1630012730
1047190855
1858576442
304434849
889303625
1925144872
1642872926
1155427214
685444788
31579160
359501533
...
Elements, if listed above, are in increasing order of age.
And here is mine:
Stack (1723 elements):
2076646061
1630012730
1047190855
1858576442
304434849
889303625
1925144872
1642872926
1155427214
685444788
...
Elements, if listed above, are in increasing order of age.
You think that's it?
& this error is coming please give me correct code this is my 3rd time i am posting this question

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced Database Systems For Integration Of Media And User Environments 98

Authors: Yahiko Kambayashi, Akifumi Makinouchi, Shunsuke Uemura, Katsumi Tanaka, Yoshifumi Masunaga

1st Edition

9810234368, 978-9810234362

More Books

Students also viewed these Databases questions

Question

recognise typical interviewer errors and explain how to avoid them

Answered: 1 week ago

Question

identify and evaluate a range of recruitment and selection methods

Answered: 1 week ago

Question

understand the role of competencies and a competency framework

Answered: 1 week ago