0% found this document useful (0 votes)
27 views7 pages

Bhavesh

The document discusses function overriding and member functions in C++. It provides code examples for function overriding using classes Base and Derived. It also provides examples of a member function and a static member function in a BSc_Cs class and note class respectively.

Uploaded by

dedali8086
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)
27 views7 pages

Bhavesh

The document discusses function overriding and member functions in C++. It provides code examples for function overriding using classes Base and Derived. It also provides examples of a member function and a static member function in a BSc_Cs class and note class respectively.

Uploaded by

dedali8086
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/ 7

Page |

Q. 14 Write a program for Function overriding in C++.


Source Code:
/*Name of programmer : Bhavesh Dewangan
Path of program : turbo c++ */

#include<iostream.h>
#include<conio.h>
class Base
{
public:
void input()
{
cout<<endl<<"Honesty is the best policy.";
}
};
class Derived: public Base
{
public:
void input()
{
cout<<endl<<"People must choose their words wisely.";
}
};
void main()
{
Derived d;

BSc Cs II 2023-24 Programming in C++ GUIDED BY: Mrs. Jaspreet Kaur


GDRCST
Page |

clrscr();
d.input();
getch();
}

Output:

BSc Cs II 2023-24 Programming in C++ GUIDED BY: Mrs. Jaspreet Kaur


GDRCST
Page |

Q 15. Write a program for the following


(a)Member function in C++

Source Code :
/* Name of programmer : Bhavesh Dewangan
Path of program : Turbo C++ */

//A simple program of member function


#include<iostream.h>
#include<conio.h>
class BSc_Cs
{
public:
int students;
void printData();
};
void BSc_Cs :: printData()
{
cout<<endl<<"Enter data: ";
cin>>students;
cout<<"Total number of students in Bsc Computer science is
"<<students;
}
void main()
{
BSc_Cs total:

BSc Cs II 2023-24 Programming in C++ GUIDED BY: Mrs. Jaspreet Kaur


GDRCST
Page |

clrscr();

total.printData();
getch();
}

Output:

(b) Static member function

Source Code :
/* Name of programmer : Bhavesh Dewangan
Path of program : Turbo C++*/

//static member function in C++


#include<iostream.h>
#include<conio.h>
class note
{
static int num;
public:

BSc Cs II 2023-24 Programming in C++ GUIDED BY: Mrs. Jaspreet Kaur


GDRCST
Page |

static int func()


{
return num;
}
};
int note::num = 220;
void main()
{
clrscr();
cout<<endl<<"The given value is "<<note: :func();
getch();
}

Output :

BSc Cs II 2023-24 Programming in C++ GUIDED BY: Mrs. Jaspreet Kaur


GDRCST
Page |

Q 16. Write a program for pointer to pointer.

Source Code:
/* Name of programmer : Bhavesh Dewangan
Path of program : Turbo C++ */

//pointer to pointer
#include<iostream.h>
#include<conio.h>
void main()
{
int year;
clrscr();
int *yr= &year;
int **yrs = &yr;
cout<<endl<<"Enter current year: ";
cin>>year;
cout<<"Value stored in first pointer: "<<*yr;
cout<<endl<<"Value stored in second pointer: "<<**yrs;
getch();
}

BSc Cs II 2023-24 Programming in C++ GUIDED BY: Mrs. Jaspreet Kaur


GDRCST
Page |

Output :

BSc Cs II 2023-24 Programming in C++ GUIDED BY: Mrs. Jaspreet Kaur


GDRCST

You might also like