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 {
//statement
}
class College : public Student {
//statement
}
Example: How to print student details using single inheritance in C++.
#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 << "Enter Your Name:";
cin.getline(sname, 100);
cout << "Enter College Name:";
cin.getline(cname, 100);
}
};
class College : public Student {
public:
void display() {
cout << "Your 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:Xiith
Enter College Name:Xiith345
Your Roll is :101
Your Name is :Xiith
College Name is :Xiith345