Write a program to illustrate the concept of overriding member function


 

/* Write a program to illustrate the concept of overriding member function*/

#include<iostream.h>

#include<conio.h>

class per

{

private:

char name[20];

long int phno;

public:

void read()

{

cout<<“enter name and phno=”;

cin>>name>>phno;

}

void show()

{

cout<<“\n name=”<<name;

cout<<“\n phno=”<<phno;

}};

class stu:public per

{

private:

int rollno;

char course[20];

public:

void read()

{

per::read();

cout<<“enter rollno and course=”;

cin>>rollno>>course;

}

void show()

{

per::show();

cout<<“\n rollno=”<<rollno;

cout<<“\n course=”<<course;

}};

void main()

{

clrscr();

stu s1;

s1.read();

cout<<“displaying student information=”;

s1.show();

getch();

}

/* output:

enter name andphno=harjeet 2345678

enter rollno and course=2 mca

displaying student information=

name=harjeet

phno=2345678

rollno=2

course=mca*/

Related Posts

Comments are closed.