题目描述:
代码实现:
# include <iostream>
using 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 = %lf\n" , 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 = %lf\n" ,
normal * 1.0 / n * sum, late * 1.0 / n * sum, leave * 1.0 / n * sum, absent * 1.0 / n * sum) ;
return 0 ;
}