谁可以帮我做一个C语言课程设计啊,要求一个主函数含三个简单的程序

2024-12-13 17:05:38
推荐回答(2个)
回答1:

要做什么课设啊?
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
#define M 10
int num; //计数
struct student
{
char xuehao[10]; //学号
char name[10]; //姓名
char sex[8]; //性别
char birth[20]; //出生年月
char jiguan[30]; //籍贯
char tel[30]; //电话
int score; //成绩
}student[M];

char headline[80]; //全局变量

void read1()
{
FILE *fp; //文件指针
int i=0;
fp=fopen("jz0112.txt","r"); //打开文件
if(fp==NULL)
{
printf("不能找到文件,请检查!\n");
return;
}
fgets(headline,80,fp); //读第一行的函数
puts(headline);
while(!feof(fp)) //判断文件是否结束
//for(i=0;i {
fscanf(fp,"%s%s%s%s%s%s%d",student[i].xuehao,student[i].name,student[i].sex,
student[i].birth,student[i].jiguan,student[i].tel,&student[i].score);
i++; //fscanf读两个空白字符之间的字符
}
num=i;
fclose(fp); //关闭文件
for(i=0;i printf("%-10s%-8s%6s%16s%16s%16s%6d\n",student[i].xuehao,student[i].name,student[i].sex,
student[i].birth,student[i].jiguan,student[i].tel,student[i].score);
}

void find_xuehao() //按学号查询
{
char xuehao[10];
int i;
int flag=0;
printf("请输入学号:");
scanf("%s",xuehao);
for(i=0;i if(strcmp(xuehao,student[i].xuehao)==0)
{
flag=1;
printf("%-10s%-8s%6s%16s%16s%16s%6d\n",student[i].xuehao,student[i].name,student[i].sex,
student[i].birth,student[i].jiguan,student[i].tel,student[i].score);
break;
}
if(flag==0)
printf("\n无此信息\n");

}

void find_name() //按姓名查询
{
char name[8];
int i;
int flag=0;
printf("请输入姓名:");
scanf("%s",name);
for(i=0;i if(strcmp(name,student[i].name)==0)
{
flag=1;
printf("%-10s%-8s%6s%16s%16s%16s%6d\n",student[i].xuehao,student[i].name,student[i].sex,
student[i].birth,student[i].jiguan,student[i].tel,student[i].score);
break;
}

if(flag==0)
printf("\n无此信息\n");
}

void all() //显示全部
{
int i;
for(i=0;i {
printf("%-10s%-8s%6s%16s%16s%16s%6d\n",student[i].xuehao,student[i].name,student[i].sex,
student[i].birth,student[i].jiguan,student[i].tel,student[i].score);
}
}

void find()
{
int b;
printf("\n*************************************************************************\n");
printf(" 1 按学号查询 2按姓名查询 3显示全部 4退出 \n");
printf("\n*************************************************************************\n");
printf("请选择:");
scanf("%d",&b);
switch(b)
{
case 1:find_xuehao();break;
case 2:find_name();break;
case 3:all();break;
case 4:return;
}
}

void sort_name() //按姓名排序
{
char name[M][12],t[12];
int i,j;
for(i=0;i strcpy(name[i],student[i].name);
for(j=1;j for(i=0;i if(strcmp(name[i],name[i+1])>0)
{
strcpy(t,name[i]);
strcpy(name[i],name[i+1]);
strcpy(name[i+1],t);
}
for(i=0;i for(j=0;j if(strcmp(name[i],student[j].name)==0)
printf("%-10s%-8s%6s%16s%16s%16s%6d\n",student[j].xuehao,student[j].name,student[j].sex,
student[j].birth,student[j].jiguan,student[j].tel,student[j].score);
}

void sort_score() //按分数排序
{
int i,j,t,a[M];
for(i=0;i a[i]=student[i].score;
for(j=1;j for(i=0;i if(a[i] {
t=a[i];
a[i]=a[i+1];
a[i+1]=t;
}

for(i=0;i for(j=0;j if(a[i]==student[j].score)
printf("\n%-10s%-8s%6s%14s%16s%16s%6d",student[j].xuehao,student[j].name,student[j].sex,
student[j].birth,student[j].jiguan,student[j].tel,student[j].score);

}

void sort() //排序
{
int b;
printf("\n*************************************************************************\n");
printf(" 1 按姓名排序 2 按分数排序 3 退出 \n");
printf("\n*************************************************************************\n");
printf("请选择:");
scanf("%d",&b);
switch(b)
{
case 1:sort_name();break;
case 2:sort_score();break;
case 3:return;
}
}

void add() //添加
{
int i;
int flag=0;
char add[10];
printf("请输入你要修改的学生的学号:");
scanf("%s",add);
for(i=0;i if(strcmp(student[i].xuehao,add)==0)
{
flag=1;
printf("此信息已存在,不能添加!\n");
printf("%-10s%-8s%6s%14s%16s%16s%6d",student[i].xuehao,student[i].name,student[i].sex,
student[i].birth,student[i].jiguan,student[i].tel,student[i].score);break;
}
if(flag==0)
{
printf("\n无此学生信息,请添加信息:");
scanf("%s%s%s%s%s%s%d",student[num].xuehao,student[num].name,student[num].sex,
student[num].birth,student[num].jiguan,student[num].tel,&student[num].score);
num++;
for(i=0;i printf("\n%-10s%-8s%6s%14s%16s%16s%6d",student[i].xuehao,student[i].name,student[i].sex,
student[i].birth,student[i].jiguan,student[i].tel,student[i].score);
}
}

void Delete_name() //按姓名删除
{
int i;
int flag=0;
char name[10];
printf("请输入要删除的姓名:");
scanf("%s",name);
for(i=0;i if(strcmp(student[i].name,name)==0)
{
flag=1;
for(;i student[i]=student[i+1];
printf("此信息存在,将被删除。\n");
}
for(i=0;i printf("\n%-10s%-8s%6s%14s%16s%16s%6d",student[i].xuehao,student[i].name,student[i].sex,
student[i].birth,student[i].jiguan,student[i].tel,student[i].score);
if(flag==0)
{
printf("\n无此学生信息,请确认!\n");
}
}

void Delete_xuehao() //按学号删除
{
int i;
int flag=0;
char xuehao[10];
printf("请输入要删除的学号:");
scanf("%s",xuehao);
for(i=0;i if(strcmp(student[i].xuehao,xuehao)==0)
{
flag=1;
for(;i student[i]=student[i+1];
printf("此信息存在,将被删除。\n");
}
for(i=0;i printf("\n%-10s%-8s%6s%14s%16s%16s%6d",student[i].xuehao,student[i].name,student[i].sex,
student[i].birth,student[i].jiguan,student[i].tel,student[i].score);
if(flag==0)
{
printf("\n无此学生信息,请确认!\n");
}

}

void Delete() //删除
{
int b;
printf("\n*************************************************************************\n");
printf(" 1 按姓名删除 2 按学号删除 3 退出 \n");
printf("\n*************************************************************************\n");
printf("请选择:");
scanf("%d",&b);
switch(b)
{
case 1:Delete_name();break;
case 2:Delete_xuehao();break;
case 3:return;
}
}

void modify() //修改
{
int i;
int flag=0;
char modify[10];
printf("请输入你要修改的学生的学号:");
scanf("%s",modify);
for(i=0;i if(strcmp(student[i].xuehao,modify)==0)
{
flag=1;
printf("学号 姓名 性别 出生年月 籍贯 电话 成绩\n");
printf("%-10s%-8s%6s%14s%16s%16s%6d",student[i].xuehao,student[i].name,student[i].sex,
student[i].birth,student[i].jiguan,student[i].tel,student[i].score);break;
}
if(flag==0)
{
printf("\n无此学生信息\n");
return;
}

printf("\n要修改学生的姓名:\n");
printf("student[i].name=");
scanf("%s",student[i].name);

printf("\n要修改学生的性别:\n");
printf("student[i].sex=");
scanf("%s",student[i].sex);

printf("\n要修改学生的出生年月:\n");
printf("student[i].birth=");
scanf("%s",student[i].birth);

printf("\n要修改学生的籍贯:\n");
printf("student[i].jiguan=");
scanf("%s",student[i].jiguan);

printf("\n要修改学生的电话:\n");
printf("student[i].tel=");
scanf("%s",student[i].tel);

printf("\n要修改学生的成绩:\n");
printf("student[i].score=");
scanf("%d",&student[i].score);

for(i=0;i printf("\n%-10s%-8s%6s%14s%16s%16s%6d",student[i].xuehao,student[i].name,student[i].sex,
student[i].birth,student[i].jiguan,student[i].tel,student[i].score);
}

void classify_male() //按男分类
{
int i;
FILE *fp;
fp=fopen ("male.txt","w");

if (fp==NULL)
{
printf("不能找到文件,请检查!");
return ;
}

fputs(headline,fp);

for(i=0;i{
if(strcmp(student[i].sex,"男")==0)
{
printf("\n%-10s%-8s%6s%14s%16s%16s%6d",student[i].xuehao,student[i].name,student[i].sex,
student[i].birth,student[i].jiguan,student[i].tel,student[i].score);
fprintf(fp,"\n%-10s%-8s%6s%14s%16s%16s%6d",student[i].xuehao,student[i].name,student[i].sex,
student[i].birth,student[i].jiguan,student[i].tel,student[i].score);

}

}
fclose(fp);

}

void classify_female() //按女分类
{
int i;
FILE *fp1;
fp1=fopen("female.txt","w");

if (fp1==NULL)
{
printf("不能找到文件,请检查!");
return;
}
fputs(headline,fp1);

for(i=0;i {
if(strcmp(student[i].sex,"女")==0)
{
printf("\n%-10s%-8s%6s%14s%16s%16s%6d",student[i].xuehao,student[i].name,student[i].sex,
student[i].birth,student[i].jiguan,student[i].tel,student[i].score);
fprintf(fp1,"\n%-10s%-8s%6s%14s%16s%16s%6d",student[i].xuehao,student[i].name,student[i].sex,
student[i].birth,student[i].jiguan,student[i].tel,student[i].score);
}
}
fclose(fp1);
}

void classify() //分类
{
int b;
printf("\n*************************************************************************\n");
printf(" 1 按男分类 2 按女分类 3 退出 \n");
printf("\n*************************************************************************\n");
printf("请选择:");
scanf("%d",&b);
switch(b)
{
case 1:classify_male();break;
case 2:classify_female();break;
case 3:return;
}
}

void write() //写函数,将输出函数写入文本文件
{
FILE *fp;
int i=0;
fp=fopen("jz0112gyq.txt","w");
if(fp==NULL)
{
printf("不能找到文件,请检查!\n");
return;
}
fputs(headline,fp);
for(i=0;i fprintf(fp,"\n%-10s%-8s%6s%14s%16s%16s%6d",student[i].xuehao,student[i].name,
student[i].sex,student[i].birth,student[i].jiguan,student[i].tel,student[i].score);
fclose(fp);
}

void main()
{
int i;
read1();
while(1)
{
printf("\n**************简易学生信息管理系统的设计**************\n");
printf("1 查询 2 排序 3 添加\n");
printf("4 删除 5 修改 6 分类\n");
printf(" 0 退出 \n");
printf("\n******************************************************\n");
printf("请选择:");
scanf("%d",&i);
switch(i)
{
case 1:find();break;
case 2:sort();break;
case 3:add();write();break;
case 4:Delete();write();break;
case 5:modify();write();break;
case 6:classify();break;
case 0:return;
}
}
}
这是我的课设程序。简易学生信息管理系统。

回答2:

能说具体点吗,什么是c语言课程设计,三个简单的程序分别需要些什么功能。

//
#include
main()
{
int i=0;
int a=1,b=2;
for(i;i<10;i++)
printf("the nem is :%d\n",i);//一个小功能,打印1-10

if(a>b)
printf("a大于b\n");//比大小
else if(a=b)
printf("a等于b\n");//
else
printf("a小于b\n");//

scanf("you age is%d",&i);//显示输出
printf("you age is%d",i);
}