Archives for 

programming in c++

Write a program to string lowercase( ) function

 /* Write a program to string lowercase( ) function. */ #include<iostream.h> #include<conio.h> #include<string.h> void main() { char a[10]; clrscr(); cout<<“enter name=”; cin.get(a,10); int length=strlen(a); cout<<“length of string=”<<length; cout<<endl<<“lowercase=”<<strlwr(a); cout<<endl<<“uppercase=”<<strupr(a); getch();} /* output: enter name=VeneetA length of string=7 lowercase=veneeta uppercase=VENEETA*/ Continue reading →

Write a program to string palindrome( ) function

  /* Write a program to string palindrome( ) function*/ #include<iostream.h> #include<conio.h> #include<string.h> void main() { char a[10],b[10]; clrscr(); cout<<“enter one string=”; cin.get(a,10); strcpy(b,a); strrev(b); if(strcmp(a,b)= =0) cout<<“palindrom”; else cout<<“not palindrom”; getch();} /* output: enter one string=madam palindrome enter one string=harjeet not palindrome*/ Continue reading →

Write a program to string concat( ) function

  /* Write a program to string concat( )  function*/ #include<iostream.h> #include<conio.h> #include<string.h> void main() { char a[10],b[]=”city”; clrscr(); cout<<“enter name=”; cin.get(a,10); int length=strlen(a); cout<<“length of string=”<<length; cout<<endl<<“uppercase=”<<strupr(a); cout<<endl<<“lowercase=”<<strlwr(a); cout<<endl<<“strcat=”<<strcat(a,b); getch(); } /* output: enter name=ajay length og string=4 uppercase=AJAY lowercase=ajay strcat=ajaycity*/ Continue reading →

Write a program to string uppercase( ) function

  /* Write a program to string uppercase( ) function*/ #include<iostream.h> #include<conio.h> #include<string.h> void main() { char a[10]; clrscr(); cout<<“enter name=”; cin.get(a,10); int length=strlen(a); cout<<“length of string=”<<length; cout<<endl<<“uppercase=”<<strupr(a); cout<<endl<<“lowercase=”<<strlwr(a); getch();} /* output: enter name=raman length of string=5 uppercase=RAMAN lowercase=raman*/ Continue reading →

Write a program to showing use of non-type parameter in function template

  /* Write a program to showing use of non-type parameter in function template*/ #include<iostream.h> #include<conio.h> template<class t> void display(t a,t b,char operation) { switch(operation) { case ‘+’: cout<<a<<operation<<b<<‘='<<a+b<<endl; break; case ‘-‘: cout<<a<<operation<<b<<‘='<<a-b<<endl; break; case ‘*’: cout<<a<<operation<<b<<‘='<<a*b<<endl; break; case ‘/’: cout<<a<<operation<<b<<‘='<<a/b<<endl; break; default: cout<<“define operation”; }} void main() { clrscr(); display(20,40,’+’); display(3.5,1.5,’-‘); display(‘c’,’d’,’+’); getch(); } […] Continue reading →

Write a program to overload function template with non-function template

  /* Write a program to overload function template with non-function template*/ #include<iostream.h> #include<conio.h> #include<string.h> template<class t> t min(t a,t b) { return(a<b)?a:b; } char *min(char *p,char *q) { int k=strcmp(p,q); return(k<0)?p:q; } void main() { clrscr(); cout<<“\n min of 2integer number=”<<min(7,15); cout<<“\n min of 2float number=”<<min(3.5,2.75); cout<<“\n min of 2string=”<<min(“xyz”,”abc”); getch(); } /* output: […] Continue reading →

Write a program to calculate the minimum of two and three numbers of any data type

  /* Write a program to calculate the minimum of two and three numbers of any data type*/ #include<iostream.h> #include<conio.h> template<class t> t min(t a,t b) { return(a>b?a:b); } template<class t> t min(t a,t b,t c) { return(a<b?(a<c?a:c):(b<c?b:c)); } void main() { clrscr(); cout<<“\n min of 2int values=”<<min(10,20); cout<<“\n min of 2float values=”<<min(2.75,2.5); cout<<“\n min […] Continue reading →