C++ Program to print student details using single inheritance


In this program, You will learn how to print student details using single inheritance in C++.


class Student { }

class College : public Student { }


Example: How to print student details using single inheritance in C++

Run it Now
#include<iostream>
using namespace std;

class Student {
public:

   int roll;
   char sname[100];
   char cname[100];

   void input() {
       cout << "Enter Your Roll Number :";
       cin>>roll;
       cin.get();

       cout << "\nEnter Your Name :";
       cin.getline(sname, 100);

       cout << "\nEnter College Name :";
       cin.getline(cname, 100);
   }

};

class College : public Student {
public:

   void display() {
       cout << "\nYour Roll is :" << roll;
       cout << "\nYour Name is :" << sname;
       cout << "\nCollege Name is :" << cname;
   }
};

int main() {

   College obj;
   obj.input();
   obj.display();

   return 0;
}

Output:

Enter Your Roll Number :101
Enter Your Name :John
Enter College Name :Texas
Your Roll is :101
Your Name is :John
College Name is :Texas