Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- class Chitest{
- int O[10],E[10],N;
- float diff[10];
- float chisquare,chitab;
- public:
- void getdata(int n){
- int temp,i;
- for(i=0;i<n;i++){
- cout<<"Enter frequency of "<<i<<"th value:";
- cin>>O[i];
- }
- N=0;
- for(i=0;i<n;i++){
- N+=O[i];
- }
- temp = N/n;
- for(i=0;i<n;i++){
- E[i] = temp;
- }
- }
- void calculatechi(int n){
- int i;
- cout<<"\nCalculated differences:";
- for(i=0;i<n;i++){
- diff[i]=(pow((O[i]-E[i]),2))/E[i];
- cout<<"\n"<<diff[i];
- }
- chisquare=0;
- for(i=0;i<n;i++){
- chisquare+=diff[i];
- }
- }
- void decide(float chi){
- cout<<"\nObtained chisquare value:"<<chisquare;
- if(chitab>chisquare){
- cout<<"\nAccepted :The given distributions are uniform";
- }
- }
- };
- int main()
- {
- Chitest calc;
- float n,chitab;
- cout<<"Enter the number of classes or values :";
- cin>>n;
- cout<<"Enter the Tabulated value of chi:";
- cin>>chitab;
- calc.getdata(n);
- calc.calculatechi(n);
- calc.decide(chitab);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement