Advertisement
RupeshAcharya60

Lab 3 Simulation

Jul 14th, 2021
1,088
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.27 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6. class Chitest{
  7.     int O[10],E[10],N;
  8.     float diff[10];
  9.     float chisquare,chitab;
  10.     public:
  11.     void getdata(int n){
  12.         int temp,i;
  13.         for(i=0;i<n;i++){
  14.             cout<<"Enter frequency of "<<i<<"th value:";
  15.             cin>>O[i];
  16.         }
  17.     N=0;
  18.     for(i=0;i<n;i++){
  19.         N+=O[i];
  20.     }
  21.     temp = N/n;
  22.     for(i=0;i<n;i++){
  23.     E[i] = temp;
  24.        
  25.     }
  26.     }
  27.    
  28.     void calculatechi(int n){
  29.         int i;
  30.         cout<<"\nCalculated differences:";
  31.         for(i=0;i<n;i++){
  32.             diff[i]=(pow((O[i]-E[i]),2))/E[i];
  33.             cout<<"\n"<<diff[i];
  34.     }
  35.     chisquare=0;
  36.     for(i=0;i<n;i++){
  37.         chisquare+=diff[i];
  38.     }
  39.     }
  40.  
  41.     void decide(float chi){
  42.         cout<<"\nObtained chisquare value:"<<chisquare;
  43.         if(chitab>chisquare){
  44.             cout<<"\nAccepted :The given distributions are uniform";
  45.         }
  46.     }
  47.     };
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57. int main()
  58. {
  59.     Chitest calc;
  60.     float n,chitab;
  61.     cout<<"Enter the number of classes or values :";
  62.     cin>>n;
  63.     cout<<"Enter the Tabulated value of chi:";
  64.     cin>>chitab;
  65.     calc.getdata(n);
  66.     calc.calculatechi(n);
  67.     calc.decide(chitab);
  68.     return 0;
  69. }
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement