0% found this document useful (0 votes)
5 views3 pages

Prac 8

The document contains two C++ programs that define classes for handling personal and student information. The first program defines a 'person' class and a 'student' class, allowing input and display of name, age, ID, and course. The second program extends the functionality by adding a 'grad' class, which includes research and advisor details, demonstrating inheritance and encapsulation in object-oriented programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Prac 8

The document contains two C++ programs that define classes for handling personal and student information. The first program defines a 'person' class and a 'student' class, allowing input and display of name, age, ID, and course. The second program extends the functionality by adding a 'grad' class, which includes research and advisor details, demonstrating inheritance and encapsulation in object-oriented programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

1.

#include<iostream>
#include<string.h>
using namespace std;
class person{
protected:
char name[20];
int age;
public:
void set(){
cout<<"enter name=";
cin>>name;
cout<<"enter age=";
cin>>age;
}
void display(){
cout<<"name="<<name<<endl;
cout<<"age="<<age<<endl;
}
};
class student:public person{
public:
int id;
char course[30];
void input(){
cout<<"enter id=";
cin>>id;
cout<<"enter course=";
cin>>course;
}
void show(){
cout<<"id="<<id<<endl;
cout<<"course="<<course<<endl;
}
};
int main(){
student s;
s.set();
s.display();
s.input();
s.show();
}

OUTPUT
enter name=diksha
enter age=19
name=diksha
age=19
enter id=44
enter course=cpp
id=44
course=cpp

2.
#include<iostream>
#include<string.h>
using namespace std;
class person{
protected:
char name[20];
int age;
public:
void set(){
cout<<"enter name=";
cin>>name;
cout<<"enter age=";
cin>>age;
}
void display(){
cout<<"name="<<name<<endl;
cout<<"age="<<age<<endl;
}
};
class student:public person{
public:
int id;
char course[30];
void input(){
cout<<"enter id=";
cin>>id;
cout<<"enter course=";
cin>>course;
}
void show(){
cout<<"id="<<id<<endl;
cout<<"course="<<course<<endl;
}
};
class grad:public student{
public:
char research[100];
char advisor[100];
void set1(){
cout<<"enter research=";
cin>>research;
cout<<"advisor=";
cin>>advisor;
}
void display1(){
cout<<"research="<<research<<endl;
cout<<"advisor="<<advisor<<endl;
}
};
int main(){
grad g;
g.set();
g.display();
g.input();
g.show();
g.set1();
g.display1();
}

OUTPUT:
enter name=dikha
enter age=3044
name=diksha
age=3044
enter id=44
enter course=cse
id=46
course=cse
enter research=ambient
advisor=mgm
research=ambient
advisor=mgm

You might also like