Question: Main file: #include stack.h #include using namespace std; //Ignore this: it is for the tests to run inline void _test(const char* expression, const char* file,
Main file:
#include "stack.h" #include
//Ignore this: it is for the tests to run inline void _test(const char* expression, const char* file, int line, string msg) { cerr << "Error: " << msg << endl; cerr << "test(" << expression << ") failed in file " << file << ", line " << line << "." << endl; abort(); }
//Ignore this: it is for the tests to run #define test(EXPRESSION, msg) ((EXPRESSION) ? (void)0 : _test(#EXPRESSION, __FILE__, __LINE__, msg))
int main() { Stack s; test(s.size() == 0, "Should initially be empty");
s.push("Eric"); s.push("Mary"); s.push("Joseph"); test(s.size() == 3, "Should have 3 items");
s.pop();
test(s.size() == 2, "Should have 2 items");
s.push("Pimple");
test(s.size() == 3, "Should have 3 items");
test(s.top() == "Pimple", "Top should be Pimple"); s.pop();
test(s.top() == "Mary", "Pimple should have been popped. lol"); s.pop(); test(s.top() == "Eric", "Mary should have been popped.");
s.pop();
test(s.size() == 0, "Should have 0 items");
s.pop();
test(s.size() != -1, "Should have 0 items not -1 items!"); test(s.top() == "", "top() should return empty string when count < 0");
cout << "Assignment complete." << endl;
system("pause"); return 0; }
header file:
#include
class Stack { public:
Stack(); void push(string item); void pop(); string top(); int size();
private: string data[10000]; int count;
};
Implement the function definitions in a file called stack.cpp so that when the main program runs, there are no errors and the final result displays: "Assignment complete", meaning that it passed all the tests.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
