Question

What are base and derived classes ? Create a base class called Stack and a derived class called Mystack. Write an interactive C++ program to show the operations of a stack.

31 Jul 2018
Answer :
Word Count : 747

In object-oriented programming, a base class is a class that serves as a foundation for one or more derived classes. A derived class, on the other hand, inherits properties and behaviors from its base class and can also have additional features or modifications. This concept facilitates code reuse and supports the creation of a hierarchy of related classes.

Let's create a base class called `Stack` and a derived class called `MyStack` in C++. The base class will contain the basic operations of a stack, such as push and pop, and the derived class will inherit these operations while providing additional functionality if needed.

```cpp
#include <iostream>
#include <vector>

class Stack {
protected:
    std::vector<int> stack; // Using a vector to store stack elements

public:
    void push(int value) {
        stack.push_back(value);
        std::cout << "Pushed: " << value << std::endl;
    }

    void pop() {
        if (!stack.empty()) {
            int poppedValue = stack.back();
     

______ ______ ____ _________ __________ ______ ________ _______ ________ _________ _____.
__________ ______ __________ _____ ________ _________ _______.
____ _________ ______ __________ ________ _________ _______.
_________ _____ __________ ____ _______ _____.
_______ __________ _____ _____ ____.
___ ___ ________ ______ __________.
_______ _______ ________ _____ ___ ________ _______ ________ _______ ________ ____.
________ ______ ____ __________ ___ __________ ____ __________.
_____ ______ ___ _________ ____ _________ _______ ______ _________ __________ ___.
__________ _________ __________ ____ __________ ________ _____ _______.
_____ ________ _________ _____ ____ ________ ___ _______.
____ __________ ____ _________ _______ ________ ______.
_________ _____ ____ _______ __________.
______ ____ _________ ____ ___ ______ ___ _________ ______ ______ _______.
_____ ___ _______ _________ _________ ______.
____ __________ ______ ___ _______ _____ ______ ______.
__________ _______ _______ ____ ________ ______ ___ _________ __________ ______.
_______ ___ ______ ___ _________ ______ ___ ________ _____ __________.
______ _______ _____ _________ ______.
_________ _____ ____ _____ ____.
______ _________ ________ ______ ________.
__________ _________ _______ ______ _______ __________ _______.
________ ___ _______ ______ ___ __________ _________ _____.
_____ _________ _____ ______ ___ __________ __________ __________ ___ _______ __________ _______.
_________ ________ _________ ________ ______ _____ _____ ______ _____ _____ ____.
_____ ___ ___ ________ ______ _______.
_____ ____ _____ ___ ____ __________ _____ _____.
_____ ___ _________ _______ ____ ____ ______ _____ ______ _________.
___ __________ ________ ___ ___.
___ _____ __________ ____ ___ _____ _____.
____ ________ _____ __________ ______ _________ ___.
______ ______ _________ _____ _____ ___ _____ ____.
_____ _________ ____ _____ _____ ___ _______ ____.
__________ ______ ______ ___ ________ _______ _______ _______.
_____ ________ __________ ________ ____ __________.
__________ ___ ___ __________ _____ ______ __________ _________ __________.
_____ ________ ____ ____ ___.
________ ________ _________ ________ ______ _____ ______.
________ ________ ______ _____ _______ __________ _________ ________.
______ _______ __________ ____ ____ ______ ________ ______ _______.
__________ ________ _____ ______ ___ __________.
______ ____ _________ ________ _______ _____.
__________ ____ ____ __________ ____ ________ _______ ____ __________ __________ _________ ___.
___ _____ ___ ________ _______ _________ __________ _____ ____ ________ _________ _________.
______ _________ _____ ____ __________ _____ ___ _____ __________ __________ ______.
_______ ____ ______ ____ ____ ______.
________ _________ _________ __________ _______ ______.
__________ _______ _________ ______ _______ ___ ___ ______ ________ _______.
___ ____ _________ ________ ________ _______.
__________ _____ ______ ________ _________ ______ ___ ______.
____ _________ ___ ____ ___ ___ _______ ________.
________ ______ ___ ________ _______ _____ _______ __________.
___ ____ ________ ______ ______ _________ ________ ________.
_________ ______ _________ ___ __________ _________ ___ ___ ___.
_____ _____ ___ _____ ___ ____ _____ ____ ____.
_______ _________ ______ __________ __________.
______ ___ _________ ______ ___ ____.
___ ________ __________ ___ _________.
_____ _______ ________ ________ ________.
__________ _____ ______ _____ ________ ___.
_____ ______ _____ ____ _____ ____ _____.
______ ___ ________ ____ ____ _______ _______ ___ ______ ___.
_________ _____ _______ ___ ______ _____ ______ ______ ________ ____ _____ _________.
___ _____ _______ ________ _________ __________ ______ ___.
_________ __________ ________ ________ _______ ____.
__________ ___ ______ ___ ________ ______ ___ ___ _____ ______ ________ ________.
_____ ___ __________ __________ ____ ____ ______ __________ __________.
_____ _______ _________ ____ _____ ____ _____.
______ ________ _____ _______ __________ _____ _______ _____ _______ ___ _______ __________.
________ ___ ___ _______ __________ _______ _____ ________ ________.
_________ _________ ___ ____ _________ _________ __________ __________.
IGNOU ACADEMY
Your IGNOU journey, made easier.
  • Solved Assignments
  • Study Notes
  • Guess Papers
  • Question Papers
Skip in 10
Top
📞
Call Support Instant phone assistance IGNOU BCS 31 2016 - What are base and derived classes ? Create a base class called Stack a | IGNOU Academy
→
🟢
WhatsApp Chat Fast live messaging
→
Email Us Business enquiries & support
→