当前位置:编程学习 > C/C++ >>

求C语言程序????

·········C语言C语言

C语言
补充:学生管理系统
答案:恩,我就是ChooserFan

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 100

int menu( );
void data_input( );
int read_data(struct student stu[]);

void Delete_data();//增加的功能--删除功能

void printf_data(struct student stu[], int n);
void sort_num(struct student stu[], int n);
void sort_score(struct student stu[], int n);
void search_num(struct student stu[], int n, char find_num[]);
void search_name(struct student stu[], int n, char find_name[]);
void count_academy(struct student stu[], int n, char count_ac[]);

struct student
{
char num[14];
char name[16];
int age;
int score;
char academy[20];
};

void main( )
{
int item, n, flag = 121;
struct student stu[N];
char find_num[14], find_name[16], count_ac[20];

while ((flag == 121) || (flag == 89)) //121是'y'的ASCII码,89是'Y'的ASCII码
{ item = menu( );
switch(item)
{
case 1:
data_input();
break;
case 2:
n = read_data(stu);
sort_num(stu, n);
printf_data(stu,n);
break;
case 3:
n = read_data(stu);
sort_score(stu, n);
printf_data(stu,n);
break;
case 4:
n = read_data(stu);
sort_num(stu, n);
printf("\n请输入待查学生的学号:");
scanf("%s", find_num);
search_num(stu, n, find_num);
break;
case 5:
n = read_data(stu);
printf("\n请输入待查学生的姓名:");
scanf("%s", find_name);
search_name(stu, n, find_name);
break;
case 6:
n = read_data(stu);
printf("\n请输入要统计的学院名称:");
scanf("%s", count_ac);
count_academy(stu, n, count_ac);
break;
case 7:
Delete_data();//函数调用
break;
case 0:
printf("\n谢谢您的使用,再见!\n");
exit(0);
}
printf("\n是否继续?(按Y继续,否则退出):\n");
flag = getch();
if ((flag != 121) && (flag != 89))
{ printf("\n谢谢您的使用,再见!\n");
exit(0);
}
}
}

int menu( ) //展示菜单,返回用户的输入选项
{
printf("\n1--输入学生数据");
printf("\n2--依据学号查询数据");
printf("\n3--依据成绩查询数据 ");
printf("\n4--依据学号查询数据");
printf("\n5--依据姓名查询数据");
printf("\n6--统计某学院的人数");
printf("\n7--删除");
printf("\n0--退出");
//int item;
scanf("%d", &item);
return item;

}

void data_input() //学生信息录入,数据保存在文件student_info.txt中
{
int i = 0, n;
FILE *fp;
struct student stu[N];

if((fp = fopen("student_info.txt", "a")) == NULL)
{
printf("\n文件无法打开,程序退出!\n");
exit(0);
}
printf("\n请输入记录个数: ");
scanf("%d", &n);
printf("\n%14s%16s%6s%10s%20s\n", "学号", "姓名", "年龄", "入学成绩", "学院");
for(i = 0; i < n; i++)
{
printf("输入第%d个学生记录:\n", i + 1);
scanf("%s%s%d%d%s", stu[i].num, stu[i].name, &stu[i].age, &stu[i].score, stu[i].academy);
fprintf(fp, "%14s%16s%6d%10d%20s\n", stu[i].num, stu[i].name, stu[i].age, stu[i].score, stu[i].academy);
}
fclose(fp);
}

int read_data(struct student stu[]) //从文件student_info.txt中读出数据
{
FILE *fp;
int i = 0;

if((fp = fopen("student_info.txt","r")) == NULL)
{
printf("\n文件无法打开,程序退出!\n");
exit(0);
}
while(fscanf(fp, "%s%s%d%d%s", stu[i].num, stu[i].name, &stu[i].age, &stu[i].score, stu[i].academy) > 1)
i++;
return i;
}

void printf_data(struct student stu[ ], int n)
{
for(i=0;i<N;i++)
printf("num:%c name:%c age:%d score:%d academy:%c\n",stu[i].num, stu[i].name, &stu[i].age, &stu[i].score, stu[i].academy);
}

void sort_num(struct student stu[], int n)//按学号排序
{
for(j=1;j<=n;j++)
for(i=1;i<=n-j;i++)
if(stu[i].num>stu[i+1].num)
{
t=stu[i].num;
stu[i].num=stu[i+1].num;
stu[i+1].num=t;
}
printf("按照学号排序后的结果:\n");
for(i=1;i<n;i++)
printf("\n%14s%16s%6s%10s%20s\n", "学号", "姓名", "年龄", "入学成绩", "学院");

}

void sort_score(struct student stu[], int n)// 按入学成绩排序
{
for(j=1;j<=n;j++)
for(i=1;i<=n-j;i++)
if(stu[i].score>stu[i+1].score)
{
t=stu[i].score;
stu[i].score=stu[i+1].score;
stu[i+1].score=t;
}
printf("按照入学成绩排序后的结果:\n");
for(i=1;i<n;i++)
printf("\n%14s%16s%6s%10s%20s\n", "学号", "姓名", "年龄", "入学成绩", "学院");
}

void search_num(struct student stu[], int n, char find_num[]) //按学号查询(折半查找)
{
int iIndex=0;
int iStart=0;
int iEnd=n-1;
while(true)
{
iIndex = (iStart+iEnd)/2;
if(stu[iIndex]<iSeek)
{
iStart = iIndex;
}
else if(stu[iIndex]>iSeek)
{
iEnd = iIndex;
}
else
{
break;
}
}
printf("\n%14s%16s%6s%10s%20s\n", "学号", "姓名", "年龄", "入学成绩", "学院");
}

void search_name(struct student stu[], int n, char find_name[]) //按姓名查询(顺序查找)
{

//char name[16];
printf("请输入查询学生的姓名:\n");
gets(name); /*获得学生姓名*/
for(i=0;i<N;i++)
{
if (strcmp(name,stu[i].name)==0)
{
printf("num:%c name:%c age:%d score:%d academy:%c\n",stu[i].num, stu[i].name, &stu[i].age, &stu[i].score, stu[i].academy);
break;
}
}
if (i>=m+n)
printf("******查无此人******\n");

}

void count_academy(struct student stu[], int n, char count_ac[]) // 按学院统计人数
{
int m=0;
printf("请输入要查学的学院的名称");
gets(academy);
for(i=0;i<N;i++)
{
if (strcmp(academy,stu[i].academy)==0 )
{
m++;
return m;
}
}
if (i>=n)
printf("这个学院总共有%d个学生:\n",m);

}


void Delete_data() //增加的功能函数
{
printf("请输入要删除的学号:");
gets(num);
for(i=0;i<N;i++)
{
if (strcmp(num,stu[i].num)==0 )
{
stu[i].num="", stu[i].name="", stu[i].age="", stu[i].score="", stu[i].academy=""

}
}

}

啥意思?

void main()

{printf("Hello World!");}

老兄 说明白点撒

有C++做的!用c语言太复杂了!

#include "stdio.h" /*I/O函数*/
#include "stdlib.h" /*其它说明*/
#include "string.h" /*字符串函数*/
#include "conio.h" /*屏幕操作函数*/
#include "mem.h" /*内存操作函数*/
#include "ctype.h" /*字符操作函数*/
#include "alloc.h" /*动态地址分配函数*/
#define N 3 /*定义常数*/
typedef struct z1 /*定义数据结构*/
{
char no[11];
char name[15];
int score[N];
float sum;
float average;
int order;
struct z1 *next;
}STUDENT;

STUDENT *init(); /*初始化函数*/
STUDENT *create(); /*创建链表*/
STUDENT *delete(STU

上一个:怎样学好C语言?
下一个:怎么学习C语言?

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,