Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #include <math.h>
- #include <stdlib.h>
- using namespace std;
- void printEquation(int stage);
- double s1, n1, s2, n2, y_1, y_2;
- double A, B, C, D, numerator, leftDenominator, rightDenominator, degreesFreedom, standardError, tValue, first, second;
- int main(int argc, char *argv[])
- {
- if (argc > 1) {
- 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]);
- }
- else {
- cout << "s1: ";
- cin >> s1;
- cout << "n1: ";
- cin >> n1;
- cout << "s2: ";
- cin >> s2;
- cout << "n2: ";
- cin >> n2;
- cout << "y1: ";
- cin >> y_1;
- cout << "y2: ";
- cin >> y_2;
- }
- cout << "s1 = " << s1 << endl;
- cout << "n1 = " << n1 << endl;
- cout << "s2 = " << s2 << endl;
- cout << "n2 = " << n2 << endl;
- //printEquation(0);
- A = pow(s1, 2) / n1;
- B = pow(s2, 2) / n2;
- // printEquation(1);
- numerator = pow(A + B, 2);
- // printEquation(2);
- A = 1 / ( n1 -1 );
- B = pow(pow(s1, 2) / n1, 2);
- C = 1 / ( n2 - 1 );
- D = pow(pow(s2, 2) / n2, 2);
- // printEquation(3);
- leftDenominator = A * B;
- rightDenominator = C * D;
- // printEquation(4);
- degreesFreedom = numerator / ( leftDenominator + rightDenominator );
- printf("\ndf = %.08f\n", degreesFreedom);
- standardError = sqrt((pow(s1, 2) / n1) + (pow(s2, 2) / n2));
- printf("SE = %.08f\n\n", standardError);
- cout << "t-value: ";
- cin >> tValue;
- printf("%.04f - %.04f +- %.04f * %.04f\n", y_1, y_2, tValue, standardError);
- first = y_1 - y_2;
- if (first < 0)
- first = abs(first);
- second = tValue * standardError;
- printf("%.04f +- %.08f \n", first, second);
- printf("(%.04f, %.04f)\n", first - second, first + second);
- }
- void printEquation(int stage) {
- switch (stage) {
- case 0:
- printf(" / %.0f^2 %.0f^2 \\ ^2\n", s1, s2);
- printf(" ( --- + --- )\n");
- printf(" \\ %.0f %.0f /\n", n1, n2);
- printf("-----------------------------------------------------------------\n");
- printf(" / 1 \\ / %.0f \\ ^2 / 1 \\ / %.0f \\ ^2\n", s1, s2);
- printf("( ------- ) * ( ---- ) + ( ------- ) * ( ---- )\n");
- printf(" \\ %.0f - 1 / \\ %.0f / \\ %.0f - 1 / \\ %.0f /\n\n", n1, n2, n1, n2);
- break;
- case 1:
- printf(" / \\ ^2\n");
- printf(" ( %.4f + %.4f )\n", A, B);
- printf(" \\ /\n");
- printf("-----------------------------------------------------------------\n");
- printf(" / 1 \\ / %.0f \\ ^2 / 1 \\ / %.0f \\ ^2\n", s1, s2);
- printf("( ------- ) * ( ---- ) + ( ------- ) * ( ---- )\n");
- printf(" \\ %.0f - 1 / \\ %.0f / \\ %.0f - 1 / \\ %.0f /\n\n", n1, n2, n1, n2);
- break;
- case 2:
- printf(" / \\\n");
- printf(" ( %.8f )\n", numerator);
- printf(" \\ /\n");
- printf("-----------------------------------------------------------------\n");
- printf(" / 1 \\ / %.0f^2 \\ ^2 / 1 \\ / %.0f^2 \\ ^2\n", s1, s2);
- printf("( ------- ) * ( ---- ) + ( ------- ) * ( ---- )\n");
- printf(" \\ %.0f - 1 / \\ %.0f / \\ %.0f - 1 / \\ %.0f /\n\n", n1, n2, n1, n2);
- break;
- case 3:
- printf(" / \\\n");
- printf(" ( %.8f )\n", numerator);
- printf(" \\ /\n");
- printf("-----------------------------------------------------------------\n");
- printf("( %.4f ) * ( %.4f ) + ( %.4f ) * ( %.4f )\n\n", A, B, C, D);
- break;
- case 4:
- printf(" / \\\n");
- printf(" ( %.8f )\n", numerator);
- printf(" \\ /\n");
- printf("-----------------------------------------------------------------\n");
- printf(" ( %.8f ) + ( %.8f )\n\n", leftDenominator, rightDenominator);
- break;
- case 5:
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement