源代码如下:
#include<iostream>
using namespace std;
struct socre
{
char iName[30];
double iTotal;
struct course
{
int iChinese;
int iMath;
int iEnglish;
}personal;
}student[100];
void output(int n);
void caculate(struct score *pchar,int i);
void main()
{
cout<<"学生人数:";
int n;
cin>>n;
getchar();
for(int i=0;i<n;i++)/*名字,分数*/
{
cout<<"NO.:"<<i+1<<endl;
cout<<"iName:";
char temp[30];
strcpy(student[i].iName,gets(temp));
cout<<"Chinese:";
cin>>student[i].personal.iChinese;
cout<<"Math:";
cin>>student[i].personal.iMath;
cout<<"English:";
cin>>student[i].personal.iEnglish;
getchar();
caculate(&student[i],i);/*这里我想把student[i]的地址和结构体数组下标传递给形参*/
}
output(n);
}
/*计算综合成绩*/
void caculate(struct score *pchar,int i);/*错误提示:cpp(40) : error C2664: 'caculate' : cannot convert parameter 1 from 'struct socre *' to 'struct score *'*/
{
pchar->iTotal=pchar->personal.iCinese*0.2+pchar->personal.iEnglish*0.3+pchar->personal.math*0.5;/*总成绩等于语文成绩*20%+英语成绩*30%+数学成绩*50%*/
}
/*输出学生姓名和综合成绩*/
void output(int n)
{
for(int i=0;i<n;i++)
{
cout<<"NO.:"<<i+1<<endl;
cout<<"Name:"<<student[i].iName<<endl;
cout<<"Total:"<<student[i].iTotal<<endl;
}
}
问题点:1,结构体数组作为函数参数,把实参到形参的方式有哪些呢?
2,/*错误提示:cpp(40) : error C2664: 'caculate' : cannot convert parameter 1 from 'struct socre *' to 'struct score *'*/这句错误提示我不知道怎么解决,求前辈们指导,谢谢!
|
|