Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.21 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <math.h>
  4. #include <stdlib.h>
  5. using namespace std;
  6.  
  7. void printEquation(int stage);
  8.  
  9. double s1, n1, s2, n2, y_1, y_2;
  10. double A, B, C, D, numerator, leftDenominator, rightDenominator, degreesFreedom, standardError, tValue, first, second;
  11.  
  12. int main(int argc, char *argv[])
  13. {
  14.  
  15.     if (argc > 1) {
  16.         s1 = atof(argv[1]), n1 = atof(argv[2]), s2 = atof(argv[3]), n2 = atof(argv[4]), y_1 = atof(argv[5]), y_2 = atof(argv[6]);
  17.     }
  18.     else {
  19.         cout << "s1: ";
  20.         cin >> s1;
  21.  
  22.         cout << "n1: ";
  23.         cin >> n1;
  24.  
  25.         cout << "s2: ";
  26.         cin >> s2;
  27.  
  28.         cout << "n2: ";
  29.         cin >> n2;
  30.  
  31.         cout << "y1: ";
  32.         cin >> y_1;
  33.  
  34.         cout << "y2: ";
  35.         cin >> y_2;
  36.     }
  37.  
  38.     cout << "s1 = " << s1 << endl;
  39.     cout << "n1 = " << n1 << endl;
  40.     cout << "s2 = " << s2 << endl;
  41.     cout << "n2 = " << n2 << endl;
  42.  
  43.     //printEquation(0);
  44.  
  45.     A = pow(s1, 2) / n1;
  46.     B = pow(s2, 2) / n2;
  47.  
  48. //  printEquation(1);
  49.  
  50.     numerator = pow(A + B, 2);
  51.  
  52. //  printEquation(2);
  53.  
  54.     A = 1 / ( n1 -1 );
  55.     B = pow(pow(s1, 2) / n1, 2);
  56.  
  57.     C = 1 / ( n2 - 1 );
  58.     D = pow(pow(s2, 2) / n2, 2);
  59.  
  60. //  printEquation(3);
  61.  
  62.     leftDenominator = A * B;
  63.     rightDenominator = C * D;
  64.  
  65. //  printEquation(4);
  66.  
  67.     degreesFreedom = numerator / ( leftDenominator + rightDenominator );
  68.  
  69.     printf("\ndf = %.08f\n", degreesFreedom);
  70.  
  71.     standardError =  sqrt((pow(s1, 2) / n1) + (pow(s2, 2) / n2));
  72.  
  73.     printf("SE = %.08f\n\n", standardError);
  74.  
  75.     cout << "t-value: ";
  76.     cin >> tValue;
  77.  
  78.  
  79.     printf("%.04f - %.04f +- %.04f * %.04f\n", y_1, y_2, tValue, standardError);
  80.     first = y_1 - y_2;
  81.     if (first < 0)
  82.         first = abs(first);
  83.     second = tValue * standardError;
  84.     printf("%.04f +- %.08f \n", first, second);
  85.     printf("(%.04f, %.04f)\n", first - second, first + second);
  86. }
  87.  
  88. void printEquation(int stage) {
  89.     switch (stage) {
  90.     case 0:
  91.         printf("                        / %.0f^2     %.0f^2 \\ ^2\n", s1, s2);
  92.         printf("                       (  ---  +  ---  )\n");
  93.         printf("                        \\ %.0f      %.0f  /\n", n1, n2);
  94.         printf("-----------------------------------------------------------------\n");
  95.         printf(" /    1    \\       /  %.0f   \\ ^2     /    1   \\        /  %.0f  \\ ^2\n", s1, s2);
  96.         printf("(  -------  )  *  (  ----  )   +  (  -------  )  *  ( ----  )\n");
  97.         printf(" \\ %.0f - 1  /       \\  %.0f  /        \\ %.0f - 1  /       \\ %.0f  /\n\n", n1, n2, n1, n2);
  98.         break;
  99.     case 1:
  100.         printf("                        /                   \\ ^2\n");
  101.         printf("                       (  %.4f  +  %.4f  )\n", A, B);
  102.         printf("                        \\                   /\n");
  103.         printf("-----------------------------------------------------------------\n");
  104.         printf(" /    1    \\       /  %.0f   \\ ^2     /    1    \\       /  %.0f  \\ ^2\n", s1, s2);
  105.         printf("(  -------  )  *  (  ----  )   +  (  -------  )  *  ( ----  )\n");
  106.         printf(" \\ %.0f - 1  /       \\  %.0f  /        \\ %.0f - 1  /       \\ %.0f  /\n\n", n1, n2, n1, n2);
  107.         break;
  108.     case 2:
  109.         printf("                         /            \\\n");
  110.         printf("                        (  %.8f  )\n", numerator);
  111.         printf("                         \\            /\n");
  112.         printf("-----------------------------------------------------------------\n");
  113.         printf(" /    1    \\       /  %.0f^2 \\ ^2     /    1    \\       /  %.0f^2 \\ ^2\n", s1, s2);
  114.         printf("(  -------  )  *  (  ----  )   +  (  -------  )  *  (  ----  )\n");
  115.         printf(" \\ %.0f - 1  /       \\  %.0f  /        \\ %.0f - 1  /       \\  %.0f  /\n\n", n1, n2, n1, n2);
  116.         break;
  117.     case 3:
  118.         printf("                         /            \\\n");
  119.         printf("                        (  %.8f  )\n", numerator);
  120.         printf("                         \\            /\n");
  121.         printf("-----------------------------------------------------------------\n");
  122.         printf("(  %.4f  )  *  (  %.4f  )   +  (  %.4f  )  *  (  %.4f  )\n\n", A, B, C, D);
  123.         break;
  124.     case 4:
  125.         printf("                         /            \\\n");
  126.         printf("                        (  %.8f  )\n", numerator);
  127.         printf("                         \\            /\n");
  128.         printf("-----------------------------------------------------------------\n");
  129.         printf("             (  %.8f  )   +  (  %.8f  )\n\n", leftDenominator, rightDenominator);
  130.         break;
  131.     case 5:
  132.         break;
  133.     }
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement