Q1.

WAP TO PERFORM FOLLOWING OPERATIONS ON INTEGERS AS COMMAND LINE ARGUMENT: * TO CHECK IF A NUMBER IS PRIME OR NOT * TO PRINT THE SUM AND PRODUCT OF THE NUMBER’S DIGITS * TO REVERSE THE NUMBER #include<iostream.h> #include<conio.h> #include<stdlib.h> class integer { int *arr,L; public: integer(int x,int *n) { L=x; arr=n; } void pri() { int flag=0; for(int i=0;i<L;i++) { flag=0; for(int j=2;j<=((arr[i])/2);j++) { if(arr[i]%j==0) { flag=1; break; } } if(flag==1) { cout<<endl<<arr[i]<<" is Not Prime..."; } else { cout<<endl<<arr[i]<<" is Prime..."; } } cout<<"\n\n\nPress any key to continue... "; getch(); } void sp() { int sum=0; long int pro=1; for(int i=0;i<L;i++) { sum+=arr[i]; pro*=arr[i]; cout<<endl<<arr[i]; } cout<<"\nThe sum is = "<<sum<<"\nProduct is... = "<<pro<<"\n\nPress any key to continue... "; getch(); } void rev()

{ int temp=0,rev=0; for(int i=0;i<L;i++) { temp=arr[i]; rev=0; while(temp!=0) { rev+=temp%10; rev*=10; temp/=10; } rev/=10; cout<<"\nReverse of "<<arr[i]<<" is "<<rev; } cout<<"\n\n\nPress any key to continue... "; getch(); } }*A; void menu(); void main(int argv,char *argc[]) { clrscr(); if(argv==1) { cout<<"No integer entered... Press any key to exit... "; getch(); exit(0) } int *N; N=(int*)malloc((sizeof(int))*(argv-1)); for(int i=1;i<argv;i++) { *(N+i-1)=atoi(argc[i]); //cout<<endl<<*(N+i-1); } A=new integer((argv-1),N); menu(); } void menu() { clrscr(); cout<<"\n\n1)Find if integer is prime or not...\n\n2)Display Sum and Products...\n\n3)Reverse the entered integer...\n\nPress any other key to exit...\n\n"; char ch; ch=getch(); clrscr(); switch(ch) { case '1': { A->pri(); break; } case '2': { A->sp(); break; } case '3': { A->rev(); Break : } default: { exit(0); } } menu(); }

Q2. WAP TO CHECK IF A STRING IS PALINDROME OR NOT.USE THIS FUNCTION TO CHECK USER ENTERED STRING #include<iostream.h> #include<stdio.h> #include<conio.h> #include<stdlib.h> void palindrome(int,char*); void main() { cout<<"Prog to check if a String is palindrome or not... \n\n"; char *s; int x=0; cout<<"Enter the String... "; gets(s); for(x=0;s[x]!='\0';x++); palindrome(x,s); getch(); exit(0); } void palindrome(int len,char *str) { int flag=0; for(int i=0;i<(len/2);i++) { if((str[i])!=(str[len-i-1])) { flag=1; break; } } if(flag) { cout<<endl<<"The Entered STRING ( "<<str<<" ) is NOT PALINDROME."; } else { cout<<endl<<"The Entered STRING ( "<<str<<" ) is PALINDROME."; } }

Q3. WAP TO PERFORM FOLLOWING ON USER ENTERED ARRAY * PRINT THE ODD VALUED ELEMENTS. * CALCULATE & PRINT SUM & AVERAGE. * PRINT MAXIMUM N MINIMUM ELEMENT * SORT THE ARRAY * REMOVE THE DUPLICATE * COMPACT THE ARRAY * PRINT ARRAY IN REVERSE ORDER #include<iostream.h> #include<conio.h> #include<stdlib.h> class integerarray { int *a,len,sum,max,min; float avg; public: integerarray() { len=-1; sum=max=min=0; avg=0.0; } void enter() { clrscr(); cout<<"Enter the number of terms... "; int i=0; cin>>i; i=((i<0)?((-1)*i):(i)); a=(int*)malloc((sizeof(int))*i); len=i; for(int w=0;w<i;w++) { cout<<"Enter term number [ "<<(w+1)<<" ] ... "; cin>>(*(a+w)); } cout<<"Integers entered Successfully... Press any key "; getch(); } void print() { clrscr(); for(int i=0;i<len;i++) { cout<<endl<<"term number [ "<<(i+1)<<" ] = "<<*(a+i); getch(); } void peven(); void podd(); void sa(); void mm(); void sort(); void dup(); void com(); void rev();

}

enter(). break.sa(). } case '3': { A. } case '2': { A.rev(). void main() { clrscr(). cout<<"\n\n\n1)Enter Array\n2)Print Array\n3)Print Even valued elements\n4)Print odd valued elements\n5)Print the sum and average\n6)Print the max and min element\n7)Sort\n8)Remove the duplicates\n9)Compact\n0)Reverse\n\nEnter your Choice. } case '7': { A. } case '5': { A.}A.print(). break. } case '4': { A. break. } } //switch menu().sort(). char ch='l'. } void integerarray::peven() { for(int i=0.i<len. break.peven(). switch(ch) { case '1': { A. ". } case '0': { A.com(). } case '6': { A.. break.podd(). or any other key to exit. break. ch=getch(). void menu(). menu(). break. break.} void menu() { clrscr().mm()..i++) { if((*(a+i))%2==0) . } case '9': { A. break. } default: { exit(0). } case '8': { A..dup(). clrscr(). break..

} } if(flag==0) { (*(temp+tl))=(*(a+i)).i++) { if((*(a+i))>max) { max=(*(a+i)). } } (*(a+pos))=(*(a+i)).j<tl.j++) { if((*(a+i))==(*(temp+j))) { flag=1.. cout<<" Sum is.. } cout<<"\n\n\nPress any key. getch().j++) { if((*(a+j))<small) { small=(*(a+j))... "<<avg. } void integerarray::dup() { int *temp. getch().i++) { small=(*(a+i)). for(int j=(i+1).i++) { sum+=(*(a+i)). (*(a+i))=small. \n". for(int j=0.. pos=j.i++) { flag=0. getch().tl=0. ". "<<sum<<endl<<" Average. "<<max<<"\nMin term is.min=*a. for(int i=0. for(int i=0. } cout<<"\n Done.i++) { if((*(a+i))%2!=0) { cout<<"\nTerm number [ "<<(i+1)<<" ] = "<<(*(a+i)).flag=0. cout<<"\n\n\nPress any key..i<len.i<len.i<len.j<len.pos. } avg=((float)sum)/((float)len). for(int i=0.i<len.. } if((*(a+i))<min) { min=(*(a+i)). } void integerarray::mm() { int max=*a.i<len... clrscr(). \n". } void integerarray::sort() { int small. tl++. for(int i=0...{ cout<<"\nTerm number [ "<<(i+1)<<" ] = "<<(*(a+i)). getch(). } } } } } . } void integerarray::sa() { sum=0. "<<min. } void integerarray::podd() { for(int i=0.. cout<<" Max term is.. getch(). temp=(int*)malloc(len*(sizeof(int))). pos=i.. } } clrscr().

. tl++.. ". if(x>=0&&x<len) { for(i=0. } void integerarray::rev() { clrscr(). for(int i=(len-1). int x=-1.. getch(). a=temp.len=tl. ". } a=temp.i<len. } . } cout<<endl<<"Enter the term number u want to delete..i. "<<(*(a+i))..i--) { cout<<endl<<"Term no [ "<<(i+1)<<" ] is.i>=0.. } void integerarray::com() { int *temp. } cout<<endl<<"deleted. } getch().tl=0. len=tl.i++) { cout<<endl<<"term number [ "<<(i+1)<<" ] = "<<*(a+i). for(i=0. cout<<"\nDone.i<len. getch(). ".i++) { if(i==x) { continue.. x--. } *(temp+tl)=*(a+i). cin>>x..

menu().M[10][10].C.i++) { for(j=0. ".i<r1. } cout<<endl<<endl. } int i=0. CREATE A MATRIX CLASS. "<<j<<" ] of the st 1 matrix..h> void menu(). ". cout<<"Enter the Number of rows n columns of the first Matrix.i<r1.".j<c1.j<c1.i<r1.. "..i++) { for(j=0.j<c1.WRITE A MENU DRIVEN PROGRAM TO PERFORM MATRIX OPERATION: (A) SUM (B) DIFFERENCE (C) PRODUCT (D) TRANSPOSE #include<iostream. ".j=0.. } cout<<endl<<endl. getch(). getch().j++) { cout<<"Enter R & C of term number [ "<<i<<" . } for(i=0. M[i][j]=M1[i][j]+M2[i][j]. } getch(). } } for(i=0.j<c1.r2.. public: void add() { clrscr(). cin>>M2[i][j]. } } cout<<"\nDone. "<<j<<" ] of the 2nd matrix.j++) { cout<<M1[i][j]<<" + "<<M2[i][j]<<" \t".... for(i=0.i<r1.j++) { cout<<M[i][j]<<"\t".i++) { for(j=0..i++) { for(j=0. if(r1<0||r1>10||c1<0||c1>10) { cout<<"Error..M2[10][10].h> #include<conio. cin>>r1>>c1. int r1.R. clrscr()..c1.. } void sub() . class MATRIX { int M1[10][10].j++) { cout<<"Enter R & C of term number [ "<<i<<" . Press any key. cin>>M1[i][j].c2. for(i=0.Q4.h> #include<stdlib.

getch(). cout<<"Enter the Number of rows n columns of the first Matrix.k=0.i++) { for(j=0.j++) { cout<<"Enter R & C of term number [ "<<i<<" .. ". cin>>M1[i][j].. M[i][j]=M1[i][j]-M2[i][j].j++) { cout<<M1[i][j]<<" . } void tra() { clrscr(). } cout<<endl<<endl. cin>>M1[i][j]. for(i=0. getch().i++) { for(j=0.. for(i=0.. } for(i=0.i++) { for(j=0.j++) { cout<<M1[j][i]<<"\t". } } cout<<"\nDone.i<r1.."..clrscr()."<<M2[i][j]<<"\t". ". } getch().. menu(). clrscr(). } cout<<endl<<endl.j++) { cout<<M[i][j]<<"\t". ".j<c1. } void mul() { int pro=0. ". clrscr(). cout<<"Enter the Number of rows n columns of the first Matrix. "<<j<<" ] of the 1st matrix.i<r1.. "<<j<<" ] of the 2nd matrix.i<c1.j=0.j++) { cout<<"Enter R & C of term number [ "<<i<<" . ".j<r1. if(r1<0||r1>10||c1<0||c1>10) { . } cout<<endl<<endl. for(i=0... cin>>r1>>c1..j++) { cout<<"Enter R & C of term number [ "<<i<<" .i<r1. menu().j=0.j<c1.j<c1. } } for(i=0. } int i=0.j<c1.".i++) { for(j=0.. cin>>r1>>c1... cin>>M2[i][j]. for(i=0. cin>>r1>>c1. } getch(). if(r1<0||r1>10||c1<0||c1>10) { cout<<"Error..i++) { for(j=0. clrscr().j<c1. "<<j<<" ] of the 1st matrix.... cout<<"Enter the Number of rows n columns of the first Matrix. } } cout<<"\nDone. ".... ".i++) { for(j=0.i<r1.. ". getch().. getch(). if(r1<0||r1>10||c1<0||c1>10) { cout<<"Error. } int i=0. Press any key.i<r1.. Press any key.

} . clrscr(). c2=r1...j++) { cout<<"Enter R & C of term number [ "<<i<<" . } for(i=0. } for(i=0. for(k=0. ". clrscr(). getch(). R=r1.i<r2.j<c2. } M[i][j]=pro. cin>>M2[i][j].".k<c1. ". or any other key to exit.i<R.. } cout<<endl....add().i++) { for(j=0. "<<j<<" ] of the 2nd matrix. Press any key.j++) { pro=0. } cout<<endl<<endl. switch(ch) { case '2': { A. } }A. ". menu().i++) { for(j=0. } getch(). } r2=c1.. "<<j<<" ] of the 1st matrix.} cout<<endl. for(i=0. menu().i++) { for(j=0.i++) { for(j=0. cout<<"\n\n\n2)Add Two Matrices\n3)Subtract Two Matrices\n4)Product\n5)Transpose \n\nEnter your Choice..j++) { cout<<M2[i][j]<<"\t".{ cout<<"Error. break. } } for(i=0.j<C. cin>>M1[i][j].j++) { cout<<"Enter R & C of term number [ "<<i<<" . for(i=0.. ". cout<<M[i][j]<<"\t"..i<r1.j<c1.k++) { pro=pro+(M1[i][k]*M2[k][j]). ch=getch(). void main() { clrscr()..i<r2. char ch='l'. int i=0. } void menu() { clrscr()... } } cout<<"\nDone.j<c2..i<r1.j<c1.i++) { for(j=0. getch().j=0. C=c2.j++) { cout<<M1[i][j]<<"\t".

binaryS(). } } void display() { clrscr(). int L. A=new X[L]. } void enter() { clrscr(). display().i<L..toFind. for(int i=0.i<L. for(i=0.i<L.i=0.GIVE USER THE OPTION TO PERFORM LINEAR OR BINARY.h> #include<stdlib.sub(). cin>>A[i].i++) { cout<<"Term number [ "<<(i+1)<<" ] => "<<A[i]<<endl.. search(int len) { L=len. break. ".USE TEMPLATES.case '3': { A. int flag=0. ".. break. for(int i=0.. } case '5': { A. display(). linearS(). } case '4': { A. } } //switch menu(). } void linearS() { cout<<"Enter the term to search.i++) . getch().i++) { cout<<"\nEnter term number ["<<(i+1)<<"]. #include<iostream. cin>>toFind. } default: { exit(0).h> #include<conio. enter()... } cout<<"Press any key.mul().WAP TO SEARCH ELEMENT FROM A LIST. } Q5. ". break.h> template<class X> class search { public: X *A.h> #include<string.tra().

do { cout<<endl<<b<<m<<e<<toFind<<A[m]. pos=j. } } if(flag) { cout<<"\n\nFound.flag=0.. } void binaryS() { X small.. break. b=0.i<L. int pos. ". ". m=e/2. getch(). for(int j=(i+1).j++) { if((*(A+j))<small) { small=(*(A+j)).j<L.m. } else { cout<<"\n\nNot Found.. cout<<"\nEnter the term you want to search for. display()..{ if(A[i]==toFind) { flag=1.. getch().. e=L-1.e. if(A[m]==toFind) { flag=1. pos=i. for(int i=0. ".i++) { small=(*(A+i))... } } (*(A+pos))=(*(A+i)).. } else .. } cout<<"\n\nPress any key to continue. } cout<<"\n Sorting Done. break.. int b. (*(A+i))=small. Press any key. term number [ "<<(i+1)<<" ] => "<<A[i].. ". cin>>toFind.

break. ?\n\n\n1)Integer\n2)Real Numbers\n3)character\n\n\n\nEnter a choice or any other key to exit.. x=getch().. term number [ "<<(m+1)<<" ] => "<<A[m]. void menu() { clrscr().. } . break.{ if(A[m]>toFind) { e=m. getch(). } cout<<"\n\nPress any key to continue.. int l=0. m=(e+b)/2. cout<<"\n\nEnter the number of terms. m=(b+e)/2. "... } } }while(b!=e). cout<<"What data do you want to work with. switch(x) { case '1': { search<int> obj(l). ".. } else { cout<<"\n\nNot Found. ". cin>>l. l=(l<0)?(-l):(l). } else { b=m.... } case '3': { search<char> obj(l). if(flag) { cout<<"\n\nFound.. break.. char x. ". } }. } case '2': { search<double> obj(l).

default: { exit(0). } getch(). } void enter() { clrscr(). ". void s(). len=i. int i=0. . cout<<"Enter the number of terms.i<len. public: integerarray() { len=-1. } } } void main() { menu().h> class integerarray { int *a. cin>>(*(a+w)).h> #include<conio.. WAP TO SORT A LIST OF ELEMENTS... Press any key ". a=(int*)malloc((sizeof(int))*i).. for(int w=0. i=((i<0)?((-1)*i):(i)).w<i. } void b(). #include<iostream. cin>>i. getch(). } cout<<"Integers entered Successfully.len. } void print() { clrscr().w++) { cout<<"Enter term number [ "<<(w+1)<<" ] .i++) { cout<<endl<<"term number [ "<<(i+1)<<" ] = "<<*(a+i)...h> #include<stdlib. for(int i=0. ". } Q6.GIVE USER THE OPTION TO PERFORM SOTING USING INSERTION OR BUBBLE OR SELECTION SORT.

} void menu() { clrscr().. cout<<"\n\n\n1)Enter Array\n2)Print Array\n3)Buble Sort\n4)Insertion Sort\n5)Selection Sort\n\nEnter your Choice. switch(ch) { case '1': { A..void i().. break. break. } } //switch menu(). }A. ".enter().print().. void menu().i().s().b(). ch=getch(). break. } default: { exit(0). void main() { clrscr(). menu(). break. } case '3': { A. . } case '5': { A. } void integerarray::s() { int small. } case '2': { A. break. or any other key to exit.pos. clrscr(). } case '4': { A. char ch='l'.

. } *(a+j+1)=temp. . getch(). } cout<<"\n Done. *(a+j)=*(a+j+1).j<(len-i-1).i<(len). for(int i=0. j--. while(temp<(*(a+j))) { if(j<0) { break. j=i-1.i++) { small=(*(a+i)). (*(a+i))=small.for(int i=0.i++) { temp=*(a+i)..j<len. ".j++) { if((*(a+j))>(*(a+j+1))) { temp=*(a+j). pos=i.i<len.j=0. } void integerarray::b() { int temp. getch(). for(int j=(i+1). } } (*(a+pos))=(*(a+i))..j++) { if((*(a+j))<small) { small=(*(a+j)). for(int i=1. } *(a+j+1)=*(a+j).i<len. } cout<<"\n Done. } void integerarray::i() { int temp.i++) { for(int j=0.. ". pos=j.

i++) { len=strlen(args[i]).y<argv.occ++. } } .h> struct table { int ch. } for(int y=1.char *args[]) { clrscr().j<len..h> #include<stdlib.i<argv. if(!isalpha(x)) { continue.flag=0. } table A[26]. for(int k=0. exit(0). } flag=1.. for(int j=0. Press any key to exit.x=0. if(argv<=1) { cout<<"No text entered.k<pos.. } Q7.k++) { if(A[k].". } } } cout<<"\n Done.h> #include<conio.h> #include<iomanip. #include<iostream. getch().j++) { x=((int)*(args[i]+j)). int occ. ".. OF OCCURRENCE OF EACH LETTER OF ALPHABET IN THE TEXT ENTERED AS COMMAND LINE ARGUMENTS.len=0.. for(int i=1.h> #include<string. int pos=0.y++) { cout<<endl<<args[y].ch==x) { flag=0.h> #include<ctype. } if(x>=97) { x-=32.*(a+j+1)=temp.}. void main(int argv. getch(). WAP THAT PRINTS A TABLE INDICATING THE NO. A[k]. break..

cout<<"\nSwapped Numbers Are = "<<a<<" .x=x-y void main() { cout<<"\nEnter the two numbers. } Q8.. getch().b). WAP TO USE IT.occ<<setw(10). ".. cin>>a>>b.y) x=x+y. #include<iostream.h> #define swap(x. WRITE A MACRO THAT SWAPS TWO NUMBERS THEN WAP TO USE IT. swap(a.142) void main(void) { cout<<"\n\nEnter The RADIUS.ch<<setw(10)<<A[q]. int a. "<<b. int R.h> #define area(r) (r)*(r)*(3.if(flag==1) { A[pos].ch=x.y=x-y.. pos++. cout<<"Area is = "<<area(R). } getch(). } Q9.} .h> #include<conio. ".b. A[pos].occ=1.q<pos. WRITE A MACRO THAT CALCULATES THE AREA OF THE CIRCLE. } } } for(int q=0.q++) { cout<<endl<<(char)A[q].. #include<iostream. cin>>R.

h> #include<stdlib. (F) CONVERT ALL LOWER CASE CHAR TO UPPER CASE CHARACTER (G) CONVERT ALL UPPER CASE CHAR TO LOWER CASE CHARACTER (H) CALCULATE NO.i++) { str[i]=s[i]. void vow(). } void add(). OF VOWELS (I)TO REVERSE THE STRING #include<iostream. void u2l(). WAP TO PERFROM FOLLOWING OPERATION ON STRING:: (A) SHOW ADDRESS OF EACH CHARACTER (B)CONCATENATE TWO STRINGS WITHOUT USING STRCAT FUNCTION (C) CONCATENATE TWO STRINGS USING STRCAR FUNCTION (D) COMPARE TWO STRINGS (E) CALCULATE LENGTH OF STRING USING POINTERS.char *s[]) { N=l.Q10. void com().h> class myString { char *str[2].h> #include<string. } len(). void con_u(). void rev().h> #include<conio. for(int i=0.i<l. void con_w(). public: myString(int l.N. int L[2]. void len(). void l2u().h> #include<stdio. . void show().

} case '4': { A->com().\n\n". ch=getch(). char ch. int L=2. clrscr().str). } case '8': { A->vow(). void menu().. } case '3': { A->con_u(). break. } case '5': { A->len().i++) { cout<<endl<<"Enter String number "<<(i+1)<<" => ". break. cout<<"\n\n1)Show Address of each character\n\n2)Concatenate the two strings (without using strcat)\n\n3)Concatenate using strcat\n\n4)Compare the 2 strings\n\n5)Calculate length of strings\n\n6)Convert all lowercase characters to uppercase\n\n7)Convert all uppercase characters to lowercase\n\n8)Calculate number of vowels\n\n9)Reverse the strings\n\nPress any other key to exit. } A=new myString(L. gets(str[i]). A->show(). } case '6': { A->l2u(). void main() { clrscr(). } void menu() { clrscr(). menu(). } case '7': { A->u2l(). } case '2': { A->con_w(). break. for(int i=0. switch(ch) { case '1': { A->add(). break. } case '9': . break. break. break.. char *str[2].}*A.i<L. break.

break. getch(). for(int i=0.str[1]). L[0]+=L[1]. int len=L[0]+L[1]...{ A->rev(). L[0]=len.i<len. } void myString::con_u() { // char *a=str[0]. } . // str[0]=(char*)malloc((sizeof(char))*(L[0])). cout<<"\nPress any key to continue. } void myString::add() { void *a. // strcpy(str[0]. } } *(str[0]+len)='\0'.j<L[i].j. str[0]=(char*)malloc((sizeof(char))*len).i<N. cout<<"\nPress any key to continue.a). strcat(str[0]. } void myString::con_w() { char *a=str[0]..i++) { cout<<endl<<"String "<<(i+1)<<endl<<endl. for(i=0. for(j=0. } } getch(). } } menu(). cout<<endl<<"Address of "<<*(str[i]+j)<<" is = "<<a. } else { *(str[0]+i)=*(str[1]+(i-L[0]))."..i++) { if(i<L[0]) { *(str[0]+i)=*(a+i). getch(). } default: { exit(0).". int i.j++) { a=(str[i]+j).

i++) { if((*(str[0]+i))==(*(str[1]+i))) { status=0.. } else { cout<<"\nAlphabatically arranging String 2 comes before string 1\n".(*(str[i]+j))!='\0'. } else { 2\n". for(int i=0. } } if((status==0)) { if(L[0]==L[1]) { cout<<"\nThe two strings are equal..i++) { for(j=0. L[i]=j. continue. } else { status=1. cout<<"\nLength of String "<<(i+1)<<" is => "<<L[i].i<N. } } } else { if(status<0) { cout<<"\nAlphabatically arranging String 1 comes before string 2\n". getch().j.j..j++).". } break. cout<<"\nAlphabatically arranging String 1 comes before string } .\n". } else { if((*(str[0]+i))<(*(str[1]+i))) { status=-1. } void myString::len() { int i.i<Len. int Len=(L[0]>L[1]?(L[1]):(L[0])). } else { if(L[0]>L[1]) { cout<<"\nAlphabatically arranging String 2 comes before string 1\n".void myString::com() { int status=0. getch().. for(i=0. } void myString::l2u() { int i. } } cout<<"\nPress any ket to continue.

int vowel=0. } void myString::vow() { int V[]={'A'.i<N.'O'.. getch().j<L[i].for(i=0.i<N.. Press any key to continue.j<L[i]. ".. } . } void myString::rev() { char temp.i<N.'e'..'o'.'i'.j.\n".i++) { strrev(str[i]).k++) { if((*(str[i]+j))==V[k]) { vowel++..'E'.k<10..j++) { if((*(str[i]+j))>=((int)'a')&&(*(str[i]+j))<=((int)'z')) { (*(str[i]+j))-=32...'a'.j++) { if((*(str[i]+j))>=((int)'A')&&(*(str[i]+j))<=((int)'Z')) { (*(str[i]+j))+=32. } } } cout<<"\n\nDone. ".'U'. } void myString::u2l() { int i. getch(). } } } cout<<"\n\nNumber of vowels in string number "<<(i+1)<<" are => "<<vowel.'u'}. for(int i=0. } cout<<"\nPress any key to continue. for(i=0.i<N. for(int i=0. getch(). Press any key to continue... } } } cout<<"\n\nDone.'I'.j<L[i].i++) { for(j=0.i++) { vowel=0.i++) { for(j=0.j++) { for(int k=0. for(int j=0.

double r. d=S..". n=S. (E) WAP TO TEST THE ABOVE CLASS #include<iostream.".n.j<L[i]. (C) PROVIDE A NO ARGUMENT CONSTRUCTOR WITH DEFAULT VALUE.PROVIDE A COPY CONSTRUCTOR ALSO. getch().j++) { cout<<*(str[i]+j). (VI) DECREMENT(OVERLOAD -. (D) WRITE METHOD FOR : (I) ADDITION(OVERLOAD + OPERATOR).. for(int j=0.. (II) SUBTRACTION(OVERLOAD . } void myString::show() { for(int i=0. } } } Q11.OPERATOR).h> #include<stdlib. (V) INCREMENT(OVERLOAD ++ OPERATOR).cout<<"\n\nPress any key to continue. (IX) PRINT IN THE FORM OF A/B. (VII) OVERLOAD = = OPERATOR(TO CHECK EQUALITY OF TWO RATIONAL NO.i<N.) AS A FRIEND FUNCTION. (IV) DIVISION(OVERLOAD / OPERATOR).i++) { cout<<endl<<"string "<<(i+1)<<" is => ". public: rational(rational &S) { cout<<"\nCopy Constructor. (B) WRITE A CONSTRUCTOR METHOD THAT ENABLES AN OBJECT OF THIS CLASS TO BE INITIALISED WHEN IT IS DECLARED.h> #include<conio. (A) USE INTEGER VARIABLE TO REPRESENT NUMERATOR & DENOMINATOR. (III)MULTIPLICATION(OVERLOAD * OPERATOR)..d.h> class rational { int n.OPERATOR). (VIII)OVERLOAD ASSIGNMENT OPERATOR. CREATE A CLASS RATIONAL FOR PERFORMING ARITHMETIC WITH RATIONAL NO. } .d.

n=n-d. operator*(rational). return(*this). void operator++() { cout<<"\nPreIncrement. return(*this).int d) { cout<<"\nParameterised Constructor.. operator-(rational). } rational operator=(rational X) { cout<<"\nAssignment operator..rational).d. } friend int operator==(rational.rational() { cout<<"\nDefault Constructor.. n=n+d. } rational rational rational rational operator+(rational).". } rational(int n.. n=0. this->n=n. ". cout<<endl<<n<<" / "<<d<<" = "<<r. } void display() { r=((double)n)/((double)d). ".. n=X. n=n-d...n... . } rational operator--() { cout<<"\nPreDecrement... } void operator--(int x) { cout<<"\nPostDecrement. d=1. ". ". d=X.. this->d=d. } void operator++(int x) { cout<<"\nPostIncrement. operator/(rational).. ". ". n=n+d..

return (Z).n)/((double)X. Y.. } rational rational::operator*(rational X) { cout<<"\nMultiplication.d)).d).n)). } return (0). rational Z.r=((double)Z.n)/((double)Y.n).d).d). rational Z. Z...n). } rational rational::operator/(rational X) { cout<<"\nDivision. Z.rational X) { cout<<"\n Equality Operator. Z.n=((this->n)*(X.d=(this->d)*(X. if(Y.r==X.n)/((double)Z.n)).d)..n)/((double)Z.d).n=((this->n)*(X. Z. X.d))-((this->d)*(X.n=(this->n)*(X.n)/((double)Z.}.r=((double)Z. Z..". Z.d=(this->d)*(X.d).r=((double)Y. Z. } rational rational::operator+(rational X) { cout<<"\nAddition.n)/((double)Z.d=(this->d)*(X. Z.".d)..". Z.r) { return (1). Z.. ".".r=((double)Z. Z.d). } rational rational::operator-(rational X) { cout<<"\nSubtraction.d=(this->d)*(X.n=((this->n)*(X. return (Z).r=((double)X. Z..d).. rational Z. } . int operator==(rational Y. return (Z).r=((double)Z.. return (Z).d))+((this->d)*(X. rational Z.

cout<<"\n\n1) Add (+)\n2) Sub (-)\n3) Mul (*)\n4) Div (/)\n5) Inc (++)\n6) Dec (--)\n7) chk (==)\n8) asg (=)\n\n\nEnter choice. Or any other key to exit. cout<<endl<<"\t="<<endl.display().d. W. . } switch(ch) { case '1': { rational A.. } else { cout<<"\nEnter the numerator and denominator.void menu(rational &W) { clrscr(). break. int n. Q->display(). cout<<"\nDone. ". W.. switch(ch) { rational *Q. Q=new rational(n. case '7': { } case '1': { } case '2': { } case '3': { } case '4': { cout<<"\n\n1) Enter the value for the second rational number or\n2) use copy constructor. ". char a. A=W+(*Q). cout<<endl<<"\t+"<<endl...\n". char ch... if(a=='2') { Q=new rational(W).. ". cout<<endl..display()..display().\n\n First Rational number is.d).. ch=getch(). A.. a=getch(). cin>>n>>d..

display(). W. } } break. cout<<endl<<"\t="<<endl. A=W*(*Q). cout<<endl<<"\t="<<endl. break. break.display(). W. } case '4': { rational A.".. cout<<endl<<"\t*"<<endl. W. if(!a) { cout<<"\nNot Equal. Q->display(). A. cout<<endl<<"\t-"<<endl. Q->display()..display().display(). W. . } case '7': { int a=(W==(*Q)). } case '3': { rational A. break. } else { cout<<"\nEqual. A. } case '5': { W++.".} case '2': { rational A.. Q->display().display(). A=W-(*Q)..display(). A.display(). } break. A=W/(*Q). cout<<endl<<"\t/"<<endl. cout<<endl<<"\t="<<endl.

menu(W). } case '6': { W--. ". W. W. cin>>n>>d.d. break.display(). break.++W.display().. menu(q). rational q(n. ". cin>>n>>d. W. cout<<"Enter the numerator and denominator.display(). W=X. } default: { exit(0).d).d). W. int n. } .display(). int n.d. --W.. break. rational X(n. } case '8': { cout<<"\nEnter the numerator and denominator... } } getch(). } void main() { clrscr().

0.".Q12. CREATE A CLASS TRIANGLE INCLUDE OVERLOAD FUNCTION FOR CALCULATING AREA.h> #include<stdlib.b.".. public: triangle() { cout<<"\nDefault constructor. v1=v2=b=h=0.". AREA=area(v1.h> class triangle { float v1. } triangle(float v1..h> #include<conio.float v2. double AREA. this->b=b. } triangle(float h. AREA=0..OVERLOAD ASSIGNMENT OPERATOR & EQUALITY OPERATOR #include<iostream.float b) { cout<<"\nInitialising the base and height.b). this->v2=v2.float b) { cout<<"\nInitialising the three sides.v2.. h=0.v2..h> #include<math. this->v1=v1..h. this->h=h. this->b=b. .

". this->h=X. AREA=area(h. int a=0.s. } triangle(float k) { cout<<"\nInside equilateral triangle contructor. float s=s1+s2+s3. this->v1=X..AREA.float b1) { cout<<"\nCalculating area with the Height and Base length given..v1=v2=0. return(X). X=sqrt((s)*(s-s1)*(s-s2)*(s-s3)).....float s3) { cout<<"\nCalculating area with the three sides given. } double area(float s) { cout<<"\nCalculating area of the equilateral triangle.b). ".AREA) a=1. } double area(float s1.v2. h=0. this->b=X. v1=v2=b=k.v1.. } int operator==(triangle X) { cout<<"\nComparing.s)).5).. double X. } void operator=(triangle X) { cout<<"\n\nAssigning values (Inside assignment operator function) . this->v2=X.. } double area(float h1.h. AREA=area(b). return (a). X=h1*b1*(0..b.float s2. return(area(s... ". \n". AREA=X. ". } void disp() { . if(this->AREA==X. double X. ". s/=2. return(X).

. } case '2': { cout<<"\nEnter one side.b.. cout<<"\n\n\nHow do you want to find out the area of the triangle.b.disp(). triangle t(s). ch=getch().". .. triangle t(b. ".disp(). ". } case '4': { cout<<"\nenter the three sides. triangle t(a.h). void menu(triangle &x) { clrscr()..if(v1) { cout<<" Edge 1 = "<<v1<<endl<<" Edge 2 = "<<v2<<endl<<" Edge 3 = "<<b<<endl. } }.c).c. cin>>s. } cout<<endl<<" Area = "<<AREA.disp()..".. } if(h) { cout<<"\nHeight = "<<h<<endl<<" Base = "<<b. cin>>a>>b>>c.". break. double s..b. break.. } case '3': { cout<<"\nEnter the base and heght. switch(ch) { case '1': { float a..\n1) Using the dimensions of the three sides\n\n2) Equilateral triangle\n\n3) Using the Base and Height\n\n4) Asg (=)\n\n5) cmp (==)\n\n\nEnter choice or any othr key to continue. t. float h. char ch. cout<<"\nEnter the three sides of the triangle. t... break. t. cin>>b>>h..

x=t. break.c). "..c). } default: { exit(0). } case '5': { float a. menu(x).b. x. cin>>a>>b>>c. cout<<"\nEnter the 3 sides of the first triangle. } . } } getch(). cout<<"\nEnter the 3 sides of the second triangle.c. triangle t1(a....b. triangle t(a.disp().b. cin>>a>>b>>c.. triangle t2(a.". menu(x). } else { cout<<"\nNot Equal.".float a....".c.b. } break.b. } void main() { triangle x. if(t1==t2) { cout<<"\n\n\nEqual.c). cin>>a>>b>>c.

h> #define leap(x) \ if((x%4)==0) \ { \ if((x%100)!=0) \ { \ cout<<"Leap".Q13...WRITE A MACRO TO TEST WHETHER A YEAR IS LEAP OR NOT. ".". #include<iostream. \ } \ else \ { \ cout<<"Not Leap. . \ } \ else \ { \ if((x%400)==0) \ { \ cout<<"Leap".. \ } void main() { cout<<"\nEnter the year..".. \ } \ } \ } \ else \ { \ cout<<"Not Leap.. int a.

cout<<"\nEnter age. } Q14. CREATE THE PERSON CLASS.h> #include<stdio. gets(name).CREATE SOME OBJECT OF THIS CLASS.. ... ". puts(name).e.MAINTAIN EMPLOYEE INFORMATION.. public: virtual void enter() { cout<<"\nEnter the name. } virtual void disp() { cout<<"\nName => ". CREATE. int age. i.h> #include<stdlib. #include<iostream.". cin>>age.cin>>a.h> class person { protected: char name[20].INHERIT THE CLASS PERSON TO CREATE EMPLOYEE CLASS. DISPLAY & DELETE EMPLOYEE OBJECT & CALCULATE THEIR WAGES (show run time polymorphism).h> #include<conio. leap(a).

Press any key to view details... int pi."<<wpd<<" per hr the employee should get Rs. person *p.enter(). cin>>eid>>wpd. //Person class should not be abstract. } void disp() { person::disp().". cout<<"\nFor "<<d<<" number of days.i++) { cout<<"\nRecord number.i. p[i].*q.. ".. cout<<"\n\nHow many Objects of person do u want to create. cin>>d. ". employee *e. cout<<"\nEnter the employee id and wage per day.cout<<"Age = "<<age.. } }.. ". getch(). "<<(d*wpd). double d. .*x. cin>>pi..i<pi... public: int eid. }. } void calWage() { cout<<"\nEnter the number of days the employee worked.. void main() { clrscr(). } //virtual void calwage()=0. void enter() { person::enter().. at Rs. class employee:public person { private: double wpd. p=new person[pi]... } cout<<"\n\nDone.. for(i=0. "<<(i+1). cout<<"\nEmployee id is => "<<eid<<endl<<"\nWage per day is = "<<wpd.

q->enter().i<pi.i++) { q=&e[i]. for(i=0.. delete []p.". q=e.i<pi. } } if(flag==1) { cout<<"\nDeleted.calWage().i<pi. cout<<"\nEnter the Employee id u want to delete. int flag=0.disp().".i<pi. q->disp(). ". delete x. for(. ". } x=&e[pi].". for(i=0....i++) { q=&e[i]. getch(). } cout<<"\nPress any key to view details. e[i]. } getch().. } cout<<"\n\nPress any key.disp().i<(pi-1). cin>>pi. q=e. for(i=0. getch()..i++) { e[i]. ". int EID. for(i=0.. } cout<<"\n\nPress any key.i++) { p[i]. pi--...... e=new employee[pi]. cout<<"\n\nEnter the number employees.i++) { if(e[i].eid==EID) { flag=1. cin>>EID. . getch().. break.i++) { e[i]=e[i+1].i<pi. to calculate their wages.for(i=0..

.h> #include<stdlib. q->disp(). OVERLOAD ++ OPERATOR (BOTH PREFIX AND POSTFIX) (D)DECREMENT.BREATH.".} else { cout<<"\nNotFound.i<pi. OVERLOAD -– OPERATOR (BOTH PREFIX AND POSTFIX) (E)OVERLOAD OPERATOR == (TO CHECK EQUALITY OF TWO BOXES) (F)OVERLOAD ASSIGNMENT OPERATOR (G)CHECK IF IT IS A CUBE OR CUBOID.INCLUDE FOLLOWING METHODS IN IT:(A)CALCULATE SURFACE AREA (B)CALCULATE VOLUME (C)INCREMENT.b. } Q15. } cout<<"\n\nPress any key to exit. } for(i=0. WAP TO TEST THE ABOVE CLASS.i++) { q=&e[i].A. getch(). public: BOX() { BOX(0). #include<iostream..HEIGHT... CREATE A CLASS BOX CONTAINING LENGTH.h> #include<conio.h> class BOX { private: double l. } BOX(double s) { l=b=h=s. } .".h.V.

} void operator--() { cout<<"\nPreDecrementing.BOX(double l. ++b. h--. --l. return (V). } void display() { cout<<endl<<"L = "<<l<<"\nB = "<<b<<"\nH = "<<h<<"\n\nArea = "<<ca()<<"\n\nVolume = "<<cv()<<endl. } double ca() { A=0... --b. V=l*b*h. l++. ++h.. ++l.". b++. } void operator++() { cout<<"\nPreIncrementing.double h) { this->l=l. h++..double b. b--.". } void operator++(int x) { cout<<"\nPostIncrementing. l--. this->h=h. } void operator--(int x) { cout<<"\nPostDecrementing... return(A)..". . } double cv() { V=0. A+=(2)*((l*b)+(b*h)+(h*l)).. this->b=b.". --h.

".h) { return 1.ca())&&((this->cv())==(X. } return(0).} BOX operator=(BOX X) { cout<<"\nAssigning values. } } if(b==X... } int cube() { if((l==b)&&(l==h)) { return(1).l.l) { if(b==X.l) { return 1. this->h=X.h. } } . if(this->cube()&&X.. }. } return 0. this->l=X. } else { if(((this->ca())==X.cube()) { if(l==X.b) { return 1.. return(*this).h) { if(h==X.".b) { if(h==X. int BOX::operator==(BOX X) { cout<<"\nChecking Equality.b.cv()))) { if(l==X. this->b=X. } int operator==(BOX).

} } void menu(BOX &). BOX b1(a.h) { if(h==X.l) { return 1. } } if(b==X. } } } } return 0.b) { return 1..l) { return 1. } void menu(BOX &w) { clrscr().b. menu(b1).b) { if(h==X.l) { if(h==X. cin>>a>>b>>c.. cout<<"\n\n\nEnter the L. .h) { if(b==X. } } } if(l==X.c).} if(l==X.b) { if(b==X.b. ".l) { if(h==X. double a. void main() { clrscr(). } } if(b==X.c.h) { return 1.B and H of the Cube / Cuboid.

} else { cout<<"\nNot Equal. if(w==n) { cout<<"\nEqual. Or any other key to EXIT.... w.. break.cube()) { cout<<"\nCube.c..B.b.. w. char ch. break.. ++w.H.". BOX n(a.H.b.". w. ".c. ch=getch().. cout<<endl<<"\n\n1)Increment\n2)Decrement\n3)Check Equality\n4)Assign values to new BOX\n5)Check if the currewnt box is cube or cuboid\n\nEnter choice.display().c).display(). cin>>a>>b>>c. w=n.c).. --w.display(). } break. switch(ch) { case '1': { w++...display(). double a. ". } case '3': { cout<<"\nEnter L.display(). } case '5': { if(w. ". w.B..". break.w.. BOX n(a. . double a. } case '2': { w--. cin>>a>>b>>c.b..b. } case '4': { cout<<"\nEnter L.

. } default: { exit(0). . } break. cin>>a. getch().. } Q24.". } int factR(int x) { if(x<=1) { return (1). menu(w). } int factI(int x) { int f=1..h> int factR(int). void main() { cout<<"\n\nEnter the number. } } cout<<"\nPress any key.} else { cout<<"\nCuboid. ".. WAP TO CALCULATE FACTORIAL & TO COMPUTE FACTORS OF GIVEN NO. int factI(int). = "<<factI(a). cout<<"Factorial using recursion = "<<factR(a)<<"\n\nFactorial using iteration. (a) USING RECURSION (b) USING ITERATION #include<iostream.. ". int a=0... } return((x)*(factR(x-1)))..

#include<iostream.1.. int fI(int). b=a+b.int b. } cout<<b<<" . int a=0.int.i<=x. if(i==x) { return 0. } return f. cout<<"\nUsing recursion = ". cout<<"\nSum = "<<fI(a).i++) { f*=i. ". = ". cin>>a.for(int i=1. cout<<"\n\nUsing iteration..a). } int fR(int a. WAP TO CALCULATE FIBONACCI SERIES: (a) USING RECURSION (b) USING ITERATION. . ". cout<<"\nSum = "<<fR(0.. void main() { cout<<"\n\nEnter the number of terms.int x) { static int i=0.int). } Q25..h> int fR(int.

if(((a%i)==0)&&((b%i)==0)) { gcd=i.b=1. i++.C. } return sum.int. } Q26. WAP TO CALCULATE G. "..b). cin>>a>>b. for(int i=0.m=(a>b?b:a).b. int gcdI(int.i<x. b=a+b.int i) { static int gcd=1. cout<<"GCD using recursion = "<<gcdR(a. void main() { cout<<"\n\nEnter the numbers. int a=0. } .h> int gcdR(int.D OF TWO NO. return (a+fR(a.a=b-a. = "<<gcdI(a.int).int b. sum+=b.x)). } if(i==m) { return gcd.sum=0.. } int fI(int x) { int a=0.. a=b-a. } int gcdR(int a.b=0. : (a) WITH RECURSION (b) WITHOUT RECURSION #include<iostream.b.int)..i++) { cout<<b<<" .1)<<"\n\nGCD using iteration. ".

int y) { int gcd=1.i). } } int gcdI(int x. } . } } return gcd.g++) { if(((x%g)==0)&&((y%g)==0)) { gcd=g. for(int g=1. return gcdR(a.b.m=(x>y?y:x).else { i++.g<=m.

Sign up to vote on this title
UsefulNot useful