Advertisement
Sajib_Ahmed

Statistics project

Aug 17th, 2019
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.69 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. void mergesort(int a[],int i,int j);
  4. void merge(int a[],int i1,int j1,int i2,int j2);
  5. void Boxplot();
  6. int binary_search(int a[],int n);
  7. int linear_search(int a[],int n);
  8. int main()
  9. {
  10.     int press;
  11.     cout<<"For find Box plot or out liner data press 1"<<endl;
  12.     cin>>press;
  13.     if(press==1)
  14.     {
  15.         Boxplot();
  16.  
  17.     }
  18. }
  19.  
  20. void Boxplot()
  21. {
  22.     cout<<"Input Arry size"<<endl;
  23.     int size1;
  24.     cin>>size1;
  25.     int A[size1];
  26.     cout<<"Input Number"<<endl;
  27.     for(int i=1; i<=size1; i++)
  28.     {
  29.         cin>>A[i];
  30.     }
  31.     mergesort(A,1,size1);
  32.  
  33.     int Q1,Q2,Q3,miden;
  34.     if(size1%2!=0)
  35.     {
  36.         Q2=((0+size1)/2)+1;
  37.         miden=A[Q2];
  38.         int half=(0+(Q2-1))/2;
  39.         Q1=(A[half]+A[half+1])/2;
  40.         int half2=((Q2+1)+size1)/2;
  41.         Q3=(A[half2]+A[half2+1])/2;
  42.     }
  43.     else
  44.     {
  45.         int half=(0+size1)/2;
  46.         Q2=(A[half]+A[half+1])/2;
  47.         miden=Q2;
  48.         int half1=(0+half)/2;
  49.  
  50.         Q1=A[half1];
  51.  
  52.         int half2=((half+2)+size1)/2;
  53.  
  54.         Q3=A[half2];
  55.  
  56.     }
  57.     int low=binary_search(A,size1);
  58.     int high=linear_search(A,size1);
  59.     int IQR=(Q3-Q1);
  60.     int LVT=(Q1-(1.5*IQR));
  61.     int HVT=(Q3+(1.5*IQR));
  62.  
  63.     cout<<"Q1="<<Q1<<"\n"<<"Q2="<<miden<<"\n"<<"Q3="<<Q3<<endl;
  64.     cout<<"Low value is="<<low<<endl;
  65.     cout<<"LVT is="<<LVT<<endl;
  66.     cout<<"High Value is="<<high<<endl;
  67.     cout<<"HVT="<<HVT<<endl;
  68.  
  69. }
  70.  
  71. void mergesort(int a[],int i,int j)
  72. {
  73.     int mid;
  74.     if(i<j)
  75.     {
  76.         mid=(i+j)/2;
  77.         mergesort(a,i,mid);
  78.         mergesort(a,mid+1,j);
  79.         merge(a,i,mid,mid+1,j);
  80.  
  81.     }
  82. }
  83. void merge(int a[],int i1,int j1,int i2,int j2)
  84. {
  85.     int temp[50];
  86.     int i,j,k;
  87.     i=i1;
  88.     j=i2;
  89.     k=0;
  90.     while(i<=j1&&j<=j2)
  91.     {
  92.         if(a[i]<a[j])
  93.         {
  94.             temp[k++]=a[i++];
  95.         }
  96.         else
  97.         {
  98.             temp[k++]=a[j++];
  99.         }
  100.     }
  101.     while(i<=j1)
  102.     {
  103.         temp[k++]=a[i++];
  104.     }
  105.     while(j<=j2)
  106.     {
  107.         temp[k++]=a[j++];
  108.     }
  109.     for(i=i1,j=0; i<=j2; i++,j++)
  110.     {
  111.         a[i]=temp[j];
  112.     }
  113. }
  114. int binary_search(int a[],int n)
  115. {
  116.     int low=1,high=n,mid;
  117.     int k=1;
  118.     mid=(low+high)/2;
  119.     while(low<=high)
  120.     {
  121.         if(k==mid)
  122.         {
  123.             k=a[mid];
  124.             return k;
  125.         }
  126.         else if(k>a[mid])
  127.         {
  128.             low=mid+1;
  129.  
  130.         }
  131.         else
  132.         {
  133.             high=mid-1;
  134.         }
  135.         mid=(low+high)/2;
  136.     }
  137. }
  138. int linear_search(int a[],int n)
  139. {
  140.     int max1=0;
  141.     for(int i=1; i<=n; i++)
  142.     {
  143.         if(a[i]>max1)
  144.         {
  145.             max1=a[i];
  146.         }
  147.  
  148.     }
  149.     return max1;
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement