211. Write a program to demonstrate object slicing?

#include<iostream.h> #include<conio.h> class base { public:                 int x;                 base()                 {                                 x=10;                 } }; class derived:public base { public:                 int y;                 derived()                 {                                 x=30;                                 y=50;                 } }; void main() {                 clrscr();                 base b;                 derived d;                 cout<<"In Base Class X ="<<b.x<<endl;                ... Continue Reading →

Advertisements

210. Write a program to demonstrate external storage class?

TEST.H int i=9;  //Global Variable DEMO.CPP #include<iostream.h> #include<conio.h> #include"TEST.H" extern int i;         //External Variable void main() {                 clrscr();                 cout<<"External Variable : "<<i<<endl;                 getch(); }

209. Write a program to demonstrate overloading template function?

#include<iostream.h> #include<conio.h> template <class T> void display(T t) {                 cout<<"Inside Template Function = "<<t<<endl; } void display(int i) {                 cout<<"Inside Specific Function = "<<i<<endl; } void main() {                 clrscr();                 display('X');                 display(10);                 display('Z');                 display(10.5);                 getch(); }

208. Write a program to perform the operation using function template?

#include<iostream.h> #include<conio.h> template <class T> void display(T v) {                 cout<<"V = "<<v<<endl; } void main() {                 clrscr();                 int i=50;                 char c='Z';                 double d=3.71;                 display(i);                 display(c);                 display(d);                 getch(); }

207. Write a program to create two argument of template type inside template function?

#include<iostream.h> #include<conio.h> template <class T,class X> class demo {                 T a;                 X b; public:                 demo(T p,X q)                                 {                                 a=p;                                 b=q;                                 }                 void display()                                 {                                 cout<<"A = "<<a<<"\tB = "<<b<<endl;                                 } }; void main() {                 clrscr();                 demo <char,int> d1('Y',10);                 demo <int,char> d2(20,'Z');... Continue Reading →

206. Write a program to read different values from constructor and display through member function?

#include<iostream.h> #include<conio.h> template <class T> class demo {                 T a; public:                 demo(T ch)                                 {                                 a=ch;                                 }                 void display(T b)                                 {                                 cout<<"A = "<<a<<"\tB = "<<b<<endl;                                 } }; void main() {                 clrscr();                 demo <char> x('V');                 demo <int> y(10);                 demo <double> z(15.13);                 x.display('K');... Continue Reading →

205. Write a program to perform above operation by using template data type?

#include<iostream.h> #include<conio.h> template <class T> class demo { public:                 demo(T ch)                                 {                                 cout<<"Value = "<<ch<<endl;                                 } }; void main() {                 clrscr();                 demo <char> x('A');                 demo <int> y(10);                 demo <double> z(15.13);                 getch(); }

204. Write a program to work with different data type by without using template keyword?

#include<iostream.h> #include<conio.h> class demo { public:                 demo(char ch)                                 {                                 cout<<"Character = "<<ch<<endl;                                }                 demo(int i)                                 {                                 cout<<"Integer = "<<i<<endl;                                 }                 demo(double d)                                 {                                 cout<<"Double = "<<d<<endl;                                 } }; void main() {                 clrscr();                 demo x('A');                 demo y(10);                 demo z(15.13);                ... Continue Reading →

203. Write a program to create an object outside the function?

#include<iostream.h> #include<conio.h> class number {                 int a; public:                 void get()                                 {                                 cout<<"Enter A Number : ";                                 cin>>a;                                 }                 void display()                                 {                                 cout<<"The Number Is : "<<a<<endl;                                 } }; number m,n; void main() {                 clrscr();                 number n;                 n.get(); //Local Object                 m.get();                ... Continue Reading →

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: