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 to Demonstrate Single Inheritance

C++ Program for Single Inheritance (Parent and Child Class)

✅ C++ Program to Demonstrate Single Inheritance

#include <iostream>
using namespace std;

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

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

int main() {
    child c;
    c.parent1();
    c.child1();
}
  

πŸ“˜ Explanation:

This program demonstrates the concept of single inheritance in C++. - The parent class defines a function parent1(). - The child class inherits from the parent class using : public parent. - The child object can access both its own function (child1()) and the parent's function (parent1()).

🧾 Sample Output:

Hi I am parent class:
Hi I am child class:
  

πŸ”‘ Keywords:

C++ inheritance example, single inheritance in C++, parent and child class, OOP in C++, C++ object oriented programming

πŸ“Œ Hashtags:

#CPlusPlus #Inheritance #OOP #Programming #CppExamples #CodingForBeginners

πŸ” Search Description:

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

Comments

Popular Posts

πŸŒ™