C语言学生成绩管理系统(简易版)
#include<stdio.h>
#include<stdlib.h>
#include<string.h> int readstudents(struct students stu[]); //读取学生信息
int readsexcode(struct sexcode sex[]); //读取性别代码
int readcollegecode(struct collegecode colle[]); //读取学院代码
void transform(struct students stu[],struct sexcode sexy[],struct collegecode colle[],int a,int b,int c); //录入
void namesort(struct students stu[],int a); //按照姓名排序
void averagesort(struct students stu[],int a); //平均分排序
void searchcollege(struct students stu[],int a); //按学院搜索学生
void namesearch(struct students stu[],int a); //按名字搜索
void printstudent(struct students stu[],struct sexcode sex[],struct collegecode colle[],int a,int b,int c); //输出
void change(struct students stu[],int a);
int passwordfun();
void passwordchange();
void averagefun(struct students stu[],int a); struct students{
int num;
char name[];
int sexnum;
char sex[];
int collegenum;
char college[];
int score[];
float average;
};
struct sexcode{
int sexnum;
char sex[];
};
struct collegecode{
int collegenum;
char college[];
}; int main()
{
int a,b,c;
int choice;
struct students stu[];
struct sexcode sexy[];
struct collegecode colle[];
int t = passwordfun();
if(t == ){
printf("请使用正确密码重新登陆程序!\n");
return ;
}
while(){
system("cls");
printf("***********学生成绩系统菜单************ \n* 1. 原始文件读取 *\n* 2. 按姓名排序,输出 *\n* 3. 按平均成绩排序,输出 *\n* 4. 输出给定学院学生 *\n* 5. 修改给定学生成绩信息 *\n* 6. 按姓名查询学生,输出 *\n* 7. 修改系统密码 *\n* 0. 返回上一级菜单 *\n***************************************\n");
scanf("%d",&choice);
switch(choice){
case : system("cls");
a = readstudents(stu);
b = readsexcode(sexy);
c = readcollegecode(colle);
transform(stu,sexy,colle,a,b,c);
averagefun(stu,a);
printf("原始文件读取完毕!\n0. 返回上一级菜单 \n");
scanf("%d",&choice);
if(choice == ) break;
case : system("cls");
namesort(stu,a);
printstudent(stu,sexy,colle,a,b,c);
printf("\n0. 返回上一级菜单 \n");
scanf("%d",&choice);
if(choice == ) break;
case : system("cls");
averagesort(stu,a);
printstudent(stu,sexy,colle,a,b,c);
printf("\n0. 返回上一级菜单 \n");
scanf("%d",&choice);
if(choice == ) break;
case : system("cls");
searchcollege(stu,a);
printf("\n0. 返回上一级菜单 \n");
scanf("%d",&choice);
if(choice == ) break;
case : system("cls");
change(stu,a);
printf("修改成功!\n");
printf("\n0. 返回上一级菜单 \n");
scanf("%d",&choice);
if(choice == ) break;
case : system("cls");
namesearch(stu,a);
printf("\n0. 返回上一级菜单 \n");
scanf("%d",&choice);
if(choice == ) break;
case : system("cls");
passwordchange();
printf("\n0. 返回上一级菜单 \n");
scanf("%d",&choice);
if(choice == ) break;
case : system("cls");
printf("欢迎使用,下次再见!\n");
system("pause");
exit();
}
}
return ;
}
int readstudents(struct students stu[]) //读取学生信息
{
int i = ;
FILE *fp;
fp = fopen("D:\\abc\\Student_Info.txt","r+");
if(fp == ){
printf("can not open this file\n");
exit ();
}
fscanf(fp,"%d",&stu[i].num);
while(!feof(fp)){
fscanf(fp,"%s%d%d",stu[i].name,&stu[i].sexnum,&stu[i].collegenum);
for(int j = ;j < ; j++ ){
fscanf(fp,"%d",&stu[i].score[j]);
}
i++;
fscanf(fp,"%d",&stu[i].num);
}
fclose(fp);
return i;
}
int readsexcode(struct sexcode sexy[]) //读取学生性别信息
{
int i = ;
FILE *fp;
fp = fopen("D:\\abc\\S_Info.txt","r");
if(fp == ){
printf("can not open this file\n");
exit ();
}
fscanf(fp,"%d",&sexy[i].sexnum);
while(!feof(fp)){
fscanf(fp,"%s",sexy[i].sex);
i++;
fscanf(fp,"%d",&sexy[i].sexnum);
}
fclose(fp);
return i;
}
int readcollegecode(struct collegecode colle[]) //读取学生学院信息
{
int i = ;
FILE *fp;
fp = fopen("D:\\abc\\C_Info.txt","r");
if(fp == ){
printf("can not open this file\n");
exit ();
}
fscanf(fp,"%d",&colle[i].collegenum);
while(!feof(fp)){
fscanf(fp,"%s",colle[i].college);
i++;
fscanf(fp,"%d",&colle[i].collegenum);
}
fclose(fp);
return i;
}
void averagefun(struct students stu[],int a) //平均分
{
for(int i = ; i < a; i++){
int sum = ;
for(int j = ; j < ; j++){
sum = sum + stu[i].score[j];
}
stu[i].average = 1.0 * sum / ;
}
return ;
}
void namesort(struct students stu[],int a) //按姓名排序
{
for(int i = ; i < a-; i++){
for(int j = i+; j < a ; j++){
if(strcmp(stu[i].name,stu[j].name) < ){
struct students temp = stu[i];
stu[i] = stu[j];
stu[j] = temp;
}
}
}
return ;
}
void averagesort(struct students stu[],int a) // 按平均分排序
{
for(int i = ; i < a-; i++){
for(int j = i+; j < a ; j++){
if(stu[i].average < stu[j].average){
struct students temp = stu[i];
stu[i] = stu[j];
stu[j] = temp;
}
}
}
return ;
}
void printstudent(struct students stu[],struct sexcode sexy[],struct collegecode colle[],int a,int b,int c) //输出信息
{
for(int i = ;i < a; i++){
printf("%d%8s%4s%12s",stu[i].num,stu[i].name,stu[i].sex,stu[i].college);
for(int j = ; j < c; j++){
printf("%4d",stu[i].score[j]);
}
printf("%7.2f\n",stu[i].average);
}
return ;
}
void transform(struct students stu[],struct sexcode sexy[],struct collegecode colle[],int a,int b,int c) //修改信息
{
for(int i = ; i < a; i++){
for(int j = ; j < b; j++){
if(stu[i].sexnum == sexy[j].sexnum){
strcpy(stu[i].sex,sexy[j].sex);
break;
}
}
for(int j = ; j < c; j++){
if(stu[i].collegenum == (colle[j].collegenum - )){
strcpy(stu[i].college,colle[j].college);
break;
}
}
}
} void searchcollege(struct students stu[],int a) //查找学院并输出
{
char collegename[];
printf("请输入需要查找的学院的名称:\n") ;
scanf("%s",collegename);
for(int i = ;i < a; i++){
if(strcmp(stu[i].college,collegename) == ){
printf("%d%8s%4s%12s",stu[i].num,stu[i].name,stu[i].sex,stu[i].college);
for(int j = ; j < ; j++){
printf("%4d",stu[i].score[j]);
}
printf("%7.2f\n",stu[i].average);
}
}
return ;
}
void namesearch(struct students stu[],int a) //按姓名查找
{
printf("请输入需要查找的学生的姓名:\n");
char name[];
scanf("%s",name);
for(int i = ;i < a; i++){
if(strcmp(stu[i].name,name) == ){
printf("%d%8s%4s%12s",stu[i].num,stu[i].name,stu[i].sex,stu[i].college);
for(int j = ; j < ; j++){
printf("%4d",stu[i].score[j]);
}
printf("%7.2f\n",stu[i].average);
}
}
return ;
}
void change(struct students stu[],int a) //按名字搜索修改分数
{
char name[];
printf("请输入需要修改成绩的学生的姓名:\n");
scanf("%s",name);
printf("请输入改学生各科成绩,不需要修改的按原样输入:\n");
for(int i = ;i < a; i++){
if(strcmp(stu[i].name,name) == ){
for(int j = ; j <= ; j++){
printf("第%d门成绩: ",j);
scanf("%d",&stu[i].score[j-]);
printf("\n");
}
}
}
int i = ;
FILE *fp;
fp = fopen("D:\\abc\\Student_Info.txt","w");
if(fp == ){
printf("can not open this file\n");
exit ();
}
while(i<){
fprintf(fp,"%d %s %d %d",stu[i].num,stu[i].name,stu[i].sexnum,stu[i].collegenum);
for(int j = ;j < ; j++ ){
fprintf(fp," %d",stu[i].score[j]);
if(j == ){
fprintf(fp,"\n");
}
}
i++;
}
fclose(fp);
return ;
}
int passwordfun() //密码
{
char password_1[],password_2[],password_3[];
int i = ;
FILE *fp;
fp = fopen("D:\\abc\\password.txt","r");
if(fp == ){
printf("can not open this file\n");
exit ();
}
fscanf(fp,"%s",password_2);
fclose(fp);
if(password_2[i] == '\0'){ //当检测到密码文本为空时
printf("欢迎使用学生成绩管理系统!\n首次使用系统,您可以直接进入主菜单,进入主菜单后请及时修改密码!\n");
system("pause");
return ;
}
else
{
printf("请输入系统密码:\n"); //保存输入的密码
char s[];
int t,n_,x;
for(x=;x<;x++){
s[x]=getch();
if(s[x]=='\r') break;
printf("*");
}
s[x]='\0';
for(t=;t<;t++){ //将输入的密码存放在password_1中
password_1[t]=s[t];
}
for(i = ; password_2[i] != '\0'; i++){
if(password_2[i] <= && password_2[i] >= ){ //password_2为真实密码
password_3[i] = password_2[i] - ; //密码密文加密(+3)
}else{
password_3[i] = - password_3[i];
} //password_3为按算法处理后的真实密码
}
password_3[i] = '\0';
if(strcmp(password_1,password_3) == ){
return ;
}else{
printf("密码错误!\n程序结束!请使用正确密码重新登入程序!\n");
system("pause");
return ;
}
}
}
void passwordchange() //密码修改
{
FILE *fp;
char newpassword_1[];
char newpassword_2[];
int i = ;
printf("请输入新的密码:\n");
scanf("%s",newpassword_1);
for(i = ; newpassword_1[i] != '\0'; i++){
if(newpassword_1[i] + <= ){
newpassword_2[i] = newpassword_1[i] + ;
}else{
newpassword_2[i] = newpassword_1[i] + -;
}
}
newpassword_2[i] = '\0';
fp = fopen("D:\\abc\\password.txt","w");
if(fp == ){
printf("can not open this file\n");
exit ();
}
fprintf(fp,"%s",newpassword_2);
fclose(fp);
printf("密码修改成功!\n");
return ;
}
C语言学生成绩管理系统(简易版)的更多相关文章
- c++链表实现学生成绩管理系统(简易版)
#include<iostream> using namespace std; typedef struct student{ int id;//学号 string sex; string ...
- 《C语言 学生成绩管理系统》
/* (盯着先拔头筹程序) * 该计划的版权声明和版本号 * Copyright (c) 2011, 烟台大学计算机学院学生的学校 * All rights reserved. * 文件名: 学生成绩 ...
- 第一次写C语言小程序,可以初步理解学生成绩管理系统的概念
1 成绩管理系统概述 1.1 管理信息系统的概念 管理信息系统(Management Information Systems,简称MIS),是一个不断发展的新型学科,MIS的定义随着科技的进步也在 ...
- 《C语言编写 学生成绩管理系统》
/* (程序头部凝视開始) * 程序的版权和版本号声明部分 * Copyright (c) 2011, 烟台大学计算机学院学生 * All rights reserved. * 文件名: 学生成绩管理 ...
- 【学生成绩管理系统】 大二c语言作业
几年前写的了,只能在命令行窗口运行,虽然比较挫,还是有一定参考价值... #include <cstdio> #include <conio.h> #include <i ...
- C语言项目:学生成绩管理系统
C语言项目:学生成绩管理系统 1.数据结构:学生信息:学号.姓名.年龄.性别.3课成绩 2.功能: (1)增加学生记录 (2) 删除学生记录 (3) 查找学生信息(学号 ...
- C语言实现---学生成绩管理系统
C语言实现了学生成绩管理系统,可以进行学生成绩的增加,删除,更新,查询,计算和展示. 完整代码如下: #include<stdio.h> #include<stdlib.h> ...
- JAVA语言课堂测试01源代码(学生成绩管理系统)
package 考试; /*信1807-8 * 20183798 * 向瑜 */ import java.util.Scanner; //ScoreInformation 类 class ScoreI ...
- 学生成绩管理系统-JAVA语言测试
首先右键新建一个工程project 选择Java Project,单击next下一步 project命名为“学生成绩管理系统”,点击finish继续 右键src文件夹新建Package包,取名为te ...
随机推荐
- Mybatis学习笔记4 - 获取自增主键的值
获取自增主键的值:mysql支持自增主键,自增主键值的获取,mybatis也是利用statement.getGenreatedKeys():useGeneratedKeys="true&qu ...
- java编程--04比较几个常用的日期时间相关类的区别
第一篇,介绍日期的比较 第二篇,介绍日期的格式化 第三篇,介绍关于日期常用的计算 第四篇,比较几个常用的日期时间相关类的区别 第五篇,jdk9对日期类进行了更新,写一些i自己的学习心得. 下面以一组思 ...
- java多线程(一)
一.进程,线程,并发,并行 1.1 进程和线程的区别 进程是指:一个内存中运行的应用程序,每个进程都有自己独立的一块内存空间,一个进程中可以启动多个线程.比如在Windows系统中,一个运 ...
- gdb调试汇总
1. 启动GDB开始调试: (1)gdb program ///最常用的用gdb启动程序,开始调试的方式(2)gdb program core ///用gdb查看core dump文件,跟踪程序cor ...
- Unity C# 用枚举(enum)制作复选框
最近在项目中做测试脚本用到一些布尔值做方法的开关,突然想到可以制作一个复选框控制开关. 首先搜集网上的资料,基本大同小异,这里就不多做解释了,代码附上: public class EnumFlagsA ...
- 乐蜂网SALES倒计时原码展示
这是一个基于jquey写的倒计时.当然代码有点小改动,只是改了一下展示效果. 在静态页添加显示倒计时的容器,并引用下面脚本,代入时间参数即可使用. timeoutDate——到期时间,时间格式为201 ...
- JavaScript 数组(Array)
//声明方式 //调用 Array构造函数创建并赋值 var users = new Array(); //new 可以省略 ); //new 可以省略 var users3 = new Array( ...
- yield关键字的使用
yield的中文是什么意思呢? 在金山词霸上面的翻译是: vt.屈服,投降: 生产: 获利: 不再反对 vi.放弃,屈服: 生利: 退让,退位 n.产量,产额: 投资的收益: 屈服,击穿: 产品 个人 ...
- BZOJ3261: 最大异或和(可持久化trie树)
题意 题目链接 Sol 设\(sum[i]\)表示\(1 - i\)的异或和 首先把每个询问的\(x \oplus sum[n]\)就变成了询问前缀最大值 可持久化Trie树维护前缀xor,建树的时候 ...
- 对MVVM思想的在认识
如果说MVP是对MVC的进一步改进,那么MVVM则是思想的完全变革.它是将“数据模型数据双向绑定”的思想作为核心,因此在View和Model之间没有联系,通过ViewModel进行交互,而且Model ...