Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- class chisquare
- {
- private:
- int n, observed[20],i,N,Expected;
- float Calculation[20],final,critical;
- public:
- chisquare() //constructor to initialize values
- {
- N=0;
- final=0.00;
- }
- void getdata() //getting observed frequency
- {
- cout<<"How many numbers:?"<<endl;
- cin>>n;
- cout<<"Enter the observed frequency:"<<endl;
- for(i=0;i<n;i++)
- {
- cout<<"Enter "<<i+1<<"th number: "<<endl;
- cin>>observed[i];
- }
- }
- void calculation() //calculation of N(total frequency), Calculation(((Oi-Ei)^2/Ei)),final(?)
- {
- for(i=0;i<n;i++)
- {
- N=N+observed[i];
- }
- Expected=N/n;
- for(i=0;i<n;i++)
- {
- Calculation[i]=(float)((observed[i]-Expected)*(observed[i]-Expected))/Expected;
- final=final+Calculation[i];
- }
- }
- void display() //display in tabulated format
- {
- cout<<"S.No"<<"\t";
- cout<<"Oi"<<"\t";
- cout<<"Ei"<<"\t";
- cout<<"((Oi-Ei)*(Oi-Ei))/Ei"<<endl;
- for(i=0;i<n;i++)
- {
- cout<<i+1<<"\t";
- cout<<observed[i]<<"\t";
- cout<<Expected<<"\t";
- cout<<Calculation[i]<<endl;
- }
- cout<<"-------------------------------------------------------"<<endl;
- cout<<"Total sum of Oi:"<<N;
- cout<<"calculation is: "<<final;
- cout<<endl;
- }
- void conclusion() //compare tabulated and calculated value and conclude if Ho is accepted.
- {
- cout<<endl;
- cout<<"Enter the critical value:"<<endl;
- cin>>critical;
- if(final<critical)
- {
- cout<<"The test is accepted"<<endl;
- }
- else
- {
- cout<<"The test is rejected"<<endl;
- }
- }
- };
- int main()
- {
- chisquare c;
- c.getdata();
- c.calculation();
- c.display();
- c.conclusion();
- return(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement