score

 1 #include<iostream>
 2 using namespace std;
 3 class student{
 4 public:
 5     int Input()
 6     {
 7         for(i=0;i<5;i++)
 8         {
 9             cout<<"Please Input "<<i+1<<" Student's Number And Scores:"<<endl;
10             cin>>number[i];
11             for(j=0;j<5;j++)
12                 cin>>score[i][j];
13         }
14         return 0;
15     }
16 
17     int calculateall()
18     {
19         for(i=0;i<5;i++)
20         {
21             ave[i]=0;
22             for(j=0;j<5;j++)
23                 ave[i]=ave[i]+score[i][j];
24             ave[i]=ave[i]/5.0;
25         }
26         
27         return 0;
28     }
29     int calculateone(int n)
30     {
31         average=0;
32         for(i=0;i<5;i++)
33             average+=score[i][n];
34         return average/5.0;
35     }
36     int Output()
37     {
38         calculateall();
39         for(i=0;i<5;i++)
40         {
41             cout<<"The number is "<<number[i]<<endl;
42             for(j=0;j<6;j++)
43                 cout<<score[i][j]<<" ";
44             cout<<endl;
45             cout<<"The average is "<<ave[i]<<endl;
46         }
47         return 0;
48     }
49 private:
50     char number[5][10];
51     double score[5][5];
52     double ave[5];
53     double average;
54     int i;
55     int j;
56 };
57 
58 int main()
59 {
60     int n;
61     class student stu1;
62     stu1.Input();
63     stu1.Output();
64     cout<<"Please input the number of the class which you want calculate(0,1,2,3,4):"<<endl;
65     cin>>n;
66     cout<<"The class's average is: "<<stu1.calculateone(n)<<endl;
67     return 0;
68 }

posted on 2013-12-26 16:37  了发发  阅读(216)  评论(0)    收藏  举报

导航