// ***** ROOTS OF QUADRATIC EQUATION * #include #include #include void main() { int a,b,c; float D,x1,x2; cout<<"Enter the coefficients a,b,c of the equation ax^2+bx+c:"; cin>>a>>b>>c; D=b*b-4*a*c; if(D<0) { cout<<"Roots are imaginary!!!Aborting!!"<>year; if((year%4==0)&&(year%100!=0)||(year%400==0)) cout<<"Year entered is a leap year!!"; else cout<<"Year entered is not a leap year!!"; } /*OUTPUT Enter year:2000 Year entered is a leap year!! Enter year:2100 Year entered is not a leap year!! */ // ***** NESTED IF ELSE * #include #include int main() { char ch; int a,b; float result; cout<<"Enter two numbers:"; cin>>a>>b; cout<<"Enter the operation u want to perform(+ - * /):"; cin>>ch; if(ch=='+') result = a+b; else if(ch=='-') result = a-b; else if(ch=='*') result = a*b; else if(ch=='/') result = a/b; else { cout<<"Invalid Operator!!Aborting!!"; exit(0); } cout<<"Result="< #define PI 3.141 int main() { char shape,choice; int r,a; double area,perimeter; cout<<"Enter the shape code c-circle/s-square:"; cin>>shape; switch(shape) { case 'c': cout<<"Enter the radius:"; cin>>r; cout<<"What do you want to do? a-area p-perimeter:"; cin>>choice; switch(choice) { case 'a': area=PI*r*r; cout<<"Area="<>a; cout<<"What do you want to do? a-area p-perimeter:"; cin>>choice; switch(choice) { case 'a': area=a*a; cout<<"Area="< void main() { float n,tm,term,fact=1; float x; int sign=1; double sum=0; cout<<"Enter the angle:"; cin>>x; cout<<"Enter the number of terms:"; cin>>n; x=x*3.141/180; sum+=x; tm=x; for(int i=2;i>x; cout<<"Enter the number of terms:"; cin>>n; x1 = 3.142 * (x / 180.0); sum = 1.0; nr = x1*x1; while(i<=n) { dr = dr * pow * (pow - 1.0); sum = sum + (nr / (dr * sign)); sign = sign * (-1); pow = pow + 2.0; nr = nr * x1 * x1; i++; } cout<<"Result="< void main() { int space=2; for(int i=1;i<3+1;i++) { for(int j=1;j<=space;j++) cout<<" "; for(int k=1;k<=i;k++) cout<<"* "; space--; cout< void main() { int n,space=0; cout<<"Enter number:"; cin>>n; while(n>0) { ++space; for(int i=1;i<=n;i++) cout<0;j--) cout< void main() { char ch='A',c='D',ch1; ch1=c; for(int i=0;i<=4;i++) { for(ch='A';ch<=ch1;ch++) cout<='A';c--) cout< void main() { int space,n; cout<<"Enter the number of rows in the pattern:"; cin>>n; space=n-1; for(int i=1;i #include int main() { int no,i; cout<<"In the range 1-500:"<sqrt(no)) cout< #include float fact(int i) { if(i==1) return i; else if(i==0) return 1; else return i*fact(i-1); } void main() { float ang,x,n; int sign=1; cout<<"Enter the angle:"; cin>>ang; cout<<"Enter the number of terms:"; cin>>n; x=3.141*(ang/180.0); float sum_sin=0,sum_cos=0; for(int i=1,j=1,k=0;i<=n;i++,j+=2,k+=2) { sum_sin=sum_sin+((sign*pow(x,j))/(fact(j))); sum_cos=sum_cos+((sign*pow(x,k))/(fact(k))); sign=sign*-1; } cout<<"\nsin("<>x>>y>>z; int result=max(x,y,z); cout<<"The largest of the three numbers is:"< float calcSalary(float sal,float rate=8) { float new_salary=sal+(sal*rate/100); return new_salary; } void main() { float salary,rate; cout<<"Enter the salary:"; cin>>salary; cout<<"Enter the rate(press 0 for default rate)"; cin>>rate; float new_sal; if(rate==0) new_sal=calcSalary(salary,8); else new_sal=calcSalary(salary,rate); cout<<"The net salary is:"< #define PI 3.141 float calcVolume(float a) { float volume=a*a*a; return volume; } float calcVolume(float l,float b,float h) { float volume=l*b*h; return volume; } float calcVolume(float r,float h) { float volume=PI*r*r*h; return volume; } void main() { float volume,a,l,b,h,r; int choice; cout<<"Find Volume of:"<>choice; switch(choice) { case 1: cout<<"Enter the side of cube:"; cin>>a; volume=calcVolume(a); break; case 2: cout<<"Enter the dimensions of the cuboid:"; cin>>l>>b>>h; volume=calcVolume(l,b,h); break; case 3: cout<<"Enter the radius:"; cin>>r; cout<<"Enter the height:"; cin>>h; volume=calcVolume(r,h); break; default: cout<<"Invalid Choice!!"; break; } cout<<"\nVolume is:"< void dec2bin(int n) { if(n==1) cout<>num; cout<<"Binary Equivalent of "< void bubbleSort(int [],int); void main() { int ar[50],item,n,index; cout<<"Enter number of elements in the array:"; cin>>n; cout<<"Enter Array Elements...."<>ar[i]; bubbleSort(ar,n); cout<<"\n\nThe Sorted array is..."< int Bsearch(int ar[],int size,int item) { int beg,last,mid; beg=0; last=size-1; while(beg<=last) { mid=(beg+last)/2; if(item==ar[mid]) return mid; else if(item>ar[mid]) beg=mid+1; else last=mid-1; } return -1; } void main() { int ar[50],item,n,index; cout<<"Enter the number of elements:"; cin>>n; cout<<"Enter Array(must be sorted in ascending order)..."<>ar[i]; cout<<"Enter the element to be searched for:"; cin>>item; index=Bsearch(ar,n,item); if(index==-1) cout<<"\nSorry!!Given element cannot be found!!"< int fact(int n) { int value=1; while(n!=0) { value=value*n; n--; } return value; } void main() { int rows,i,j,k; cout<<"Enter the number of rows you want in the triangle:"; cin>>rows; for(i=0;i #include void main() { int a[10][10],b[10][10],c[10][10],i,j,m,n,p,q,ip; cout<<"Input row & column of matrix A:"; cin>>m>>n; cout<<"Input row & column of matrix B:"; cin>>p>>q; if(n==p) cout<<"Matrices can be multiplied!!"<>a[i][j]; cout<<"Input Matrix B..."<>b[i][j]; for(i=0;i #include #include void main() { char str1[30],str2[30]; int i,len; cout<<"Enter the string:"; gets(str1); len=strlen(str1); for(i=0;str1[i]!='\0';i++) { str2[--len]=str1[i]; } str2[i]='\0'; cout<<"\nReversed String is:"; for(i=0;str2[i]!='\0';i++) { cout< #include #include void main() { char str1[30],str2[30]; int i,len; cout<<"Enter the string:"; gets(str1); len=strlen(str1); for(i=0;str1[i]!='\0';i++) str2[--len]=str1[i]; str2[i]='\0'; int flag=1; for(i=0;str1[i]!='\0';i++) { if(str1[i]!=str2[i]) { flag=0; break; } } if(flag==0) cout<<"Sring Entered is Not a Palindrome!!"; else cout<<"String Entered is a Palindrome!!"; } /*OUTPUT Enter the string:WELCOME TO C++ Sring Entered is Not a Palindrome!! Enter the string:MALAYALAM String Entered is a Palindrome!! */ // ***** ORDERING A STRUCTURE * #include #include #include struct Student { char name[25]; float marks; }s[50]; void selSort(int size) { int small,pos; Student tmp; for(int i=0;ismall) { small=s[j].marks; pos=j; } } tmp=s[i]; s[i]=s[pos]; s[pos]=tmp; } } void main() { int n; cout<<"Enter the number of students:"; cin>>n; cout<<"Enter details of students:"<>s[i].marks; } selSort(n); cout<<"The sorted students on marks is:"< void swap_callbyvalue(int x,int y) { int temp; temp=x; x=y; y=temp; cout<<"Value 1:"<>a>>b; cout<<"CALL BY VALUE...:"< #include void printArray(int *p,int n) { cout<<"Elements in the array are:"<>n; cout<<"Enter the elements:"<>a[i]; int *p=a; printArray(p,n); } /*OUTPUT Enter the number of elements(max 50):4 Enter the elements: 1 2 3 4 Elements in the array are: 1 2 3 4 */ // ***** TO IMPLEMENT INHERITANCE USING CONSTRUCTORS AND DESTRUCTOTS * #include class Base1 { protected: int a; public: Base1(int x) { a=x; cout<<"Contructing Base1"< class Distance { int a; public: Distance(){} Distance(float x) { a=x; } Distance operator+=(Distance); void display(); }; Distance Distance::operator+=(Distance y) { Distance res(0); res.a=a+y.a; return(res); } void Distance::display() { cout<>m; cout<<"Enter Distance2:"; cin>>n; Distance d1(m),d2(n); Distance d3=d1+=d2; cout<<"Distance1=";d1.display(); cout<<"Distance2=";d2.display(); cout<<"Sum=";d3.display(); } /*OUTPUT Enter Distance1:10 Enter Distance2:20 Distance1=10 Distance2=20 Sum=30 */ /* ******************************** TO IMPLEMENT VIRTUAL FUNCTIONS * ******************************** */ #include class Base { public: void display() { cout<<"Display Base"<display(); bptr->show(); cout<<"bptr points to Derived"<display(); bptr->show(); } /*OUTPUT bptr points to Base Display Base Show Base bptr points to Derived Display Base Show Base */ /* ******************************* TO IMPLEMENT FRIEND FUNCTIONS * ******************************* */ #include class A; class B { int b; public: B(int i) { b=i; } friend void max(A,B); }; class A { int a; public: A(int i) { a=i; } friend void max(A,B); }; void max(A m,B n) { if(m.a>=n.b) cout<>x>>y; cout<<"Max of "<