Skip to main content

Featured

Mastering Hollow Square Patterns in C: Stars, Numbers, Alphabets & Binary

πŸ”’ C Program to Print Hollow Continuous Number Square πŸ“„ Source Code: #include <stdio.h> int main() { int num, k = 0; printf("Enter the number:\n"); scanf("%d", &num); for(int i = 1; i <= num; i++) { for(int j = 1; j <= num; j++) { if(i == 1 || i == num || j == 1 || j == num) { // k increments sequentially only along the borders printf("%d ", k++); } else { printf(" "); } } printf("\n"); } return 0; } πŸ“‹ Copy Code πŸ’» Expected Output (Input: 5): Enter the number: 5 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 πŸ”’ C Program to Print Standard Hollow Binary Row Square πŸ“„ Source Code (Fixed Specifier): #include <stdio.h> int main() { ...

C++ Program for Multiple Inheritance (Grandparent, Parent, Child)

C++ Program for Multiple Inheritance (Grandparent, Parent, Child)

✅ C++ Program to Demonstrate Multiple Inheritance

#include <iostream>
using namespace std;

class grandparent {
  public:
    void gp() {
        cout << "Hi I am your grandparent:\n";
    }
};

class parent {
  public:
    void p() {
        cout << "Hi I am your parent:\n";
    }
};

class child : public grandparent, public parent {
  public:
    void c() {
        cout << "Hello I am your child:\n";
    }
};

int main() {
    child obj;
    obj.gp();
    obj.p();
    obj.c();
}
  

πŸ“˜ Explanation:

This program demonstrates the concept of multiple inheritance in C++. - The grandparent class has a function gp(). - The parent class has a function p(). - The child class inherits from both grandparent and parent. - The child object can call functions from both its parent and grandparent, along with its own function.

🧾 Sample Output:

Hi I am your grandparent:
Hi I am your parent:
Hello I am your child:
  

πŸ”‘ Keywords:

C++ multiple inheritance example, grandparent parent child program, inheritance in C++, OOP in C++, C++ object oriented programming

πŸ“Œ Hashtags:

#CPlusPlus #Inheritance #MultipleInheritance #OOP #CppExamples #CodingForBeginners

πŸ” Search Description:

This C++ program demonstrates multiple inheritance where a child class inherits from both a grandparent and a parent class. Includes example code, explanation, and sample output.

Comments

πŸŒ™