持续更新(6)、巩固一下C语言基础知识,顺便散分(学生平均分排序)

Vincent_Song
领域专家: 操作系统技术领域
2011-11-07 12:16:08
动手写代码,解决以下问题:

问题:
已知学生三门课程基本信息如下。请使用结构体编程,计算学生三门课程平均成绩后,列表输出学生的姓名、数学、英语、计算机、平均分信息,并按平均分排序。(20分)
姓名 数学 英语 计算机
Mary 93 100 88
Jone 82 90 90
Peter 91 76 71
Rose 100 80 92

稍后会给出实现代码,以供参考!

支持行动派,拒绝拷贝派!

谁动手,谁收获!
...全文
162 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
火龙 2011-11-07
  • 打赏
  • 举报
回复
我是来接分的,不做题有分接吗~ ╮(╯▽╰)╭
寻找自我 2011-11-07
  • 打赏
  • 举报
回复
脱离VA,经常打错。
Vincent_Song 2011-11-07
  • 打赏
  • 举报
回复
代码来了,仅供参考。
/*author:宋金时*/
/*date:2011/11/01*/

#include <stdio.h>
#include <stdlib.h>
typedef struct student
{
char name[20];
float f_math,f_english,f_compute,f_ave;
}stu;
stu g_arr[4]={{"Mary",93,100,88},{"Jone",82,90,90},{"Peter",91,76,71},{"Rose",100,100,92}};
void c_ave(stu s_arr[],int i_n)
{
int i;
for(i=0;i<i_n;i++)
{
s_arr[i].f_ave = (s_arr[i].f_math+s_arr[i].f_english+s_arr[i].f_compute)/3;
}
}
void sort(stu s_arr[],int i_n)
{
stu* s_p[i_n],*s_temp;
int i,j,i_num;
float f_temp;
for(i=0;i<i_n;i++)
{
s_p[i]=&s_arr[i];
}
for(i=0;i<i_n;i++)
{
i_num = i;
for(j=i+1;j<i_n;j++)
{
if(s_p[i_num]->f_ave<s_p[j]->f_ave)
{
i_num = j;
}
}
if(i_num!=i)
{
s_temp = s_p[i];
s_p[i] = s_p[i_num];
s_p[i_num] = s_temp;
}
printf("%s %f %f %f %f\n",s_p[i]->name\
,s_p[i]->f_math,s_p[i]->f_english\
,s_p[i]->f_compute,s_p[i]->f_ave);
}
}
int main(int argc, char *argv[])
{
c_ave(g_arr,4);
printf("姓名 数学 英语 计算机\n");
sort(g_arr,4);
system("PAUSE");
return 0;
}
Vincent_Song 2011-11-07
  • 打赏
  • 举报
回复
不是考大家,谁动手,谁就收获,不动手,也没事。
龙哥依旧 2011-11-07
  • 打赏
  • 举报
回复
你在考大家?
Vincent_Song 2011-11-07
  • 打赏
  • 举报
回复
算了,没有行动派以后就不散分了。
Vincent_Song 2011-11-07
  • 打赏
  • 举报
回复
不错。
小笨同学 2011-11-07
  • 打赏
  • 举报
回复
我刚看完《C primer plus》链表那一张,巩固一下新学的知识:

#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#define MAX_NAME_SIZE 30
struct student_info {
char name[MAX_NAME_SIZE];
int math_score;
int english_score;
int computer_score;
float average;
};
typedef struct student_info item_t;
struct node {
item_t item;
struct node * next;
};
typedef struct node node_t;
struct list {
node_t * next;
int count;
};
typedef struct list list_t;

void init(list_t *list);
bool add(item_t *item, list_t *list);
void sort_by_average(list_t *list);
int main(void)
{
list_t list;
init(&list);
item_t tmp;
printf("请输入学生名字以及对应的分数,以空格隔开:\n");
printf("例如:\n张三 2 3 4 \n");
printf("姓名\t数学\t英语\t计算机\n");
while (scanf("%s %d %d %d",
tmp.name,
&tmp.math_score,
&tmp.english_score,
&tmp.computer_score) == 4) {
tmp.average = ((float)(tmp.math_score) +
tmp.english_score +
tmp.computer_score) / 3;
add(&tmp, &list);
}
node_t *node;
printf("姓名\t数学\t英语\t计算机\t平均分\n");
sort_by_average(&list);
node = list.next;
while(node != NULL) {
printf("%s\t%d\t%d\t%d\t%f\n",\
node->item.name,\
node->item.math_score,\
node->item.english_score,\
node->item.computer_score,\
node->item.average);
node = node->next;
}
return 0;
}

void init(list_t *list)
{
list->next = NULL;
list->count = 0;
list->count = 0;
}
bool add(item_t *item, list_t *list)
{
node_t *node;
node = malloc(sizeof(node_t));
if (node == NULL) {
return false;
} else {
node->item = *item;
node->next = list->next;
list->next = node;
(list->count)++;
return true;
}
}
void sort_by_average(list_t *list)
{
node_t *current;
node_t *pre;
node_t **pre_pre;
int i;
int j;
for (i = 1 ; i <= list->count - 1; i++) {
pre_pre = &list->next;
pre = *pre_pre;
current = pre->next;
for ( j= 1; j <= list->count - i; j++) {
if (pre->item.average > current->item.average) {
*pre_pre = current;
pre->next = current->next;
current->next = pre;
pre_pre = ¤t->next;
pre = *pre_pre;
current = pre->next;
} else {
pre_pre = &pre->next;
pre = current;
current = current->next;
}
}
}
}

调试结果:
请输入学生名字以及对应的分数,以空格隔开:
例如:
张三 2 3 4
姓名 数学 英语 计算机
Rose 100 80 92
Peter 91 76 71
Jone 82 90 90
Mary 93 100 88
k k k
姓名 数学 英语 计算机 平均分
Peter 91 76 71 79.333336
Jone 82 90 90 87.333336
Rose 100 80 92 90.666664
Mary 93 100 88 93.666664
源码下载地址: https://pan.quark.cn/s/40677b766bda "ContextCapture 倾斜摄影快速、创新及全面空三建模与单机集群硬件部署方案2018" 此资源聚焦于倾斜摄影(ContextCapture)空三建模及单机集群硬件部署方案,致力于为用户呈现最快、最优成本效益的台式工作站、移动工作站、并行集群的多样化部署选择。以下是该资源的详细知识点概述: 一、相关设备型号说明 * UltraLAB 是西安坤隆计算机科技有限公司推出的专属图形工作站品牌,具备三大卓越优势:顶尖的计算硬件架构、精准的行业应用定制服务、专业的硬件系统优化工艺。 二、硬件部署方案 * 台式工作站部署建议:设备特色在于当前市场上最快的台式计算架构,适用于办公场景下,部门层级常规的倾斜摄影空三处理、三维建模。 * 便携式工作站部署建议:设备特色在于当前市场上最快的移动计算架构,适用于移动倾斜摄影的空三处理、三维建模工作站。 * 大数据量处理工作站推荐:设备特色在于极限自动超频加速与16个并行存储构造,具备空三处理和三维建模最强的计算性能及海量高速并行存储性能。 * 多设备并行计算集群部署建议:针对海量图像数据计算产生的巨大需求,单机计算能力处理时间过长,效率不高,通过多台机器并行集群,进行空三处理、三维建模,显著减少处理时间。 三、部署方案深入解析 * 2.1 倾斜摄影建模(台式工作站)部署方案:设备特色在于最高的计算处理能力~6核5.2GHz,内存最大配置可达64GB,配备最新图灵架构的RTX显卡,相比市场其他品牌机器(单CPU、双Xeon处理器)更快、更具成本效益。 * 2.2 倾斜摄影建模(移动便携式工作站)硬件部署方案:设备特色在于最高的计算处理能力~6...

70,039

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧