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(); }

Advertisements

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 →

202. Write a program to show the use of this pointer?

#include<iostream.h> #include<conio.h> class number {                 int a; public:                 void get()                                 {                                 cout<<"Enter A Number : ";                                 cin>>a;                                 }                 number check(number num)                                 {                                 if(num.a>a)                                                 {                                                 return num;                                                 }                                 else                                                 {                                                 return *this;                                                 }                                 }                 void display()                                 {... Continue Reading →

201. Write a program to access the private data of parent class by its child class?

#include<iostream.h> #include<conio.h> class parent {                 int a,b; public:                 parent()                                 {                                 a=10;                                 b=20;                                 } }; class child:public parent { public:                 int c;                 child()                                 {                                 c=30;                                 } }; void main() {                 clrscr();                 int *ptr;                 child obj;                 ptr=&obj.c;                 cout<<"The Address of C... Continue Reading →

200. Write a program to demonstrate abstract class?

#include<iostream.h> #include<conio.h> int p=1000,t=1; class bank { public:                 virtual void interest()=0;               //Pure Virtual Function }; void bank::interest() {                 cout<<"The Home Loan : "; } class sbi:public bank {                 int i; public:                 void interest()                                 {                                 i=(p*5*t)/100;                                 cout<<"SBI Interest Is : "<<i<<endl;                                 } }; class pnb:public bank {                ... Continue Reading →

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: