Question: Visual Studio C++ OOP how do you find mean and standard deviation of Book1.txt, (Book1.txt consists of student names,scores and seat number) please complete the
Visual Studio C++ OOP how do you find mean and standard deviation of Book1.txt, (Book1.txt consists of student names,scores and seat number) please complete the program and check if there is anything wrrong, I am currently learning OOP and really need some help. Thank You
#include
class ABC { //member variable(data): int a, b, c; DATA ab; //member function: { //... } }Abc[4]; #define MAX 100 struct DATA { char Name[10]; int Score[4]; int Total; float Average; int ID; int Rank; }; DATA Data[MAX];
void Print_Out(DATA* lp, int N) { for (int i = 0; i < N; i++) { printf("%s %2d %2d %2d %2d =%3d =%2d =%2d ", lp->Name, lp->Score[0], lp->Score[1], lp->Score[2], lp->Score[3], lp->Total, lp->ID, lp->Rank); lp++; //lp+=1; //lp=lp+1; } }
void Sorting(DATA* lp, int N) { DATA Tmp, * pi, * pj; int i, j, L = sizeof(DATA); //bubblesort for (i = 0; i < N - 1; i++) { pi = &Data[i]; for (j = i + 1; j < N; j++) { pj = &Data[j]; if (pi->Total < pj->Total) { memcpy(&Tmp, pi, L); memcpy(pi, pj, L); memcpy(pj, &Tmp, L); } } pi->Rank = i + 1; } lp[N - 1].Rank = N; } void Estimate(DATA* lp, int No, float* Mean, float* Std_Dev) { }
int main() { errno_t err; FILE* In; int No = 0; DATA* lp; if ((err = fopen_s(&In, "Book1.txt", "rb")) != 0) { printf("Book1.txt error "); return -1; } while (!feof(In)) { lp = &Data[No]; fscanf_s(In, "%s %d %d %d ", lp->Name, 10, lp->Score + 1, lp->Score + 2, lp->Score + 3); //Data[No].Name, 10 //& Data[No].Score[0], //lp->Score + 1, //Data[No].Score + 2, //Data[No].Score + 3); lp->Total = *lp->Score + *(lp->Score + 1) + *(lp->Score + 2) + *(lp->Score + 3);//total lp->Average = (float)lp->Total / 4;//average lp->ID = No + 1; //seat number No++;
} //arrange in sequence Sorting(Data, No); //print Print_Out(Data, No); //homework,mean and standard deviation float Mean[4], Std_Dev[4]; Estimate(Data, No, Mean, Std_Dev); for (int i = 0; i < 4, i++) printf(" % mean[% d] = % f Std_Dev[% d] = % f ", i, Mean[i], i, Std_Dev[i]);
}
Book1.txt file look like this x 70 85 78 82 1 F 65 78 99 84 2 85 99 80 85 3 df{ 95 80 99 80 4 w 83 93 78 82 5 L 95 90 99 84 6 H 93 93 80 85 7 84 82 99 80 8 95 92 99 80 9 iR 93 83 99 80 10 R 93 83 78 82 11 82 85 99 84 12 84 90 80 85 13 y 85 70 99 80 14 LM 90 65 95 92 15 90 85 93 83 16 \ 94 95 93 83 17 90 83 82 85 18 aR 88 95 84 90 19 i 90 93 99 80 20 v 88 84 78 82 21 Bs 92 95 99 84 22 f 84 93 80 85 23 @ 85 93 95 92 24 K 78 82 93 83 25 99 84 93 83 26 cN 80 85 82 85 27 L 93 90 84 90 28 PHw 90 90 78 82 29 B 93 94 99 84 30 hp 82 90 80 85 31 Gg 92 88 95 92 32 W 83 90 93 83 33 }P 83 88 93 83 34 aa 85 92 82 85 35 90 84 84 90 36
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
