#includeusing namespace std; enum STATUS { NORMAL = 0, // 正常 LATE = 1, // 迟到 LEAVE = 2, // 请假 ABSENT = 3 // 旷课 }; struct Student { int id; int course[4]; int sum; }; const int N = 110; Student arr[N]; int main() { int n, sum; cout << "please input the number of student:"; cin >> n; cout << "please input the number of course:"; cin >> sum; for (int i = 0; i < n; i++) { cout << "please input the student's id:"; cin >> arr[i].id; cout << "please input the student's course status:"; int status; cin >> status; arr[i].course[status]++; arr[i].sum = sum; } // 每个人的出勤情况 for (int i = 0; i < n; i++) { double normal_rate = 1.0 * (arr[i].course[0]) / arr[i].sum; double late_rate = 1.0 * (arr[i].course[1]) / arr[i].sum; double leave_rate = 1.0 * (arr[i].course[2]) / arr[i].sum; double absent_rate = 1.0 * (arr[i].course[3]) / arr[i].sum; printf("id = %d, normal_rate = %lf, late_rate = %lf, leave_rate = %lf, absent_rate = %lfn", arr[i].id, normal_rate, late_rate, leave_rate, absent_rate); } int normal = 0; int late = 0; int leave = 0; int absent = 0; for (int i = 0; i < n; i++) { normal += arr[i].course[0]; late += arr[i].course[1]; leave += arr[i].course[2]; absent += arr[i].course[3]; } // 课程的情况 printf("course : normal_rate = %lf, late_rate = %lf, leave_rate = %lf, absent_rate = %lfn", normal * 1.0 / n * sum, late * 1.0 / n * sum, leave * 1.0 / n * sum, absent * 1.0 / n * sum); return 0; }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)