c语言三个学生每人四门,C语言一道题目,求教教3.统计一个班的学生成绩。要求程序具有如下功能:(1) 每个学生的学号和四门功课的成绩从键盘读入。...
共回答了20个问题采纳率:100%
#include
#include
#define NULL0
#define LEN sizeof(struct student)
struct student
{
long num;
char name[20];
float score1;
float score2;
float score3;
float score4;
float score5;
float c;
float z;
struct student *next;
};
int n;
struct student *creat(void)
{
struct student *head;
struct student *p1,*p2;
n=0;
p1=p2=(struct student *)malloc(LEN);
scanf("%ld,%f,%f,%f,%f,%f,%s",&p1->num,&p1->score1,&p1->score2,&p1->score3,&p1->score4,&p1->score5,p1->name);
head=NULL;
while(p1->num!=0)
{n=n+1;
if(n==1)head=p1;
else p2->next=p1;
p2=p1;
p1=(struct student*)malloc(LEN);
scanf("%ld,%f,%f,%f,%f,%f,%s",&p1->num,&p1->score1,&p1->score2,&p1->score3,&p1->score4,&p1->score5,p1->name);
}
p2->next=NULL;
return(head);
}
void print(struct student *head)
{
struct student *p;
printf("nNow,these %d records are:n",n);
p=head;
if(head!=NULL)
do
{
p->z=(p->score1)+(p->score2)+(p->score3)+(p->score4)+(p->score5);
p->c=(p->z)/5;
printf("%ld %5.1f%5.1f%5.1f%5.1f%5.1f %s ",p->num,p->score1,p->score2,p->score3,p->score4,p->score5,p->name);
printf("总分=%f 平均分=%fn",p->z,p->c);
p=p->next;
}
while(p!=NULL);
}
struct student *del(struct student *head,long num)
{
struct student *p1,*p2;
if(head==NULL)
{printf("nlist nulln");
return head;}
p1=head;
while(num!=p1->num && p1->next!=NULL)
{p2=p1;
p1=p1->next;
}
if(num==p1->num)
{if(p1==head)head=p1->next;
else p2->next=p1->next;
printf("delete:%ldn",num);
n=n-1;
free(p1);
}
else printf("%ld not been found!n",num);
return(head);
}
struct student *insert(struct student *head,struct student *stud)
{
struct student *p0,*p1,*p2;
p1=head;
p0=stud;
if(head==NULL)
{head=p0;p0->next=NULL;}
else
{
while((p0->num>p1->num)&&(p1->next!=NULL))
{
p2=p1;
p1=p1->next;
}
if(p0->numnum)
{if(head==p1)head=p0;
else p2->next=p0;
p0->next=p1;}
else
{p1->next=p0;p0->next=NULL;}
}
n=n+1;
return(head);
}
struct student * ordination(struct student * head)
{
struct student * first;
struct student * tail;
struct student * p_min;
struct student * min;
struct student * p;
first=NULL;
while(head!=NULL)
{
for(p=head,min=head;p->next!=NULL;p=p->next)
{
if(p->next->numnum)
{
p_min=p;
min=p->next;
}
}
if(first==NULL)
{
first=min;
tail=min;
}
else
{
tail->next=min;
tail=min;
}
if(min==head)
{
head=head->next;}
else{p_min->next=min->next;}
}
if(first!=NULL)
{
tail->next=NULL;
}
head=first;
return(head);
}
struct student * ordinationc(struct student * head)
{
struct student * first;
struct student * tail;
struct student * p_min;
struct student * min;
struct student * p;
first=NULL;
while(head!=NULL)
{
for(p=head,min=head;p->next!=NULL;p=p->next)
{
if(p->next->z>min->z)
{
p_min=p;
min=p->next;
}
}
if(first==NULL)
{
first=min;
tail=min;
}
else
{
tail->next=min;
tail=min;
}
if(min==head)
{
head=head->next;}
else{p_min->next=min->next;}
}
if(first!=NULL)
{
tail->next=NULL;
}
head=first;
return(head);
}
struct student *cha(struct student *head,long cha)
{
struct student *p1,*p2;
if(head==NULL)
{printf("nlist nulln");
return head;}
p1=head;
while(cha!=p1->num && p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
if(cha==p1->num)
{
printf("%ld,%5.1f%5.1f%5.1f%5.1f%5.1f,%sn",p1->num,p1->score1,p1->score2,p1->score3,p1->score4,p1->score5,p1->name);
}
else printf("%ld not been found!n",cha);
return(head);
}
struct student *chap(struct student *head)
{
struct student *p1,*p2;
int x;
x=1;
if(head==NULL)
{printf("nlist nulln");
return head;}
p1=head;
while( p1->next!=NULL)
{
if(p1->c>85)
{
printf("%ld,%5.1f%5.1f%5.1f%5.1f%5.1f,%sn",p1->num,p1->score1,p1->score2,p1->score3,p1->score4,p1->score5,p1->name);
x=0;
}
p1=p1->next;
}
if(x) printf("没有平均分在85分以上的学生n");
return(head);
}
struct student *chapb(struct student *head)
{
struct student *p1,*p2;
int x;
x=1;
if(head==NULL)
{printf("nlist nulln");
return head;}
p1=head;
while( p1->next!=NULL)
{
if(p1->cnum,p1->score1,p1->score2,p1->score3,p1->score4,p1->score5,p1->name);
x=0;
}
p1=p1->next;
}
if(x) printf("没有不及格的学生n");
return(head);
}
void main()
{
struct student * head, * stu;
long del_num;
long cha_num;
printf("input record:(学号、5科成绩、姓名)n");
head=creat();
print(head);
printf("ninput the deleted number:");
scanf("%ld",&del_num);
while(del_num!=0)
{
head=del(head,del_num);
print(head);
printf("input the deleted number:");
scanf("%ld",&del_num);
}
printf("ninput the inserted record:");
stu=(struct student * )malloc(LEN);
scanf("%ld,%f,%f,%f,%f,%f,%s",&stu->num,&stu->score1,&stu->score2,&stu->score3,&stu->score4,&stu->score5,stu->name);
while(stu->num!=0)
{
head=insert(head,stu);
print(head);
printf("input the inserted record:");
stu=(struct student * )malloc(LEN);
scanf("%ld,%f,%f,%f,%f,%f,%s",&stu->num,&stu->score1,&stu->score2,&stu->score3,&stu->score4,&stu->score5,stu->name);
}
printf("ninput the 查找 number:");
scanf("%ld",&cha_num);
while(cha_num!=0)
{
head=cha(head,cha_num);
printf("input the 查找 number:");
scanf("%ld",&cha_num);
}
printf("下面是85分以上的:nn");
head=chap(head);
printf("n");
printf("下面是不及格的:nn");
head=chapb(head);
printf("n");
printf("下面是学号排序");
head=ordination(head);
print(head);
printf("nn");
printf("总分排序");
head=ordinationc(head);
print(head);
}
这是我上学期的作业,跟你的差不多
1年前
9
c语言三个学生每人四门,C语言一道题目,求教教3.统计一个班的学生成绩。要求程序具有如下功能:(1) 每个学生的学号和四门功课的成绩从键盘读入。...相关推荐
- c语言三个数从小到大排序/输出_C语言经典100题(6)
1 上期答案揭晓 首先给大家看看上一篇文章C语言经典100题(5)中第三部分编程题的答案: #include int main(){ int x,y,z,t; printf("\n请输入三个 ...
- c语言三个字母比较大小,C语言stricmp()函数:比较两个字符串大小
函数名: stricmp 头文件: 函数原型: int stricmp(const char *str1, const char *str2); 功 能: 比较两个字符串大小,但不区分大小写 参 数: ...
- c语言三个人的象棋,【C语言小游戏】 中国象棋(示例代码)
人人对战 [email protected]:~$ cat main.c // main.c // 象棋 // 車马相仕帅仕相马車 // 十十十十十十十十十 // 十炮十十十十十炮十 // ...
- 编写一个程序,设计一个类Score用于统计一个班的学生成绩,其中使用一个静态数据成员sum存储总分和一个静态成员函数getSum返回该总分
头文件名称: 头文件: #include<iostream> using namespace std;class Score { public:int getSum(){return su ...
- c语言文学研究助手题目,各位达人,给小弟一个文学研究助手的c程序啊!急啊!谢谢大家啦!...
#include "string.h" #include "stdio.h" #include "alloc.h" #include &qu ...
- C++实验编程题:.定义一个描述学生(Student)基本情况的类,数据成员包括姓名(name)、学号(num)、数学成绩(mathScore)、英语成绩(englishScore)、人数(count
题目描述: *6.定义一个描述学生(Student)基本情况的类,数据成员包括姓名(name).学号(num).数学成绩(mathScore).英语成绩(englishScore).人数(count) ...
- 判断成绩linux程序编程,程序输入输出 ,编写判断成绩的程序
程序输入输出 1.1 问题 编写login.py脚本,实现以下目标: 提示用户输入用户名 将用户名保存在变量中 在屏幕上显示欢迎用户的信息 1.2 方案 编写程序时,很多情况下都需要程序与用户交互.在 ...
- c语言动态生成二维数组,C语言 动态创建二维数组
/*C语言 如何动态创建二维数组 转化为一维数组申请数组,创建和释放都比较简单 */ #include #include #include #define RANK 10 #define COLUMN ...
- 三个学生四门课程,求出学生平均成绩和课程的平均成绩;n个学生每人m门课程,找出最高分学生,输出有一门成绩不合格的学生的各门成绩,计算每门成绩都在85分及以上的学生的人数(C)
养成好习惯,点个赞 再走:有问题,欢迎私信.评论,我看到都会回复的 以下两个题目就是玩一下for循环语句和二维数组 文章目录 三个学生四门课程,求出学生平均成绩和课程的平均成绩 n个学生,每人m门课程 ...
- 【例16 Java从键盘读入学生成绩,找出最高分,并输出学生成绩等级】
例16:从键盘读入学生成绩,找出最高分,并输出学生成绩等级. 成绩>=最高分-10 等级为'A' 成绩>=最高分-20 等级为'B' 成绩>=最高分-30 等级为'C' 其余 等级为 ...
最新文章
- 取文字_有内涵的男孩名字:用三字经为宝宝取一个独特稀少有内涵的好名
- 高斯混合模型理解汇总
- const指针和指向常量的指针
- 如何使用Tornado实现WebSocket服务器?
- 蚂蚁金服回应海外和科创板上市传言:暂无上市时间表
- MFC 教程【12_对话框和对话框类CDialog 】
- leetcode—8.同向双指针—滑动窗口题型python解答
- mysql安装显示挂起_安装SQL时提示有挂起的文件操作无法安装的解决
- Qt视频直播软件--项目实战(Day5)
- 校园民谣:1983-2003。谨以此文献给2020年说再见就此生再也不见的毕业生们
- pillow库——使用图像类Image
- 解决MySQL登录ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using passwor)问题
- halo_回顾:Halo 3与糖尿病抗争
- 仿滴滴首页车辆随机平滑移动,基于高德地图
- PHP:40+开发工具推荐
- 关于64位整型int64_t
- 【计算机网络-自顶向下】3—Transport layer运输层(概述、多路复用与分解、UDP、可靠数据传输、TCP、拥塞控制)
- java实现下载excel文件
- vscode vetur 代码格式化优化设置(亲测有用)
- 低功耗4g无线视频服务器,低功耗4G+AI+IOT视频安防行业的首选