刚学C 写得程序咋运行不正确?谢谢
/*----------------------------------name:CHENG HAN
Data:11-10-27
Function:班级课程成绩计算(计算5个学生的平均成绩和每门课的平均成绩)
----------------------------------*/
#include<iostream>
using namespace std;
int num[5]={1,2,3,4,5};
int sco[5][5]={{50,60,70,80,90},{60,50,70,55,60},{58,60,79,80,98},{85,65,45,98,76},{80,60,65,75,65}};
float avsco[5];
class grade{ //定义一个名为“grade”的类
public :
void averscore(int sco[5][5],float avsco[5]) //定义一个函数用来计算每个学生的平均成绩
{
int i,j,s;
for(i=0;i<5;i++)
s=0;
for(j=0;j<5;j++)
{s=s+sco[i][j];
if(j==4) avsco[i]=s/5.0;
}
}
void avercourse(int (*psco)[5],int n) //定义一个函数计算每门课的平均成绩
{ int i,j,s;
for(j=0;j<5;j++)
s=0;
for(i=0;i<5;i++)
{ s=s+sco[i][j];
if(i==4) *psco[j]=s/5;}
switch(n)
{case 1: cout<<"first lie avgrade="<<psco[0]<<endl;
break;
case 2: cout<<"second lie avgrade="<<psco[1]<<endl;
break;
case 3: cout<<"third lie avgrade="<<psco[2]<<endl;
break;
case 4: cout<<"forth lie avgrade="<<psco[3]<<endl;
break;
case 5: cout<<"fifth lie avgrade="<<psco[4]<<endl;
break;
default:cout<<"input error!" ;
}
}
};
void main()
{
int i,n;
grade A;
A.averscore(sco,avsco);
for(i=0;i<5;i++)
cout<<num[i]<<" "<<avsco[i]<<endl;
cout<<"please input n:"<<endl;
cin>>n;
A.avercourse(sco,n);
}