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 Multi-Level Inheritance (Grandparent → Parent → Child)

C++ Program for Multi-Level Inheritance (Grandparent → Parent → Child)

✅ C++ Program to Demonstrate Multi-Level Inheritance

#include <iostream>
using namespace std;

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

class parent : public grandparent {
  public:
    void display2() {
        cout << "Hello I am parent:\n";
    }
};

class child : public parent {
  public:
    void display3() {
        cout << "Hello I am child:\n";
    }
};

int main() {
    child obj;
    obj.display1();
    obj.display2();
    obj.display3();
}
  

πŸ“˜ Explanation:

This program demonstrates the concept of multi-level inheritance in C++. - The grandparent class defines display1(). - The parent class inherits from grandparent and adds display2(). - The child class inherits from parent and adds display3(). - Thus, an object of the child class can access functions from all three classes.

🧾 Sample Output:

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

πŸ”‘ Keywords:

C++ multi-level inheritance example, grandparent parent child program, inheritance in C++, OOP in C++, C++ object oriented programming

πŸ“Œ Hashtags:

#CPlusPlus #Inheritance #MultiLevelInheritance #OOP #CppExamples #CodingForBeginners

πŸ” Search Description:

This C++ program demonstrates multi-level inheritance where a child class inherits from a parent, which in turn inherits from a grandparent class. Includes example code, explanation, and sample output.

Comments

Popular Posts

πŸŒ™