Skip to main content

Featured

C Pattern Programs: Square Number and Alphabet Patterns Explained

πŸ”· Square Star Pattern πŸ“‹ Copy Code #include <stdio.h> int main() { int num; printf("Enter the number:\n"); scanf("%d", &num); for(int i = 1; i <= num; i++) { for(int j = 1; j <= num; j++) { printf("* ");//keep"* " } printf("\n"); } return 0; } πŸ”· Reverse Square Alphabet Pattern (Column-wise) πŸ“‹ Copy Code #include <stdio.h> int main() { int num; printf("Enter the number:\n"); scanf("%d", &num); for(int i = num; i >= 1; i--) { for(int j = num; j >= 1; j--) { printf("%c ", j + 64);//%c for Character and 64 will be ASIIC VALUE } printf("\n"); } return 0; } πŸ”· Reverse Square Alphabet Pattern (Row-wise) πŸ“‹ Copy Code #include <stdio.h> int main() { int num; ...

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

Popular Posts

πŸŒ™