Advertisement
Guest User

addadad

a guest
Aug 18th, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.20 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #include<stdio.h>
  3. #include<conio.h>
  4. using namespace std;
  5. void mergesort(int a[],int i,int j);
  6. void merge(int a[],int i1,int j1,int i2,int j2);
  7. void Boxplot();
  8. int Decile();
  9. int binary_search(int a[],int n);
  10. int linear_search(int a[],int n);
  11. void FrequencyDistribution();
  12. int Median();
  13. int partition(int a[],int low,int high);
  14. void quicksort(int a[],int low,int high);
  15. void printArray(int a[], int n);
  16.  
  17. int main()
  18. {
  19. int choise,quite;
  20. cout<<"\n\n\t\t ======WELCOME TO STATISTICS CALCULATOR======\n";
  21. cout<<"\n\n\t\t\t*********************************\n\t\t\t*\t\t\t\t*\n\t\t\t*\t Main Menu \t*\n\t\t\t*\t\t\t\t*\n\t\t\t*********************************\n\t\t\t*\t\t\t\t*";
  22. cout<<"\n\t\t\t*\t [1]Median\t\t*\n";
  23. cout<<"\t\t\t*\t [2]Frequency\t\t*\n";
  24. cout<<"\t\t\t*\t [3]Boxplot\t\t*\n";
  25. cout<<"\t\t\t*\t [4]Decile\t\t*\n";
  26. cout<<"\t\t\t*\t [5]About Us\t\t*\n";
  27. cout<<"\t\t\t*\t [0]Exit\t\t*\n\t\t\t*\t\t\t\t*\n";
  28. cout<<"\t\t\t*********************************\n\n";
  29. cout<<"\t\t\t\tChoise Any Number: ";
  30. cin>>choise;
  31.  
  32. switch(choise)
  33. {
  34.  
  35. case 0:
  36. system("CLS");
  37. cout<<"\n\n\n\t\t\t*********************************\n\t\t\t*\t Are you sure?\t*\n\t\t\t*********************************\n\t\t\t*\t[1]YES *\t[2]NO *\n\t\t\t*********************************";
  38. cout<<"\n\n\t\t\tChoise Any Number: ";
  39. cin>>quite;
  40. if(quite==1)
  41. {
  42. system("CLS");
  43. cout<<"\n\n\n\n\n\n\t\t\t*********Thanks For Using*********\n\n\n\n\n\n\n\n\n\n\n";
  44. break;
  45. }
  46. else if(quite==2)
  47. {
  48.  
  49. system("CLS");
  50. main(); // call main function
  51. }
  52. else
  53. {
  54. cout<<"\n\n\t\t\tInvalid....\n\n ";
  55. getch();
  56. system("CLS");
  57. main(); //if invalid go to main menu
  58.  
  59.  
  60. }
  61. break;
  62. case 1:
  63. system("CLS");
  64.  
  65. Median();
  66. cout<<"\n\t\t\t===========================================================";
  67. cout<<"\n\t\t\t\t\t(Press [1]exit or [2]menu)";
  68. cout<<"\n\n\t\t\t\t\tChoise Any Number: ";
  69. cin>>quite;
  70. if(quite==1)
  71. {
  72. system("CLS");
  73. cout<<"\n\n\n\n\n\n\t\t\t*********Thanks For Using*********\n\n\n\n\n\n\n\n\n\n\n";
  74. break;
  75. }
  76. else if(quite==2)
  77. {
  78.  
  79. system("CLS");
  80. main(); // call main function
  81. }
  82. else
  83. {
  84. cout<<"\n\n\t\t\tPlease Enter Valid Option....\n\n ";
  85. getch();
  86. system("CLS");
  87. main();
  88. }
  89.  
  90. break;
  91. case 2:
  92. system("CLS");
  93. FrequencyDistribution();
  94. cout<<"\n\t\t\t\t\t(Press [1]exit or [2]menu)";
  95. cout<<"\n\n\t\t\t\t\tChoise Any Number: ";
  96. cin>>quite;
  97. if(quite==1)
  98. {
  99. system("CLS");
  100. cout<<"\n\n\n\n\n\n\t\t\t*********Thanks For Using*********\n\n\n\n\n\n\n\n\n\n\n";
  101. break;
  102. }
  103. else if(quite==2)
  104. {
  105.  
  106. system("CLS");
  107. main(); // call main function
  108. }
  109. else
  110. {
  111. cout<<"\n\n\t\t\tPlease Enter Valid Option....\n\n ";
  112. getch();
  113. system("CLS");
  114. main();
  115. }
  116. break;
  117. case 3:
  118. system("CLS");
  119. Boxplot();
  120. cout<<"\n\t\t\t\t\t(Press [1]exit or [2]menu)";
  121. cout<<"\n\n\t\t\t\t\tChoise Any Number: ";
  122. cin>>quite;
  123. if(quite==1)
  124. {
  125. system("CLS");
  126. cout<<"\n\n\n\n\n\n\t\t\t*********Thanks For Using*********\n\n\n\n\n\n\n\n\n\n\n";
  127. break;
  128. }
  129. else if(quite==2)
  130. {
  131.  
  132. system("CLS");
  133. main(); // call main function
  134. }
  135. else
  136. {
  137. cout<<"\n\n\t\t\tPlease Enter Valid Option....\n\n ";
  138. getch();
  139. system("CLS");
  140. main();
  141. }
  142. break;
  143. case 4:
  144. system("CLS");
  145. Decile();
  146. cout<<"\n\t\t\t\t\t(Press [1]exit or [2]menu)";
  147. cout<<"\n\n\t\t\t\t\tChoise Any Number: ";
  148. cin>>quite;
  149. if(quite==1)
  150. {
  151. system("CLS");
  152. cout<<"\n\n\n\n\n\n\t\t\t*********Thanks For Using*********\n\n\n\n\n\n\n\n\n\n\n";
  153. break;
  154. }
  155. else if(quite==2)
  156. {
  157.  
  158. system("CLS");
  159. main(); // call main function
  160. }
  161. else
  162. {
  163. cout<<"\n\n\t\t\tPlease Enter Valid Option....\n\n ";
  164. getch();
  165. system("CLS");
  166. main();
  167. }
  168. break;
  169. case 5:
  170.  
  171. system("CLS");
  172. cout<<"\n\n\t\tINFORMATION ABOUT GROUP 404_NOT_FOUND\n\t===========================================================";
  173. cout<<"\n\t\tName:Md.Mahedi Hasan\n\t\tID:181-15-10900\n\t\tSECTION:D\n";
  174. cout<<"\n\t\tName:Sajib Ahmed\n\t\tID:181-15-10874\n\t\tSECTION:D\n";
  175. cout<<"\n\t\tName:Mohd.Mehedi Hasan Joy\n\t\tID:181-15-10632\n\t\tSECTION:D\n";
  176. cout<<"\n\t\tName:Akkhar Ulok\n\t\tID:181-15-11207\n\t\tSECTION:D\n";
  177. cout<<"\n\t\tName:Md. Anamul Kabir\n\t\tID:181-15-10714\n\t\tSECTION:D";
  178. cout<<"\n\n\t\t\tThis is an C++ project\n\t===========================================================";
  179. cout<<"\n\t\t\tPress any key to continue....";
  180. getch();
  181. system("CLS");
  182. main();
  183. break;
  184. default:
  185.  
  186. cout<<"\n\t\t\tPlease Enter Valid Option....";
  187. cout<<"\n\t\t\tPress any key to continue....";
  188. getch();
  189. system("CLS");
  190. main();
  191. break;
  192. }
  193.  
  194.  
  195. return 0;
  196. }
  197.  
  198.  
  199. //==============================IMPLEMENT PARTITION==============================
  200. int partition(int a[],int low,int high)
  201. {
  202. int pivot=a[high];
  203. int i=low-1;
  204. for(int j=low; j<=high-1; j++)
  205. {
  206. if(a[j]<=pivot)
  207. {
  208. i++;
  209. swap(a[i],a[j]);
  210. }
  211. }
  212. swap(a[i+1],a[high]);
  213. return (i+1);
  214. }
  215. //==============================IMPLEMENT QUICKSORT==============================
  216. void quicksort(int a[],int low,int high)
  217. {
  218. if(low<high)
  219. {
  220. int p=partition(a,low,high);
  221.  
  222. quicksort(a,low, p- 1);
  223. quicksort(a, p + 1, high);
  224. }
  225. }
  226. //==============================DISPLAY==============================
  227. void printArray(int a[], int n)
  228. {
  229. int i;
  230. cout<<"\t\t\t\t"<<n<<" times of sorted data: ";
  231. for (i=1; i <=n; i++)
  232. {
  233. cout<<a[i]<<" ";
  234. }
  235. cout<<endl;
  236.  
  237. }
  238. //==============================MAIN FUNCTION==============================
  239. int Median()
  240. {
  241. int n;
  242. cout<<"\n\n\n\t\t\t\tEnter the size of data: ";
  243. cin>>n;
  244. int a[n];
  245. cout<<"\t\t\t\t"<<n<<" times of data: ";
  246. for(int i=1; i<=n; i++)
  247. {
  248. cin>>a[i];
  249. }
  250. quicksort(a,1,n);
  251. printArray(a, n);
  252.  
  253. //==============================IMPLEMENT MEDIAN==============================
  254. if(n%2==0)
  255. {
  256. double v=n;
  257. int M=(v/2);
  258. int k=(v/2)+1;
  259. double md=((double)a[M]+(double)a[k])/2;
  260. cout<<"\t\t\t\tMedian: ";
  261. cout<<md;
  262.  
  263. }
  264. if(n%2!=0)
  265. {
  266. double v=n;
  267. int M=(v+1)/2;
  268. cout<<"\t\t\t\tMedian: ";
  269. cout<<(double)a[M];
  270.  
  271. }
  272.  
  273.  
  274. }
  275.  
  276.  
  277.  
  278. void FrequencyDistribution()
  279. {
  280. int n,mx=INT_MIN;
  281. cout<<"Enter the number of values : ";
  282. cin>>n;
  283. int a[n];
  284. for(int i=0; i<n; i++)
  285. {
  286. cin>>a[i];
  287. mx=max(mx,a[i]);
  288. }
  289.  
  290. ////////Sorting Part(Counting Sort)////////
  291. int aux[mx];
  292. vector<int> b;
  293. for(int i=0; i<=mx; i++)
  294. aux[i]=0;
  295. for(int i=0 ; i<n; i++)
  296. aux[a[i]]++;
  297. for(int i=0; i<=mx; i++)
  298. {
  299. if(aux[i]!=0)
  300. {
  301. while(aux[i]--)
  302. {
  303. b.push_back(i);
  304. }
  305. }
  306. }
  307. //////////////SORTING PART END//////////////
  308.  
  309. ///////////////Initial Var////////////////////////
  310. double numofcls=log(n)/log(2);
  311. numofcls=ceil(numofcls);
  312. double clsitvl=(b[b.size()-1]-b[0])/numofcls;
  313. clsitvl=ceil(clsitvl);
  314. int lowerlim[(int)numofcls],upperlim[(int)numofcls],frq[(int)numofcls]= {0};
  315. lowerlim[0]=b[0];
  316. upperlim[0]=b[0]+(clsitvl-1);
  317. for(int i=1; i<numofcls; i++)
  318. {
  319. lowerlim[i]=lowerlim[i-1]+clsitvl;
  320. upperlim[i]=upperlim[i-1]+clsitvl;
  321. }
  322. ////////////////Intial End//////////////////////////
  323.  
  324. ///////////////Main Alogrithm///////////////////////
  325. for(int i=0; i<numofcls; i++)
  326. {
  327. for(int j=0; j<b.size(); j++)
  328. {
  329. if(b[j]>=lowerlim[i] && b[j]<=upperlim[i])
  330. frq[i]++;
  331. }
  332. }
  333. cout<<"Class Interval"<<"-------->"<<"Frequency\n";
  334. for(int i=0; i<numofcls; i++)
  335. {
  336. cout<<lowerlim[i]<<" - "<<upperlim[i];
  337. cout<<"--------------->"<<frq[i]<<"\n";
  338. }
  339. /////////////////Main Algorithm End//////////////////
  340.  
  341. }
  342.  
  343.  
  344.  
  345. void Boxplot()
  346. {
  347. cout<<"Input Arry size"<<endl;
  348. int size1;
  349. cin>>size1;
  350. int A[size1];
  351. cout<<"Input Number"<<endl;
  352. for(int i=1; i<=size1; i++)
  353. {
  354. cin>>A[i];
  355. }
  356. mergesort(A,1,size1);
  357.  
  358. int Q1,Q2,Q3,miden;
  359. if(size1%2!=0)
  360. {
  361. Q2=((0+size1)/2)+1;
  362. miden=A[Q2];
  363. int half=(0+(Q2-1))/2;
  364. Q1=(A[half]+A[half+1])/2;
  365. int half2=((Q2+1)+size1)/2;
  366. Q3=(A[half2]+A[half2+1])/2;
  367. }
  368. else
  369. {
  370. int half=(0+size1)/2;
  371. Q2=(A[half]+A[half+1])/2;
  372. miden=Q2;
  373. int half1=(0+half)/2;
  374.  
  375. Q1=A[half1];
  376.  
  377. int half2=((half+2)+size1)/2;
  378.  
  379. Q3=A[half2];
  380.  
  381. }
  382. int low=binary_search(A,size1);
  383. int high=linear_search(A,size1);
  384. int IQR=(Q3-Q1);
  385. int LVT=(Q1-(1.5*IQR));
  386. int HVT=(Q3+(1.5*IQR));
  387.  
  388. cout<<"Q1="<<Q1<<"\n"<<"Q2="<<miden<<"\n"<<"Q3="<<Q3<<endl;
  389. cout<<"Low value is="<<low<<endl;
  390. cout<<"LVT is="<<LVT<<endl;
  391. cout<<"High Value is="<<high<<endl;
  392. cout<<"HVT="<<HVT<<endl;
  393.  
  394. }
  395.  
  396. void mergesort(int a[],int i,int j)
  397. {
  398. int mid;
  399. if(i<j)
  400. {
  401. mid=(i+j)/2;
  402. mergesort(a,i,mid);
  403. mergesort(a,mid+1,j);
  404. merge(a,i,mid,mid+1,j);
  405.  
  406. }
  407. }
  408. void merge(int a[],int i1,int j1,int i2,int j2)
  409. {
  410. int temp[50];
  411. int i,j,k;
  412. i=i1;
  413. j=i2;
  414. k=0;
  415. while(i<=j1&&j<=j2)
  416. {
  417. if(a[i]<a[j])
  418. {
  419. temp[k++]=a[i++];
  420. }
  421. else
  422. {
  423. temp[k++]=a[j++];
  424. }
  425. }
  426. while(i<=j1)
  427. {
  428. temp[k++]=a[i++];
  429. }
  430. while(j<=j2)
  431. {
  432. temp[k++]=a[j++];
  433. }
  434. for(i=i1,j=0; i<=j2; i++,j++)
  435. {
  436. a[i]=temp[j];
  437. }
  438. }
  439. int binary_search(int a[],int n)
  440. {
  441. int low=1,high=n,mid;
  442. int k=1;
  443. mid=(low+high)/2;
  444. while(low<=high)
  445. {
  446. if(k==mid)
  447. {
  448. k=a[mid];
  449. return k;
  450. }
  451. else if(k>a[mid])
  452. {
  453. low=mid+1;
  454.  
  455. }
  456. else
  457. {
  458. high=mid-1;
  459. }
  460. mid=(low+high)/2;
  461. }
  462. }
  463. int linear_search(int a[],int n)
  464. {
  465. int max1=0;
  466. for(int i=1; i<=n; i++)
  467. {
  468. if(a[i]>max1)
  469. {
  470. max1=a[i];
  471. }
  472.  
  473. }
  474. return max1;
  475. }
  476.  
  477.  
  478.  
  479.  
  480. int n,i,p,l;
  481. void inseartion_sort(int a[],int n)
  482. {
  483. for(i=1; i<n; i++)
  484. {
  485. p=a[i];
  486. l=i-1;
  487. while(l>-1&&a[l]>p)
  488. {
  489. a[l+1]=a[l];
  490. l--;
  491. }
  492. a[l+1]=p;
  493.  
  494. }
  495.  
  496. }
  497. void print(int a[],int n)
  498. { cout<<"sorted Arry "<<endl;
  499. for(i=0; i<n; i++)
  500. {
  501. cout<<a[i]<<" ";
  502. }
  503. cout<<endl;
  504. }
  505. int Decile()
  506. {
  507. int n,i,p,l;
  508. cout<<"Input Arry size"<<endl;
  509. cin>>n;
  510. int a[n];
  511. for(i=0; i<n; i++)
  512. {
  513. cin>>a[i];
  514. }
  515. inseartion_sort(a,n);
  516. print(a,n);
  517.  
  518. double q,v=n;
  519. q=(2*v/10);
  520.  
  521. int x=q;
  522. double w=q-x;
  523.  
  524. double ab=a[x]-a[x-1];
  525. cout<<"Decile: ";
  526. double qr=a[x-1]+w*(ab);
  527. cout<<qr<<endl;
  528. return 0;
  529. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement