C语言课程方案设计书学生信息管理系统.docx

上传人:b****1 文档编号:1248829 上传时间:2023-04-30 格式:DOCX 页数:43 大小:26.03KB
下载 相关 举报
C语言课程方案设计书学生信息管理系统.docx_第1页
第1页 / 共43页
C语言课程方案设计书学生信息管理系统.docx_第2页
第2页 / 共43页
C语言课程方案设计书学生信息管理系统.docx_第3页
第3页 / 共43页
C语言课程方案设计书学生信息管理系统.docx_第4页
第4页 / 共43页
C语言课程方案设计书学生信息管理系统.docx_第5页
第5页 / 共43页
C语言课程方案设计书学生信息管理系统.docx_第6页
第6页 / 共43页
C语言课程方案设计书学生信息管理系统.docx_第7页
第7页 / 共43页
C语言课程方案设计书学生信息管理系统.docx_第8页
第8页 / 共43页
C语言课程方案设计书学生信息管理系统.docx_第9页
第9页 / 共43页
C语言课程方案设计书学生信息管理系统.docx_第10页
第10页 / 共43页
C语言课程方案设计书学生信息管理系统.docx_第11页
第11页 / 共43页
C语言课程方案设计书学生信息管理系统.docx_第12页
第12页 / 共43页
C语言课程方案设计书学生信息管理系统.docx_第13页
第13页 / 共43页
C语言课程方案设计书学生信息管理系统.docx_第14页
第14页 / 共43页
C语言课程方案设计书学生信息管理系统.docx_第15页
第15页 / 共43页
C语言课程方案设计书学生信息管理系统.docx_第16页
第16页 / 共43页
C语言课程方案设计书学生信息管理系统.docx_第17页
第17页 / 共43页
C语言课程方案设计书学生信息管理系统.docx_第18页
第18页 / 共43页
C语言课程方案设计书学生信息管理系统.docx_第19页
第19页 / 共43页
C语言课程方案设计书学生信息管理系统.docx_第20页
第20页 / 共43页
亲,该文档总共43页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

C语言课程方案设计书学生信息管理系统.docx

《C语言课程方案设计书学生信息管理系统.docx》由会员分享,可在线阅读,更多相关《C语言课程方案设计书学生信息管理系统.docx(43页珍藏版)》请在冰点文库上搜索。

C语言课程方案设计书学生信息管理系统.docx

C语言课程方案设计书学生信息管理系统

封面

作者:

PanHongliang

仅供个人学习

学生信息管理系统

一.课程设计目的:

熟练掌握条件语句、循环、数组、函数操作,将本课程所学的知识合理地运用于实践当中。

了解一些书上没有的函数及使用方法。

为以后的用C语言乃至其他设计语言解决实际问题打下了一个良好的基础。

二.课程设计的思路及设计过程

1.思路:

设计出适合本班同学的同学信息管理系统,可以按照多种查询方式查询班级成员信息。

2.过程:

a.定义所需函数:

voidmain()voidm(intx)voidput(LinkListp)voidall(LinkListhead,intx)

b 然后调用函数;

c通过预先输入学生信息,实现可以按照学号姓名年龄性别查询学生信息;

d快捷启动,快捷推出。

3.程序流程图如下:

4.课程设计中涉及的知识点

  ⑴循环语句:

for语句循环。

  

for语句是C语言中所提供的功能最强、使用最为灵活的一种循环语句。

特别适用与循环次数固定而循环条件不确定的情况。

   

for语句最主要的特点是:

特别适合已知循环次数的循环语句。

while语句

while语句可以实现当型循环,通常用于能够确定的循环次数的循环控制。

条件语句:

if语句。

if语句是C语言中的选择结构语句的主要形式,它根据if语句后面的条件表达式来决定执行过程。

⑵数组:

一维数组元素的应用、赋值和越界检查。

  

一维数组声明的一般形式为:

            

类型标识符 数组名 [常量表达式];  

数组元素是组成数组的基本单元。

一维数组赋值的方法有:

用赋值语句对数组元素逐个赋值;采用初始化赋值和动态赋值的方法。

为了不可避免不可预测的错误发生,在程序中最好还是加上数组越界检查程序代码,将数组越界的检查范围加在程序中,就可以确保程序执行的正确性。

因此,可以说数组的边界检验便是程序员的职责。

⑶函数:

1)、函数的定义。

函数定义的形式

1  传统的定义形式

[类型标识符]函数名([形参列表])

形参说明

{ 声明部分

语句/*功能实现部分*/

[return表达式;]

}

2  现代的定义形式

[类型标识符] 函数名([数据类型形式参数,数据类型形式参数,……])

{声明部分

语句/*功能实现部分*/

[return表达式;]

}

2)、函数的调用。

在函数调用中,对于无参数调用时是没有实际参数列表。

实际参数列表中的参数可以是常数、变量或其他构造类型数据及表达式,各是参数之间用逗号分隔。

在C语言程序中,可以用以下几种方式调用函数:

1  函数表达式

2  函数语句

3  函数实参

3)、函数变量的作用域。

C语言中所有的变量都有自己的作用域。

变量说明的方式不同,其作用域也不同。

C语言中的变量,按作用域范围可分为两种,即局部变量和全局变量。

局部变量:

局部变量也称为内部变量。

局部变量是在函数内作定义说明的,其作用域仅限于函数内,离开函数后在使用这种变量是非法的。

全局变量:

全局变量也称为外部变量,它是在函数外部定义的变量。

它不属于哪一个函数,它属于一个源程序文件。

其作用域是从定义变量的位置开始到当前源文件结束。

4)、数组元素作为函数的参数。

如果同一个源文件中,全局变量与局部变量同名,则在局部变量的作用范围内全局变量被“屏蔽”了,即它不起作用。

发生函数调用时,把作为实参的数组元素的值传送给形参,实现一一对应、单向的至传递。

5)、数组名作为函数的参数。

用数组名作为函数参数时,要求形参和相对应的实参都必须是类型相同的数组,都必须有明确的数组说明。

数组名实质上就是数组的首地址,因此数组名作函数参数时所进行的传递只是地址的传递。

数组名作函数参数时,由于实际上形参和实参共享同一数组,因此当形参变化时,形参和实参共享的数组就发生了变化,即实参也随之变化。

4.程序设计如下:

#include"stdio.h"

#include"stdlib.h"

#include"conio.h"

#include"string.h"

#defineK8

#defineERROR0

#defineOK1

charkm[K][7]。

//科目

intKM=0。

//科目数

intn=0。

//人数

intY=20。

//每页显示的人数

/*单链表结构*/

typedefstructLNode

{

charID[8]。

//学号

charname[8]。

//姓名

charsex[3]。

//性别

charage[4]。

//年龄

charcj[K][6]。

//成绩

structLNode*next。

}*LinkList。

LinkListInsert(LinkListhead)。

LinkListsort(LinkListhead,intx)。

voidm(intx)。

/*创建一个带头结点的空链表*/

LinkListcreate(void)

{LinkListL。

L=(LinkList)malloc(sizeof(structLNode))。

if(L!

=NULL)L->next=NULL。

returnL。

}

/*设置科目:

返回科目数*/

intsetKM()

{inti=0,kk=KM。

charx[1],s,y[1]。

if(KM>0)

{printf("当前设置:

")。

for(i=0。

i

i++)

{if(i%4==0)printf("\n\n")。

printf("%d.%-5s",i+1,km[i])。

}

printf("0-退出最大值:

%d",K)。

}

if(KM>0)

{printf("\n\n设置科目数:

")。

scanf("%s",x)。

if(atoi(x)==0)returnKM。

}

while(atoi(x)<1||atoi(x)>K)

{system("cls")。

m

(1)。

if(KM>0)

{printf("输入不合法!

")。

for(i=0。

i

i++)

{if(i%4==0)printf("\n\n")。

printf("%d.%-5s",i+1,km[i])。

}

printf("0-退出最大值:

%d",K)。

}else

printf("没有资料,请设置资料!

\n")。

printf("\n设置科目数:

")。

scanf("%s",x)。

if(atoi(x)==0)returnKM。

}

if(KM>0)

{printf("\n真的要修改吗?

(Y/N)")。

s=getch()。

if(s!

='y'&&s!

='Y')returnkk。

}

if(atoi(x)>KM)

{do

{if(KM==0)s='y'。

else

{printf("\n是否保留原来设置?

(Y/N)")。

s=getch()。

}

if(s=='y'||s=='Y')

{for(i=KM。

i

i++)

{printf("\n输入第%d门科目名称:

",i+1)。

gets(km[i])。

while(strlen(km[i])==0||strlen(km[i])>7)gets(km[i])。

}}

elseif(s=='n'||s=='N')

{for(i=0。

i

i++)

{printf("\n输入第%d门科目名称:

",i+1)。

gets(km[i])。

while(strlen(km[i])==0||strlen(km[i])>7)gets(km[i])。

}}

}while(s!

='y'&&s!

='Y'&&s!

='n'&&s!

='N')。

}

else

{do

{system("cls")。

m

(1)。

printf("当前设置:

")。

for(i=0。

i

i++)

{if(i%4==0)printf("\n\n")。

printf("%d.%-5s",i+1,km[i])。

}

printf("\n\n输入需要修改科目的序号:

")。

scanf("%s",y)。

if(atoi(y)==0)returnkk。

if(atoi(y)>0&&atoi(y)<=atoi(x))

{printf("\n输入第%d门科目名称:

",atoi(y))。

gets(km[atoi(y)-1])。

gets(km[atoi(y)-1])。

while(strlen(km[atoi(y)-1])==0||strlen(km[atoi(y)-1])>7)

{printf("输入不合法!

\n请重新输入第%d门科目名称:

",atoi(y))。

gets(km[atoi(y)-1])。

}}

}while(atoi(y)<1||atoi(y)>atoi(x))。

}

returnatoi(x)。

}

/*读入数据*/

intloadkm()

{inti。

FILE*fp。

if((fp=fopen("km.txt","r+"))==NULL)fp=fopen("km.txt","w+")。

for(i=0。

!

feof(fp)。

i++)

{fgets(km[i],7,fp)。

fscanf(fp,"")。

if(strlen(km[i])!

=0)KM++。

}

fclose(fp)。

returnOK。

}

LinkListload(LinkListhead)

{inti=0,j。

LinkLists,t,p。

FILE*fp。

loadkm()。

if((fp=fopen("data.txt","r+"))==NULL)returnhead。

if(fgetc(fp)==EOF)

{system("cls")。

m

(1)。

while(KM==0)

{system("cls")。

m

(1)。

printf("没有资料,请设置资料!

\n")。

KM=setKM()。

printf("\n")。

}

system("cls")。

m

(1)。

printf("添加数据:

\n")。

Insert(head)。

returnhead。

}

//fseek(fp,0L,0)。

rewind(fp)。

p=(LinkList)malloc(sizeof(structLNode))。

fscanf(fp,"%s",p->ID)。

fgets(p->name,8,fp)。

fscanf(fp,"\t%s%s",p->sex,p->age)。

for(i=0。

i

i++)fscanf(fp,"%s",p->cj[i])。

fscanf(fp,"\n")。

for(i=KM。

i

i++)strcpy(p->cj[i],"0")。

p->next=NULL。

head->next=p。

while(!

feof(fp))

{p=p->next。

p=(LinkList)malloc(sizeof(structLNode))。

fscanf(fp,"%s",p->ID)。

fgets(p->name,8,fp)。

fscanf(fp,"\t%s%s",p->sex,p->age)。

for(i=0。

i

i++)fscanf(fp,"%s",p->cj[i])。

fscanf(fp,"\n")。

for(i=KM。

i

i++)strcpy(p->cj[i],"0")。

p->next=NULL。

i=j=0。

s=head。

while(atol(s->ID)<=atol(p->ID)&&p->next)

{s=s->next。

i++。

}

s=head。

while(s->next&&j

{s=s->next。

j++。

}

t=s->next。

s->next=p。

p->next=t。

}

s=head。

i=0。

while(s->next)

{s=s->next。

i++。

n=i。

}

fclose(fp)。

returnhead。

}

/*保存文件*/

intsave(LinkListhead)

{inti。

LinkListp=head->next。

FILE*fp,*fpp。

if((fp=fopen("data.txt","w+"))==NULL)returnERROR。

if((fpp=fopen("km.txt","w+"))==NULL)returnERROR。

for(i=0。

i

i++)

{fprintf(fpp,"%s",km[i])。

fprintf(fpp,"")。

}

while(p)

{

fprintf(fp,"%s",p->ID)。

for(i=0。

i<8-(int)strlen(p->ID)。

i++)fprintf(fp,"")。

fputs(p->name,fp)。

for(i=0。

i<8-(int)strlen(p->name)。

i++)fprintf(fp,"")。

fprintf(fp,"%s%s",p->sex,p->age)。

for(i=0。

i

i++)fprintf(fp,"%s",p->cj[i])。

fprintf(fp,"\n")。

p=p->next。

}

fclose(fp)。

fclose(fpp)。

returnOK。

}

/*平均成绩*/

doublepj(LinkListp)

{inti。

doublepj=0。

for(i=0。

i

i++)

pj+=atof(p->cj[i])。

pj/=KM。

returnpj。

}

/*排头*/

bt()

{inti。

printf("学号\t姓名\t性别年龄")。

for(i=0。

i

i++)printf("%-5s",km[i])。

printf("平均\n")。

printf("-------------------------")。

if(KM<9)

{for(i=0。

i

i++)printf("------")。

printf("\n")。

}

else

for(i=0。

i

i++)printf("------")。

}

/*输出当前指针信息*/

voidput(LinkListp)

{inti。

printf("%s\t",p->ID)。

printf("%s\t",p->name)。

printf("%s",p->sex)。

printf("%3d",atoi(p->age))。

for(i=0。

i

i++)

{if(atof(p->cj[i])<10)printf("%-5g",atof(p->cj[i]))。

elseprintf("%-6g",atof(p->cj[i]))。

}

if(pj(p)<10)printf("%1.2f\n",pj(p))。

elseprintf("%2.2f\n",pj(p))。

}

intpdd(charx[],intz)

{inty=strlen(x),k,i。

if(z==1)

{for(i=0。

i

i++)if(x[i]>57||x[i]<48)returnERROR。

if(y>7)returnERROR。

}

if(z==2)

{for(i=0。

i

i++)

{if(x[i]==46)k++。

if(x[i]>57||x[i]<46||x[i]==47||k==2)returnERROR。

}}

returnOK。

}

/*输出信息*/

voidall(LinkListhead,intx)

{LinkListp=head->next。

inti,j=0。

chara1[4],a2[4],t,k[1],c1[6],c2[6],tmp[3],ID1[8],ID2[8]。

doublez[K]={0},zpj=0.0。

charn[10],s[3]。

if(x==0)

{system("cls")。

bt()。

while(p)

{put(p)。

for(i=0。

i

i++)z[i]+=atof(p->cj[i])。

j++。

if(j%Y==0)

{if(j!

=0)

{printf("-------------------------")。

if(KM<8)

{for(i=0。

i

i++)printf("------")。

printf("\n")。

}

else

for(i=0。

i

i++)printf("------")。

printf("按任意键继续")。

getch()。

system("cls")。

bt()。

}}

p=p->next。

}}

if(x==1)

{printf("按学号搜索")。

printf("\n\n学号范围:

")。

scanf("%s",ID1)。

scanf("%s",ID2)。

while(pdd(ID1,1)==ERROR||pdd(ID2,1)==ERROR)

{system("cls")。

m

(2)。

printf("输入错误!

")。

printf("\n\n学号范围:

")。

scanf("%s",ID1)。

scanf("%s",ID2)。

}

if(atol(ID1)>atol(ID2))

{strcpy(tmp,ID1)。

strcpy(ID1,ID2)。

strcpy(ID2,tmp)。

}

system("cls")。

bt()。

while(p)

{if(atol(ID1)<=atol(p->ID)&&atol(ID2)>=atol(p->ID))

{put(p)。

for(i=0。

i

i++)z[i]+=atof(p->cj[i])。

j++。

if(j%Y==0)

{if(j!

=0)

{printf("-------------------------")。

if(KM<8)

{for(i=0。

i

i++)printf("------")。

printf("\n")。

}

else

for(i=0。

i

i++)printf("------")。

printf("按任意键继续")。

getch()。

system("cls")。

bt()。

}}}

p=p->next。

}}

if(x==2)

{printf("按姓名搜索")。

printf("\n\n姓名:

")。

scanf("%s",n)。

system("cls")。

bt()。

while(p!

=NULL)

{if(strcmp(n,p->name)==0)

{put(p)。

for(i=0。

i

i++)z[i]+=atof(p->cj[i])。

j++。

if(j%Y==0)

{if(j!

=0)

{printf("-------------------------")。

if(KM<8)

{

for(i=0。

i

i++)printf("------")。

printf("\n")。

}

else

for(i=0。

i

i++)printf("------")。

printf("按任意键继续")。

getch()。

system("cls")。

bt()。

}}}

p=p->next。

}}

if(x==3)

{

printf("按年龄搜索")。

printf("\n\n年龄范围:

")。

scanf("%s",a1)。

scanf("%s",a2)。

while(pdd(a2,1)==ERROR||pdd(a1,1)==ERROR||atoi(a1)>100||atoi(a2)>100)

{printf("输入错误!

")。

printf("\n\n年龄范围:

")。

scanf("%s",a1)。

scanf("%s",a2)。

}

if(atof(a1)>atof(a2))

{strcpy(tmp,a1)。

strcpy(a1,a2)。

strcpy(a2,tmp)。

}

system("cls")。

bt()。

while(p)

{if(atoi(p->age)>=atoi(a1))

{if(atoi(p->age)<=atoi(a2))

{put(p)。

for(i=0。

i

i++)z[i]+=atof(p->cj[i])。

j++。

if(j%Y==0)

{if(j!

=0)

{printf("-------------------------")。

if(KM<8)

{

for(i=0。

i

i++)printf("------")。

printf("\n")。

}

else

for(i=0。

i

i++)printf("------")。

printf("按任意键继续")。

getch()。

system("cls")。

bt()。

}

}

}

}

p=p->next。

}

}

if(x==4)

{

printf("按性别搜索\n\n1.男2.女\n\n性别:

")。

t=getch()。

if(t=='1')strcpy(s,"男")。

elseif(t=='2')strcpy(s,"女")。

elsestrcpy(s,"男")。

system("cls")。

bt()。

while(p)

{

if(strcmp(s,p->sex)==0)

{

put(p)。

for(i=0。

i

i++)z[i]+=atof(p->cj[i])。

j++。

if(j%Y==0)

{

if(j!

=0)

{

printf("-------------------------")。

if(KM<8)

{

for(i=0。

i

i++)printf("------")。

printf("\n")。

}

els

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

当前位置:首页 > 人文社科 > 法律资料

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

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