C语言学生信息管理系统, 小迪设计
这么热的暑假,我们却还在补课。。。c语言进行时,希望自己c语言编程能有所提升吧!我的第一个比较大的c语言程序,做的是一个学生成绩管理系统。这是我的c语言代码。。。嘿嘿
代码开始了!
/*程序课题:学生成绩管理系统
设计人:小迪
设计时间:2014年7月7日*/
#include <stdio.h>
struct stu
{
char name[20];/*定义姓名*/
int cla;/*定义班级*/
long stunum;/*定义学号*/
float grade[6];/*定义一个数组记录学生语,数,外,物,化,生六科成绩*/
int sum;/*定义学生六科成绩总分*/
struct stu*next;/*定意指针,指向下一个结构体变量*/
}
int main()
{
printf("Welcome to the student grades management system, the creator Andyli\n");
printf("\n");
printf(" 选 择 功 能 编号\n");
printf(" 录 入 成 绩 1\n");
printf(" 添 加 学 生 2\n");
printf(" 查 询 成 绩 3\n");
printf(" 修 改 信 息 4\n");
printf(" 统 计 成 绩 5\n");
printf(" 删 除 成 绩 6\n");
printf(" 退 出 程 序 7\n");
printf("\n");
printf("\n");
printf("Please input the number to choose what you want to do.\n");
int choose;
scanf("%d", &choose);
if(choose < '1' && choose > '7')
printf("Please input a number between 1 to 9!");
switch(choose){
case 1 :
entry(); break;
case 2 :
addmark(); break;
case 3 :
search(); break;
case 4 :
insertmark(); break;
case 5 :
countmark(); break;
case 6 :
deletemark(); break;
case 7 :
break;
// 如果执行完一次还想再度修改,要怎样
}
void entry(void){
printf("You have choose the entry function.\n");
printf("Please choose the entry methods\n");
/*int met;
scanf("%d", &met);
if(met == 1)
printf("Input the data in "data.in", and put it at the same catalog\n")
//从文件读入信息函数
int i, j, t
FILE *fp
fp = fopen("data.in", "r");
//处理错误
if(fp == NULL){
fprintf(stderr, "Can't open the file!\n");
fclose(fp);
return 1;//1 表示文件读写失败
} */// 怎样从文件中读入数据
}
}
额,还没写完,才写了一上午,接下来会努力的!^-^
开心记录每一天,我爱百度空间。
。。。。。。。。。。。。。。。。。。。。。。。。。
成品终于出来了,虽然最终还是得依靠百度,可是我真的改了很多,并且试调通过了!
#include <stdio.h>
#include <malloc.h>
#include <conio.h>
#include <stdlib.h>
//链表单元定义
struct student{
int id;
float score;
struct student *next;
} *head,*pthis;
//成绩录入函数input()
void input(){
struct student *tmp;
printf("\n\n请输入学生的信息输入学号为0结束:\n");
do
{
printf("ID\t成绩\n");
if((tmp=(struct student*)malloc(sizeof(struct student)))==NULL){
printf("\n错误!不能申请所需的内存!\n");
exit(0);
}
scanf("%d\t%f",&tmp->id,&tmp->score);
tmp->next=NULL;
if(tmp->id!=0){
if(head==NULL){
head=tmp;
pthis=head;
}
}
else{
pthis->next=tmp;
pthis=pthis->next;
}
}
while(tmp->id!=0);
free(tmp);
}
//成绩查询函数search(int id)
void search(int id)
{
printf("\n\n查询结果\n");
printf("ID\t成绩\n");
printf("-------------------------------\n");
if(head==NULL){
printf("\n错误!没有数据!\n");
}
pthis=head;
while(pthis!=NULL){
if(pthis->id==id){
printf("%d\t%.2f\n",pthis->id,pthis->score);
}
else{
pthis=pthis->next;
}
}
printf("\n没有找到!\n");
}
//打印学生成绩
void list()
{
printf("\n\n数据列表\n");
printf("ID\t成绩\n");
printf("-------------------------------\n");
if(head==NULL){
printf("错误,没有数据!\n");
}
pthis=head;
while(pthis!=NULL){
printf("%d\t%.2f\n",pthis->id,pthis->score);
pthis=pthis->next;
}
}
//添加学生成绩
void insert()
{
int i,p;
struct student *tmp;
if(head==NULL){
printf("\n\n数据不存在,无法插入!\n");
}
printf("\n请输入插入点:\n");
scanf("%d",&p);
if(p<0){
printf("输入不合法!");
}
printf("\n\n请输入学生的信息:\nID\t成绩\n");
if((tmp=(struct student*)malloc(sizeof(struct student)))==NULL){
printf("\n错误!不能申请所需的内存!\n");
exit(0);
}
scanf("%d\t%f",&tmp->id,&tmp->score);
tmp->next=NULL;
if(tmp->id!=0){
pthis=head;
if(p==0){
tmp->next=head;
head=tmp;
}
}
else{
for(i=0;i<p-1;i++){
if(pthis->next->next==NULL){
printf("\n找不到插入点,您输入的数据太大!\n");
}
pthis=pthis->next;
}
tmp->next=pthis->next;
pthis->next=tmp;
}
}
//成绩删除函数del()
void del()
{
int p,i;
struct student *tmp;
if(head==NULL)
printf("\n\n没有数据,无法删除!\n");
printf("\n\n请输入要删除的记录号:\n");
scanf("%d",&p);
if(p<0)
printf("\n输入不合法!\n");
if(p==0){
pthis=head;
head=pthis->next;
free(pthis);
pthis=head;
}
else{
pthis=head;
for(i=0;i<p-1;i++){
pthis=pthis->next;
if(pthis->next==NULL)
printf("\n\n指定记录不存在,无法删除!\n");
}
tmp=pthis->next;
pthis->next=pthis->next->next;
free(tmp);
}
}
//程序主函数
int main()
{
int command=0;
int id=0;
do
{
printf("Welcome to the student grades management system, the creator Andyli\n");
printf("\n");
printf(" 选 择 功 能 编号\n");
printf(" 录 入 成 绩 1\n");
printf(" 查 询 成 绩 2\n");
printf(" 打 印 成 绩 3\n");
printf(" 插 入 成 绩 4\n");
printf(" 删 除 成 绩 5\n");
printf(" 退 出 程 序 6\n");
printf("\n");
printf("\n");
printf("Please input the number to choose what you want to do.\n");
int command;
scanf("%d", &command);
//命令处理
switch(command){
case 1:
if(head==NULL){
input();
break;
}
else{
printf("\n\n数据已经存在!\n");
break;
}
case 2:
printf("\n\n要查询的ID:");
scanf("%d",&id);
search(id);
break;
case 3:
list();
break;
case 4:
insert();
break;
case 5:
del();
break;
}
}
while(command != 6);
return 0;
}
嘿嘿,接下来又要做更深的了,继续加油!

浙公网安备 33010602011771号