МЕЙЛА 2018-12-29 01:02 采纳率: 0%
浏览 1224

c++ 用链表怎么怎么算十个学生的三门成绩平均值

  1. 有10个学生,每个学生的数据包括学号、姓名、英语、数学、物理三门课的成绩,从键盘输入10个学生数据,要求打印出3门课程的总平均成绩,以及最高分的学生的数据(包括学号,姓名,3门课的成绩,平均分数)。下面是我写出来的部分。。。 我用结构体数组做出来了,想知道能不能用链表做出来? #include #include using namespace std; struct studentT{char no[4]; char name[10]; int eng; int math; int phy; }; struct node{ studentT stu; node *next; };

node*create_link();
void out_link(node*head);

int main()
{node *head=NULL;
head=create_link();
out_link(head);
cout<<"打印出总平均成绩:"< avg_link(head);
return 0;
}
node*create_link()
{node*head=NULL,*p,*q;
char no[4];
char name[10];
int eng,math,phy;
cout cin>>no;
head=new node;
strcpy(head->stu.no,no);
cin>>name;
strcpy(head->stu.name,name);
cin>>eng>>math>>phy;
head->stu.eng=eng;
head->stu.math=math;
head->stu.phy=phy;
q=head;
head->next=NULL;
cin>>no;
while(no[0]!='!')
{p=new node;
strcpy(p->stu.no,no);
cin>>name;
strcpy(p->stu.name,name);//=拷贝字符串时候只会拷贝首地址(第一个字符),而strcpy是把字符串里每个字符一个一个拷贝过去
cin>>eng>>math>>phy;
p->stu.eng=eng;
p->stu.math=math;
p->stu.phy=phy;
p->next=NULL;
q->next=p;
q=p;
cin>>no;
}
return head;
}
void out_link(node*head)
{node*p=head;
cout<<"输出数据:"< while(p!=NULL)
{coutstu.no<<'\t'<stu.name<<'\t'<stu.eng<<'\t'<stu.math<<'\t'<stu.phy<<'\t'< p=p->next;
}
}
void avg_link(node*head)
{node*p,*q;
int i,j,n,m;
p=head;
while(i=0,i<)

}

  • 写回答

1条回答 默认 最新

  • weixin_43176170 2019-01-05 11:58
    关注

    //建立链表的结点
    struct stu{
    int id;//学号
    char name[16];//姓名
    int eng,math,phy;
    }
    //建立一个链表的结构体,便于查找插入、删除的操作
    struct LinkList{
    stu *head; //这里设置一个头结点,不存放任何数据,用于遍历等操作
    int size;//链表的大小(可以看你存放了多少个学生的数据)

    
    
    评论

报告相同问题?

悬赏问题

  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝