有哪位高手帮我解决一下两个C++问题,万分感谢!

1.已知一个二维数组中存放一个班30人三门课学生的成绩,求每个人的平均成绩,每门课程的平均成绩。(用指针实现)
程序:
#include"iostream.h"
void pcave(double *t);
void psave(double *t);
void main()
{
double s[30][3]={{88,71,90},{94,93,79},{81,75,67},{72,69,83},{81,78,77},{89,69,71},{85,89,83},{78,67,69},{90,98,89},{83,77,79},{66,80,65},{77,79,85},{92,95,99},{99,75,78},{98,96,85},{87,68,69},{63,89,78},{95,94,91},{95,96,92},{93,98,82},{86,97,83},{84,78,72},{86,84,72},{76,96,81},{95,86,72},{73,86,87},{87,84,82},{91,68,69},{96,67,82},{83,84,99}};
double *p;
p=*s;
cout<<"全体学生三门课的成绩"<<endl;
for(int i=0;i<90;i++)
{ cout<<*p++<<" ";
if((i+1)%3==0) cout<<endl;
}
p=*s;
cout<<"每门课的平均成绩为:"<<endl;
pcave(p);
p=*s;
cout<<"每个学生的平均成绩为:"<<endl;
psave(p);
}
void pcave(double *t)
{
double sum[3];
for(int i=0;i<3;i++)
{ for(int j=0;j<30;j+=3)
sum[i]+=*t;
t+=3;
}
for(i=0;i<3;i++)
{ cout<<sum[i]/30;
cout<<endl;
}
}
void psave(double *t)
{
double sum[30];
for(int i=0;i<30;i++)
{
for(int j=0;j<3;j+=3)
sum[i]+=*t;
t++;
}
for(i=0;i<30;i++)
{ cout<<sum[i]/3;
cout<<endl;
}
}
2.六个学生的资料,要求先算出每个学生的平均成绩,再按平均成绩从大到小排列,依次输出。
程序:
#include "iostream.h"

struct student
{
int num;
char name[10];
double score_chinese;
double score_english;
double score_math;
}stu[6];

void ave(struct student stu[6]);
void arrange(struct student stu[6],double scroe[6]);

void main()
{
stu[6]={{001,"zhang",88,95,83},{002,"wang",98,95,77},{003,"li",76,84,97},{004,"zhao",85,95,87},{005,"sun",98,88,86},{006,"qian",74,82,90}};
cout<<"学生数据如下:"<<endl;
for(int i=0;i<6 ;i++)
cout<<stu[i].num<<stu[i].name<<stu[i]. score_chinese <<stu[i]. score_english <<su[i]t. score_math <<endl;
ave(struct student stu[6]);
arrange(struct student stu[6],double scroe[6]);
cout<<"学生成绩排序如下:"<<endl;
for(i=0;i<6;i++)
cout<<stu[i].num<<stu[i].name<<stu[i]. score_chinese <<stu[i]. score_english <<su[i]t. score_math <<endl;
}

void ave(struct student stu[6])
{
double ave[6] ;
for(int i=0;i<6;i++)
ave[i]=(stu[i]. score_chinese+ stu[i]. score_english+ su[i]t. score_math)/3;
cout<< "每个学生的平均成绩是:"<<endl;
for(i=0 ;i<6;i++)
cout<<stu[i].num<<stu[i].name<<ave[i]<<endl;
}

void arrange(struct student stu[6],double scroe[6])
{
struct student temp,*p ;
for(int i=0;i<5;i++)
for(int j=1;j>i;j++)
{if(score[i]<score[j])
{temp=stu[i]; stu[i]=stu[j]; stu[j]=temp;
}
}
}

第一道题检查没错,但是输出结果不对;第二道题检查有许多标点符号的错误,就是不知道怎么改。请各位高手不吝赐教,谢谢!!!
谢谢你的帮助,但是第二道题第二个函数我修改如下,在主函数中为什么调用(arrange(stu,score))不了呢
void arrange(student stu[6],double score[6])
{
struct student *p;
int t[6]={0,0,0,0,0,0},k=0;
for(int i=0;i<5;i++,k++)
for(int j=1;j>i;j++)
{ if(score[i]>score[j])
t[k]=i;
else t[k]=j;
}
cout<<"学生成绩排序如下:"<<endl;
p=stu;
for(i=0;i<6;i++,k++)
{ p+=t[k];
cout<<p->num<<'\t'<<p->name<<'\t'<<p->score_chinese<<'\t'<<p->score_english<<'\t'<<p->score_math<<endl;
}
}

第1个回答  2009-12-08
1.修改后

#include<iostream>

using namespace std;

void pcave(double *t);
void psave(double *t);
void main()
{
double s[30][3]={{88,71,90},{94,93,79},{81,75,67},{72,69,83},{81,78,77},{89,69,71},{85,89,83},{78,67,69},{90,98,89},{83,77,79},{66,80,65},{77,79,85},{92,95,99},{99,75,78},{98,96,85},{87,68,69},{63,89,78},{95,94,91},{95,96,92},{93,98,82},{86,97,83},{84,78,72},{86,84,72},{76,96,81},{95,86,72},{73,86,87},{87,84,82},{91,68,69},{96,67,82},{83,84,99}};
double *p;
p=&s[0][0];
cout<<"全体学生三门课的成绩"<<endl;
for(int i=0;i<90;i++)
{ cout<<*p ++<<" ";
if((i+1)%3==0) cout<<endl;
}
p=&s[0][0];
cout<<"每门课的平均成绩为:"<<endl;
pcave(p);
p=&s[0][0];
cout<<"每个学生的平均成绩为:"<<endl;
psave(p);

}
void pcave(double *t)
{
double sum[3];
double *p;
sum[0] = sum[1] = sum[2] = 0.;

for(int i=0;i<3;i++)
{
p = t + i;
for(int j=0;j<30;j++) {
sum[i]+=*p;
p+=3;
}

}

for(i=0;i<3;i++)
{ cout<<sum[i]/30;
cout<<endl;
}
}
void psave(double *t)
{
double sum[30];
for( int k=0; k<30; k++ )
sum[k] = 0;

for(int i=0;i<30;i++)
{
for(int j=0;j<3;j++ )
sum[i]+=*t;
t++;
}
for(i=0;i<30;i++)
{ cout<<sum[i]/3;
cout<<endl;
}
}

2. 修改化后,指修改了语法错误. 剩下的自己做
#include <iostream>

using namespace std;

struct student
{
int num;
char name[10];
double score_chinese;
double score_english;
double score_math;
};

void ave(struct student stu[6]);
void arrange(struct student stu[6],double scroe[6]);

void main()
{
student stu[6]={
{001,"zhang",88,95,83},
{002,"wang",98,95,77},
{003,"li",76,84,97},
{004,"zhao",85,95,87},
{005,"sun",98,88,86},
{006,"qian",74,82,90}
};
cout<<"学生数据如下:"<<endl;
for(int i=0;i<6;i++)
cout<<stu[i].num<<stu[i].name<<stu[i].score_chinese <<stu[i].score_english <<stu[i].score_math <<endl;
ave( stu );
double score[6];

arrange( stu,score );
cout<<"学生成绩排序如下:"<<endl;
for(i=0;i<6;i++)
cout<<stu[i].num<<stu[i].name<<stu[i]. score_chinese <<stu[i]. score_english <<stu[i]. score_math <<endl;
}

void ave(struct student stu[6])
{
double ave[6] ;
for(int i=0;i<6;i++)
ave[i]=(stu[i]. score_chinese+ stu[i]. score_english+ stu[i]. score_math)/3;
cout<< "每个学生的平均成绩是:"<<endl;
for(i=0 ;i<6;i++)
cout<<stu[i].num<<stu[i].name<<ave[i]<<endl;
}

void arrange(struct student stu[6],double score[6])
{
struct student temp,*p ;
for(int i=0;i<5;i++)
for(int j=1;j>i;j++)
{if(score[i]<score[j])
{temp=stu[i]; stu[i]=stu[j]; stu[j]=temp;
}
}
}本回答被提问者采纳