Posts

Showing posts from July, 2016

5th sem ADA programm to implement sorting algorithms

Bubble sort in c #include<stdio.h> void bubble(int n,int arr[]); void main() {     int n;     printf("enter the size of array:");     scanf("%d",&n);     int arr[n];     int i,j,k;     printf("enter the array elemets:\n");     for(i=0;i<n;i++)     {         scanf("%d",&arr[i]);     }     bubble(n,arr);      printf("\nyour sorted array is :\n");     for(i=0;i<n;i++)     {         printf("%d\n",arr[i]);     } } void bubble(int n, int arr[n]) {     int i,j,swap;     for(i=0;i<n;i++)     {         for(j=0;j<n-i-1;j++)         {             if(arr[j]>arr[j+1])             {                 swap=arr[j];                 arr[j]=arr[j+1];                 arr[j+1]=swap;             }         }     } }

5th sem ADA programm to implement sorting algorithms

 Insertion sort in c #include<stdio.h> void insertion(int n,int arr[]); void main() {     int n,i;     printf("enter the size of array:");     scanf("%d",&n);     int arr[n];     printf("enter the array elements:\n");     for(i=0;i<n;i++)     {         scanf("%d",&arr[i]);     }     insertion(n,arr);     printf("\nyour sorted array is:\n");     for(i=0;i<n;i++)     {         printf("%d\n",arr[i]);     } } void insertion(int n,int arr[n]) {     int i,j,swap;     for(i=1;i<n;i++)     {         j=i;         while(j>0 && arr[j] < arr[j-1])         {             swap=arr[j];             arr[j]=arr[j-1];             arr[j-1]=swap;             j--;         }     } }

4th sem OOPC Write the following programs using INHERITANCE in CPP language.

1.        To enter and display the student data using single inheritance technique. #include<iostream> #include<conio.h> using namespace std; class student{ public:     int roll_no;     char name[20];     void get(){         cout<<"\nEnter Student name: ";         cin>>name;         cout<<"Enter Student Roll No: ";         cin>>roll_no;     } }; class subject:public student{ public:     char sub1[10],sub2[10],sub3[10];         void getsub(){             cout<<"Enter first subject: ";             cin>>sub1;             cout<<"Enter Second subject: ";             cin>>sub2;             cout<<"Enter Third subject: ";             cin>>sub3;             } }; class school:public subject{     public:     void display(){             cout<<"\nRoll No: "<<roll_no<<"\nName: "<<name<<&quo

4th sem OOPC Write the following programs using OPERATOR OVERLOADING in CPP language.

1.        Write a program to enter two integers, two float number, two double numbers and find and display the greater of them using function overloading technique. #include<iostream> #include<conio.h> using namespace std; class over{     public:     int get(int,int);     float get(float,float);     double get(double,double); }; int over::get(int a,int b){         if(a>b){             return a;         }else{             return b;         } } float over::get(float a,float b){         if(a>b){             return a;         }else{             return b;         } } double over::get(double a,double b){     if(a>b){         return a;     }else{         return b;     } } int main(){     int n1,n2,t;     float x,y;     double p,q;     over obj;     //clrscr();     cout<<"\nEnter two integer number: "<<endl;     cin>>n1>>n2;     t=obj.get(n1,n2);     cout<<"Maximum number is: "<

4th sem OOPC Write the following programs using CONSTRUCTOR & DESTRUCTOR in CPP language.

1.        To enter two operands using constructor and perform arithmetic operations (+,-,*, /) on them and display the results. #include<iostream> #include<conio.h> using namespace std; class operation {     public:     int a,b;     operation(int x,int y)     {         a=x;         b=y;         cout<< a<< "+" << b <<"="<< a+b<<"\n";         cout<<a << "-"<<b<<"="<<a-b<<"\n";         cout<<a<<"*"<<b<<"="<<a*b<<"\n";         cout<<a<<"/"<<b<<"="<<a/b<<"\n";     } }; int main() {     int m,n;     cout <<"enter the values of oprands "<<endl;     cin>>m>>n;     operation(m,n);     return 0; } 2.        Write a program to generate a Fibonacci series