C程大作业Word格式文档下载.docx

上传人:b****2 文档编号:3181190 上传时间:2023-05-01 格式:DOCX 页数:22 大小:50.96KB
下载 相关 举报
C程大作业Word格式文档下载.docx_第1页
第1页 / 共22页
C程大作业Word格式文档下载.docx_第2页
第2页 / 共22页
C程大作业Word格式文档下载.docx_第3页
第3页 / 共22页
C程大作业Word格式文档下载.docx_第4页
第4页 / 共22页
C程大作业Word格式文档下载.docx_第5页
第5页 / 共22页
C程大作业Word格式文档下载.docx_第6页
第6页 / 共22页
C程大作业Word格式文档下载.docx_第7页
第7页 / 共22页
C程大作业Word格式文档下载.docx_第8页
第8页 / 共22页
C程大作业Word格式文档下载.docx_第9页
第9页 / 共22页
C程大作业Word格式文档下载.docx_第10页
第10页 / 共22页
C程大作业Word格式文档下载.docx_第11页
第11页 / 共22页
C程大作业Word格式文档下载.docx_第12页
第12页 / 共22页
C程大作业Word格式文档下载.docx_第13页
第13页 / 共22页
C程大作业Word格式文档下载.docx_第14页
第14页 / 共22页
C程大作业Word格式文档下载.docx_第15页
第15页 / 共22页
C程大作业Word格式文档下载.docx_第16页
第16页 / 共22页
C程大作业Word格式文档下载.docx_第17页
第17页 / 共22页
C程大作业Word格式文档下载.docx_第18页
第18页 / 共22页
C程大作业Word格式文档下载.docx_第19页
第19页 / 共22页
C程大作业Word格式文档下载.docx_第20页
第20页 / 共22页
亲,该文档总共22页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

C程大作业Word格式文档下载.docx

《C程大作业Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《C程大作业Word格式文档下载.docx(22页珍藏版)》请在冰点文库上搜索。

C程大作业Word格式文档下载.docx

(4)对系统常量要求用符号常量进行规范,对于常用的功能和算法如排序要求做成自己的库函数,并使用头文件的方式实现分离编译。

(5)要求提供算法分析、程序流程图,对实验结果的处理包括程序调试结果、结论及改进方案、实习体会等内容。

三.大作业总体设计及源代码

1、总体设计

2、源代码

#include<

stdio.h>

string.h>

/*定义数组*/

#defineM3

structstudent/*结构体*/

{

intxh;

//学生学号

charxm[20];

/*数组*/

charxb;

intnl;

intcj[M];

//成绩

intzf,pjf;

/*总分与平均分*/

};

structstudents[20];

/*学生数组*/

intn=0;

voidcalc(i)

intsum=0,j;

for(j=0;

j<

M;

j++)

sum=sum+s[i].cj[j];

s[i].zf=sum;

s[i].pjf=sum/M;

}

voidinput()/*插入*/

intlocate(intxh);

intxh,i,sum;

printf("

请输入学号:

"

);

scanf("

%12d"

&

xh);

getchar();

while(xh!

=0)

{

if(locate(xh)!

=-1)

{

printf("

学号已存在!

!

\n\n"

gotoabc;

}

s[n].xh=xh;

printf("

姓名:

gets(s[n].xm);

性别:

scanf("

%c"

s[n].xb);

年龄:

%d"

s[n].nl);

sum=0;

3门成绩,成绩范围0--150:

for(i=0;

i<

i++)

scanf("

s[n].cj[i]);

if(s[n].cj[i]<

0||s[n].cj[i]>

150)

成绩超出范围"

return;

calc(n);

n++;

abc:

\n请输入学号:

getchar();

}

voidinsert()/*插入*/

inti,j,t;

输入插入位置(0---%d):

n);

i);

if(i<

0||i>

n)

序号超出范围!

\n"

return;

for(j=n-1;

j>

=i;

j--)

s[j+1].xh=s[j].xh;

strcpy(s[j+1].xm,s[j].xm);

s[j+1].xb=s[j].xb;

s[j+1].nl=s[j].nl;

s[j+1].cj[0]=s[j].cj[0];

s[j+1].cj[1]=s[j].cj[1];

s[j+1].cj[2]=s[j].cj[2];

请输入学号:

s[i].xh);

请输入姓名:

gets(s[i].xm);

请输入性别:

s[i].xb);

请输入年龄:

s[i].nl);

请输入3科成绩,成绩范围0---150:

for(j=0;

{scanf("

s[i].cj[j]);

if(s[i].cj[j]>

{printf("

分数超出范围,请核对后再输入!

}

calc(i);

n=n+1;

}

//删除

voiddel()

intxh,i,j;

输入学号:

i=locate(xh);

if(i!

for(j=i+1;

n;

s[j-1].xh=s[j].xh;

strcpy(s[j-1].xm,s[j].xm);

s[j-1].xb=s[j].xb;

s[j-1].nl=s[j].nl;

s[j-1].cj[0]=s[j].cj[0];

s[j-1].cj[1]=s[j].cj[1];

s[j-1].cj[2]=s[j].cj[2];

n=n-1;

else

无法删除!

intlocate(intxh)

inti,j;

for(i=0;

if(s[i].xh==xh)

%11d"

s[i].xh);

%20s"

s[i].xm);

%3c"

s[i].xb);

%5d"

s[i].nl);

s[i].cj[j]);

s[i].zf);

s[i].pjf);

returni;

学号不存在,请输入学生信息!

return-1;

//显示

voiddisplay()

----------------学生成绩统计---------------\n"

学号姓名性别年龄成绩1成绩2成绩3总分平均分\n"

-----------------------------------------------------\n"

voidsave()

FILE*fp;

inti;

charfname[20];

输入文件名:

gets(fname);

fp=fopen(fname,"

wb"

if(fp==NULL)

文件打开错误!

if(fwrite(&

s[i],sizeof(structstudent),1,fp)!

=1)

文件写入错误!

文件保存成功!

fclose(fp);

voidswap(inta,intb)

intt;

t=s[a].xh;

s[a].xh=s[b].xh;

s[b].xh=t;

strcpy(xm,s[a].xm);

strcpy(s[a].xm,s[b].xm);

strcpy(s[b].xm,xm);

xb=s[a].xb;

s[a].xb=s[b].xb;

s[b].xb=xb;

t=s[a].nl;

s[a].nl=s[b].nl;

s[b].nl=t;

t=s[a].cj[0];

s[a].cj[0]=s[b].cj[0];

s[b].cj[0]=t;

t=s[a].cj[1];

s[a].cj[1]=s[b].cj[1];

s[b].cj[1]=t;

t=s[a].cj[2];

s[a].cj[2]=s[b].cj[2];

s[b].cj[2]=t;

t=s[a].zf;

s[a].zf=s[b].zf;

s[b].zf=t;

t=s[a].pjf;

s[a].pjf=s[b].pjf;

s[b].pjf=t;

//冒泡排序法

voidsortbyxh()

n-1;

n-1-i;

if(s[j].xh>

s[j+1].xh)

swap(j,j+1);

顺序已经排好!

voidsortbyzf()

i++)//进行n-1次循环,进行n-1次比较

for(j=0;

n-i-1;

j++)//在每一趟比较中进行n-i-1次比较

if(s[j].zf>

s[j+1].zf)//相临的两个数比较

swap(j,j+1);

voidsortbypjf()

if(s[j].pjf>

s[j+1].pjf)

swap(j,j+1);

voidsort()

1按学生学号排序\n"

2按学生总分排序\n"

3按平均分数排序\n"

请输入选项:

switch(i)

case1:

sortbyxh();

break;

case2:

sortbyzf();

case3:

sortbypjf();

break;

}

//下载文件

voidload()

rb"

if(fp==NULL)

//从文件中载入学生信息

n=0;

while(!

feof(fp))

if(fread(&

s[n],sizeof(structstudent),1,fp)!

=1)

{break;

n++;

文件成功载入!

fclose(fp);

//统计数据

voidstas()

inta,b,c,d,e;

a=b=c=d=e=0;

i++)

switch(s[i].pjf/10)

case0:

case1:

case2:

case3:

case4:

case5:

case6:

case7:

case8:

a++;

case9:

case10:

b++;

case11:

c++;

case12:

d++;

case13:

case14:

e++;

case15:

;

<

80%d%5.2f%%\n"

a,a*100.0/n);

90<

-->

110%d%5.2f%%\n"

b,b*100.0/n);

110<

120%d%5.2f%%\n"

c,c*100.0/n);

120<

130%d%5.2f%%\n"

d,d*100.0/n);

130<

150%d%5.2f%%\n"

e,e*100.0/n);

voidedit()//编辑学生信息板块

请输入学号:

if(i==-1)

学号不存在!

请输入3门课的成绩:

%d%d%d"

s[i].cj[0],&

s[i].cj[1],&

s[i].cj[2]);

calc(i);

修改成功!

voidmain()

intc=1;

while(c!

**********************\n"

*学生成绩管理系统菜单*\n"

(1)输入*

(2)插入\n"

(3)删除*(4)编辑\n"

(5)查找*(6)排序\n"

(7)显示*(8)保存\n"

(9)载入*(10)统计\n"

(0)退出*\n"

**********************\n"

);

输入选项:

"

c);

//条件选择语句

switch(c)

{

case1:

input();

case2:

insert();

case3:

del();

case4:

edit();

case5:

{intxh;

printf("

scanf("

locate(xh);

}

case6:

sort();

case7:

display();

case8:

save();

case9:

load();

case10:

stas();

case0:

3、调试结果

4总结.(如需要,可附结论及改进方案、实习体会)

新疆大学课程论文(设计)、学年论文评分表

题目

作者

专业年级

指导教师

指导教师评语及

评分建议

年月日

(部)

学院或教研室主任:

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 教学研究 > 教学计划

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2