×
Reviews 4.9/5 Order Now

Create a Program to Implement Story Game in C++ Assignment Solution

June 18, 2024
Dr. Stephanie Kim
Dr. Stephanie
🇬🇧 United Kingdom
C++
Dr. Stephanie Kim earned her Ph.D. in Computer Science from New York University and is a leading authority in C++ programming. With 8 years of experience, Dr. Kim has successfully completed over 800 C++ assignments, demonstrating her proficiency and dedication to delivering high-quality solutions.
Key Topics
  • Instructions
    • Objective
  • Requirements and Specifications
Tip of the day
Understand the problem first, then choose the most suitable data structure—whether it's arrays, linked lists, stacks, queues, or trees. Practice drawing diagrams to visualize how data flows and test edge cases thoroughly to ensure your implementation handles all scenarios efficiently.
News
In early 2025, Intel’s Cryptography Primitives Library 2025.1.0 launched with optimized AES, RSA, and post-quantum algorithms (XMSS/LMS), making it ideal for students tackling assignments on secure communications

Instructions

Objective

Write a C++ assignment program to implement story game.

Requirements and Specifications

program-to-implement-story-game-in-C
program-to-implement-story-game-in-C 1 (1)

Source Code

#ifndef wordstack_h #define wordstack_h #include #include using namespace std; // A stack that holds words class WordStack { private: // Node to be used to building a linked list of stack struct Node { string word; Node *next; // Create a new node that holds a word Node(const string &word) { this->word = word; next = NULL; } }; Node *top; int numWords; public: // Create a stack WordStack() { top = NULL; numWords = 0; } // Destructor to delete nodes if there are still left ~WordStack() { Node *current = top; while (current != NULL) { Node *next = current->next; delete current; current = next; } } // Add a new word to the stack void push(const string &word) { Node *node = new Node(word); node->next = top; top = node; numWords++; } // Remove the top element and return it string pop() { if (top == NULL) return ""; string word = top->word; top = top->next; numWords--; return word; } // Return the number of elements int size() { return numWords; } // Check if stack is empty bool isEmpty() { return numWords == 0; } // Print the stack to the output stream friend ostream& operator << (ostream &out, const WordStack &stack) { Node *current = stack.top; while (current != NULL) { out << current->word; current = current->next; if (current != NULL) out << ", "; } return out; } } #endif

Similar Samples

Discover our diverse range of programming homework samples at ProgrammingHomeworkHelp.com. From introductory exercises to advanced projects in languages like Java, Python, and more, our examples showcase our expertise and dedication to academic excellence. Explore how our solutions can help you understand and excel in programming concepts effectively.