33,321
社区成员




#include<malloc.h>
#include<iostream>
#include<stdio.h>
#include<string>
#include<stdlib.h>
using namespace std;
#define N 5
#define T 2
typedef struct
{
int data[50];
int length;
}sqlist;
struct student
{
int num;
string name;
float score1;
float score2;
float score3;
}stu[2];
void creatlist(sqlist *l,struct student) ; //error1:syntax error : identifier 'stu'
void DispList(sqlist *);
void unionlist(sqlist *,sqlist *,sqlist *&);
int main()
{
int i;
sqlist *sqa,*sqb,*sqc;
cout<<"请输入学生信息:/n 学号 姓名 分数1 分数2 "<<endl;
cin>>stu[0].num>>stu[0].name>>stu[0].score1>>stu[0].score2;
creatlist(sqa,stu[0]); //error2: 'creatlist' : function does not take 2 parameters
cout<<"请输入学生信息:/n 学号 姓名 分数1 分数3 "<<endl;
cin>>stu[0].num>>stu[0].name>>stu[0].score1>>stu[0].score3;
creatlist(sqa,stu[1]); //error3: 'creatlist' : function does not take 2 parameters
unionlist(sqa,sqb,sqc);
DispList(sqc);
return 0;
}
void creatlist(sqlist *l,struct student stu) //error4: syntax error : identifier 'stu'
{
int i;
l=(sqlist *)malloc(sizeof(sqlist));
l->data[0]=stu.num;
l->data[1]=stoi(stu.name); //error5: no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no a
l->data[2]=stu.score1;
l->data[3]=stu.score2;
}
void DispList(sqlist *l)
{
int i;
for(i=0;i<l->length;i++)
{
printf("%d ",l->data[i]);
}
printf("\n");
}
void unionlist(sqlist *a,sqlist *b,sqlist *&c)
{
c=(sqlist *)malloc(sizeof(sqlist));
int i,j=0,k=0,l=0;
c->length=0;
for(i=0;i<a->length;i++)
{
c->data[i]=a->data[i];
c->length++;
}
while(j<b->length)
{
c->data[i]=b->data[j];
i++;
c->length++;
}
}