学生成绩管理系统【c】
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
#define MAX 2000
struct Student
{
int no; /*学号*/
char name[8]; /*姓名*/
char sex; /*性别*/
char phone[8];/*联系电话*/
int mark[4]; /*语文、数学、外语、考试平均成绩*/
};
int total; /*总人数*/
char password[20];/*密码*/
struct Student student[MAX];
/**************************************************************************/
void Init(); /*初始化,文件不存在,则建立,同时记录下文件中的记录数 */
int get_menu_choice() ;/*接受菜单选择 */
void menu() ;/*菜单响应 */
void Show_menu(); /*显示菜单 */
FILE *file_operate(char *mode); /*文件操作 */
void Delete(FILE *fp); /*删除记录 */
void Alter(FILE *fp); /*修改记录信息 */
void Show(); /*显示打印所有的信息 */
void Save(); /*备份信息到文件 */
void Find(); /*查找记录的函数 */
void Input(FILE *fp); /*向管理系统中增加记录 */
int Inputoneperson(int i); /*向数组增加一条记录 */
void set_psw(); /*设置密码 */
int psw_check(); /*密码验证 */
/*下面函数为了简化部分工作从上面函数中划分出来的功能 */
/**************************************************************************/
void exchange(int i,int j);/*交换两个人的所有信息 */
void PrintTitle(); /*打印头信息 */
void clear(); /*清屏 */
void Showoneperson(int i); /*显示打印一个人的信息 */
int CheckNumber(int no_temp); /*检查学号是否存在,存在返回序号,不存在返回-1 */
void Inputfile(int i,FILE *fp); /*把下标为i 的记录写入文件 */
void Readfile(int i,FILE *fp); /*读一条记录从文件 */
int Sort_menu_choice();/*选择是按学号还是成绩排序*/
void Sort_menu();/*排序菜单*/
void Sort_save();/*排序后数据写入文件*/
void Sort_no();/*选择是按学号排序*/
void Sort_mark();/*选择是按成绩排序*/
int get_menu_choice()/*接受菜单选择 */
{
int menu_ch; /*菜单选项 */
do
{
printf("Select the choice:");
scanf("%d",&menu_ch);
if((menu_ch<0)||(menu_ch>9))
printf("error!");
}
while((menu_ch<0)||(menu_ch>9));
return(menu_ch);
}
void Show_menu()/*显示菜单 */
{
printf(" 欢迎使用学生成绩管理系统 \n");
printf("*************************************************************\n");
printf(" 1.显示数据 | 2.删除数据 \n");
printf(" 3 查询数据 | 4.输入数据 \n");
printf(" 5.修改数据 | 6.备份数据 \n");
printf(" 7.设置口令 | 8.数据排序 \n");
printf(" 0.退出 \n");
printf("*************************************************************\n");
}
void clear()/*清屏 */
{
system("pause");
system("cls");
}
void menu()/*菜单响应 */
{
while(1)
{
Show_menu();
switch(get_menu_choice())
{
case 1:Show();clear();
break;
case 2:Delete(file_operate("wb"));clear();
break;
case 3:Find();clear();
break;
case 4:Input(file_operate("ab"));clear();
break;
case 5:Alter(file_operate("wb"));clear();
break;
case 6:Save();clear();
break;
case 7:set_psw();clear();
break;
case 8:Sort_menu();
break;
case 0:system("cls");
printf("*****************************\n");
printf(" 欢迎使用本程序! \n");
printf("*****************************\n");
exit(0);
}
}
}
void Show()/*显示打印所有的信息 */
{
int i;
printf("有%d个记录:\n",total);
PrintTitle();
for(i=0;i<total;i++)
Showoneperson(i);
}
void Showoneperson(int i) /*显示打印一个人的信息 */
{
printf(" %8d %8s %1c %3d %3d %3d %3d \n",student[i].no,student[i].name,student[i].sex,student[i].mark[0],student[i].mark[1],student[i].mark[2],student[i].mark[3]);
}
void PrintTitle()/*打印头信息 */
{
printf("-----------------------------------------------------------------\n");
printf(" 学号 姓名 性别 语文 数学 英语 平均成绩 \n");
printf("-----------------------------------------------------------------\n");
}
void Init() /*初始化,文件不存在,则建立,同时记录下文件中的记录数 */
{
int i;
FILE *fp;
total=0;
if((fp=fopen("student.txt","rb"))==NULL)
{
fp=fopen("student.txt","ab");
clear();
menu();
}
else
{
for(i=0;feof(fp)==0;i++)
Readfile(i,fp);
}
total=i-1;
fclose(fp);
}
void Readfile(int i,FILE *fp)/*读一条记录从文件 */
{
int j;
fscanf(fp,"%8d",&student[i].no);
fscanf(fp,"%8s ",&student[i].name);
fscanf(fp,"%1c",&student[i].sex);
for(j=0;j<4;j++)
fscanf(fp,"%3d",&student[i].mark[j]);
}
int CheckNumber(int no_temp)/*检查学号是否存在,存在返回序号,不存在返回-1 */
{
int i,result;
for(i=0;i<total;i++)
{
if(student[i].no==no_temp)
{
result=1;
break;
}
}
if(result==1)
return i;
else
return -1;
}
int Inputoneperson(int i)/*向数组增加一条记录 */
{
int j,sum=0;
int no_temp;
do
{
printf("输入学号:(如10141301)");
scanf("%d",&no_temp);
if(no_temp<10141301)
printf("error!");
}
while(no_temp<10141301);
if(CheckNumber(no_temp)>0)
{
printf("Number repeatly!\n");
return 0;
}
else
{
student[i].no=no_temp;
printf("Input name(lessthan 20 numbers):");
scanf("%s",student[i].name);
printf("Sex(M/W):");
scanf("%s",&student[i].sex);
printf("\n 语文\t 数学\t 英语\n");
for(j=0;j<3;j++)
{
scanf("%d",&student[i].mark[j]);
sum=sum+student[i].mark[j];
}
student[i].mark[3]=sum/3;
PrintTitle();
Showoneperson(i);
return 1;
}
}
void Input(FILE *fp)/*向管理系统中增加记录 */
{
int i;
i=total;
if(Inputoneperson(i))
{
total++;
Inputfile(i,fp);
}
fclose(fp);
}
void Inputfile(int i,FILE *fp) /*把下标为i 的记录写入文件 */
{
int j;
fprintf(fp,"%8d",student[i].no);
fprintf(fp,"%8s ",student[i].name);
fprintf(fp,"%1c ",student[i].sex);
for(j=0;j<4;j++)
fprintf(fp,"%3d ",student[i].mark[j]);
}
void exchange(int i,int j)/*交换两个人的所有信息 */
{
int k;
int no_temp,mark_temp;
char name_temp[20],sex_temp;
no_temp=student[i].no;
student[i].no=student[j].no;
student[j].no=no_temp;
for(k=0;k<4;k++)
{
mark_temp=student[i].mark[k];
student[i].mark[k]=student[j].mark[k];
student[j].mark[k]=mark_temp;
}
strcpy(name_temp,student[i].name);
strcpy(student[i].name,student[j].name);
strcpy(student[j].name,name_temp);
sex_temp=student[i].sex;
student[i].sex=student[j].sex;
student[j].sex=sex_temp;
}
FILE *file_operate(char *mode)/*文件操作 */
{
char choice;
FILE *fp;
do
{
fflush(stdin);
if((fp=fopen("student.txt",mode))==NULL)
{
puts("Fail to open the file!");
puts("Try again!(Y/N)?");
scanf("%c",&choice);
}
}
while(choice=='y'||choice=='Y');
if(choice=='n'||choice=='N')
exit(1);
return(fp);
}
void Find()/*查找记录的函数 */
{
int i,no_temp;
FILE *fp;
fp=file_operate("rb");
for(i=0;feof(fp)==0;i++)
Readfile(i,fp);
total=i-1;
fclose(fp);
printf("Input the number that someone you want to find:(如10141303)");
scanf("%d",&no_temp);
i=CheckNumber(no_temp);
if(i>=0)
{
PrintTitle();
Showoneperson(i);
}
else
{
printf("Nobody is the number:%d\n",no_temp);
}
}
void Save()/*备份信息到文件 */
{
int i;
char filename[10],ch;
FILE *fp;
printf("Name the new file:(less than ten bits)");
scanf("%s",filename);
if((fp=fopen(filename,"wb"))==NULL)
{
printf("Fail to build the file!\n");
exit(0);
}
ch=getchar();
for(i=0;i<total;i++)
Inputfile(i,fp);
Show();
fclose(fp);
}
void Delete(FILE *fp)/*删除记录 */
{
int i,j,k,no_temp,choice2;
printf("Inpute the number someone you needed:(如10141301)");
scanf("%d",&no_temp);
i=CheckNumber(no_temp);
if(i>=0)
{
PrintTitle();
Showoneperson(i);
printf("Sure to delete the person?(1,Y/2,N)");
scanf("%d",&choice2);
if(choice2==1)
{
for(j=i;j<total;j++)
{
strcpy(student[j].name,student[j+1].name);
student[j].sex=student[j+1].sex;
student[j].no=student[j+1].no;
for(k=0;k<4;k++)
{
student[j].mark[k]=student[j+1].mark[k];
}
}
total--;
for(k=0;k<total;k++)
Inputfile(k,fp);
}
}
else
printf("Nobody is the number:%d\n",no_temp);
}
void Alter(FILE *fp)/*修改记录信息 */
{
int i,j,no_temp,sum=0;
printf("Inpute the number somesoe you want to alter:(如10141301)");
scanf("%d",&no_temp);
i=CheckNumber(no_temp);
if(i>=0)
{
student[i].no=no_temp;
printf("Input name(less than 20 numbers):");
scanf("%s",student[i].name);
printf("Sex(M/W):");
scanf("%c",&student[i].sex);
printf("\n 语文\t 数学\t 英语\n");
for(j=0;j<3;j++)
{
scanf("%d",&student[i].mark[j]);
sum=sum+student[i].mark[j];
}
student[i].mark[3]=sum/3;
PrintTitle();
Showoneperson(i);
for(j=0;j<total;j++)
Inputfile(j,fp);
}
else
printf("Nobody is the number:%d\n",no_temp);
}
int Sort_menu_choice()/*选择是按学号还是成绩排序*/
{
int choice;
do
{
printf("输入排序方式(1 按学号 2 按平均成绩): ");
scanf("%d",&choice);
if((choice<0)||(choice>2))
printf("error!");
}
while((choice<0)||(choice>2));
return(choice);
}
void Sort_no()/*选择是按学号排序*/
{
int i,j;
for(i=0;i<total-1;i++)
{
for(j=i+1;j<total;j++)
{
if(student[i].no>student[j].no)
exchange(i,j);
}
}
}
void Sort_mark()/*选择是按成绩排序*/
{
int i,j;
for(i=0;i<total-1;i++)
{
for(j=i+1;j<total;j++)
{
if(student[i].mark[3]<student[j].mark[3])
exchange(i,j);
}
}
}
void Sort_menu()/*排序菜单*/
{
switch(Sort_menu_choice())
{
case 1:Sort_no();
Sort_save();
clear();
break;
case 2:Sort_mark();
Sort_save();
clear();
break;
}
}
void Sort_save()/*排序后数据写入文件*/
{
int i;
FILE *fp;
if((fp=fopen("student.txt","wb"))==NULL)
{
printf("Fail to save the file!\n");
exit(0);
}
for(i=0;i<total;i++)
Inputfile(i,fp);
Show();
fclose(fp);
}
void set_psw()/*设置密码 */
{
char psw_set[20],psw_check[20],c;
unsigned int i;
FILE *fp;
do
{ printf("You must set password first!\n");
printf("Enter password:(lessthan 12 numbers and key'.'for end)\n");
for(i=0;(c=getch())!='.';i++)
{
putchar('*');
psw_set[i]=c;
}
psw_set[i]='\0';
printf("\n------------\n");
printf("conform password:");
for(i=0;(c=getch())!='.';i++)
{
putchar('*');
psw_check[i]=c;
}
psw_check[i]='\0';
printf("\n------------\n");
if(strcmp(psw_set,psw_check)==0)
{printf("Set password success!");
strcpy(password,psw_set);
}
else
printf("error!\n");
}
while(strcmp(psw_set,psw_check)!=0);
clear();
fp=fopen("password.txt","wb");
fprintf(fp,"%s",password);
fclose(fp);
}
int psw_check()/*密码验证 */
{
unsigned int i=1,j=1;
FILE *fp;
char pword[20],c;
if((fp=fopen("password.txt","rb"))==NULL)
{
fp=fopen("password.txt","a");
set_psw();
}
fscanf(fp,"%s",password);
fclose(fp);
do
{
printf("\nInput password:key'.'for end(%d/three times)",j);
for(j=0;(c=getch())!='.';j++)
{
putchar('*');
pword[j]=c;
}
pword[j]='\0';
i++;
}
while(strcmp(pword,password)!=0&&i<=3);
if(i<=3)
return 1;
else
{
printf("You have tryed for three times,fail to open the file!\n");
return 0;
}
}
void main()/*主函数*/
{
if(psw_check())
{
Init();
clear();
menu();
}
}
学生成绩管理系统【c】的更多相关文章
- Java项目:学生成绩管理系统(二)
学生成绩管理系统(二):项目介绍 一.设计要求: 1.1 简单的图形界面登录功能. 1.2 对数据库的的信息的查询功能. 1.3 对数据库的的信息的修改功能. 1.4 对数据库的的信息的删除功能. 1 ...
- Java项目:学生成绩管理系统(一)
学生成绩管理系统(一) 项目名称:学生成绩管理系统 项目需求分析(Need 需求): (1)该系统的用户分为教师和学生.教师的功能有:管理某一学生或课程的信息以及成绩,包括增.删.查.报表打印等:学生 ...
- 学生成绩管理系统[C]
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<conio.h> #d ...
- 【转】 [C/OC的那点事儿]NSMutableArray排序的三种实现(依赖学生成绩管理系统).
原文网址:http://blog.csdn.net/ministarler/article/details/17018839 c语言实现的学生成绩管理系统是面向过程的,而OC实现的学生成绩管理系统则是 ...
- 学生成绩管理系统 1.0(Java+MySql)
真难…… 数据库建立不会,中文编码不会,插入数据不会,删除不会…… Java读入数据不会……数据库连接不会…… 你也好意思说自己是学计算机的啊魂淡…… 我会慢慢写2.0,3.0版的……噗…… src/ ...
- 《C语言编写 学生成绩管理系统》
/* (程序头部凝视開始) * 程序的版权和版本号声明部分 * Copyright (c) 2011, 烟台大学计算机学院学生 * All rights reserved. * 文件名: 学生成绩管理 ...
- c++学生成绩管理系统
虽然比较水 =.= 但是写了两节课+一个中午 都是强迫症的锅 http://www.cnblogs.com/wenruo/p/4940182.html #include <cstdio> ...
- 使用C++名单在文档处理和学生成绩管理系统相结合
对于学生成绩管理系统,我并不陌生,几乎学习C人的语言.做项目会想到学生成绩管理系统,我也不例外.在研究中的一段时间C语言之后,还用C语言到学生管理系统,然后做几个链接.计数,这个系统是以前的系统上的改 ...
- C语言练手自己编写学生成绩管理系统
#include<stdio.h> #include<stdlib.h> /*定义学生结构体*/ struct Student { ]; ]; float Mark1; flo ...
- 《C语言 学生成绩管理系统》
/* (盯着先拔头筹程序) * 该计划的版权声明和版本号 * Copyright (c) 2011, 烟台大学计算机学院学生的学校 * All rights reserved. * 文件名: 学生成绩 ...
随机推荐
- Node.js 解析gzip网页(https)
gzip网页指网页头字段Content-Encoding是gzip(GNU zip)内容编码方式.内容编码是指不丢失实体信息的前提下所进行的压缩. Node.js 代码如下: //========== ...
- 倍福TwinCAT(贝福Beckhoff)常见问题(FAQ)-如何获取标准驱动器扭矩值获取电流值
双击某个驱动器(以松下伺服驱动器为例),在Process Data中,注意默认显示了PDO mapping1的数据(Error code, status word等) 注意左侧,2和3分别表示了与 ...
- C# 0-1背包问题
0-1背包问题 0-1背包问题基本思想: p[i,j]表示在前面i个物品总价值为j时的价值最大值.str[i, j]表示在前面i个物品总价值为j时的价值最大值时的物品重量串. i=0 或者j=0时: ...
- C++常考面试题汇总(持续更新中)
c++面试题 一 用简洁的语言描述 c++ 在 c 语言的基础上开发的一种面向对象编程的语言: 应用广泛: 支持多种编程范式,面向对象编程,泛型编程,和过程化编程:广泛应用于系统开发,引擎开发:支持类 ...
- Leetcode:integer_to_roman
一. 题目 将给定的数字(阿拉伯数字)转化成罗马数字. 数字不会大于3999 二. 分析 首先我们要知道神马是罗马数字,尽管听说过.但事实上我还真没有记住,于是就google了下,具体 ...
- iOS swift版本无限滚动轮播图
之前写过oc版本的无限滚动轮播图,现在来一个swift版本全部使用snapKit布局,数字还是pageConrrol样式可选 enum typeStyle: Int { case pageContro ...
- zookeeper 批量启动的脚本
#!/bin/shecho "start zkServer"for i in 2 3 4dossh mini$i "source /etc/profile;/usr/l ...
- linux虚拟文件系统vfs
linux可以挂载不同的文件系统(EXT2,FAT,NTFS),用同一的样式呈现给用户,读写操作用起来都一样,这是怎样做到的呢? linux内核在各种不同的文件系统格式上做了一个抽象层,使得文件.目录 ...
- IOS设计模式浅析之适配器模式(Adapter)
引言 在项目开发中,有时候会遇到这样的一种情景:需要使用以前开发的“一些现存的对象”,但是新环境中要求的接口是这些现存对象所不满足的.怎样应对这种迁移的需求?使得可以复用这些对象,以满足新的应用环境, ...
- CI框架基本配置/教你学习CI框架codelgniter
CI框架现在中国可以说还是不成熟,不像thinkphp那样有那么多的中文手册,在国内,很多国人英语都很烂,CI现在教程还是不多.大家心里都存在这严重想法 CI 框架现在中国可以说还是不成熟,不像thi ...