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 ...
随机推荐
- C++中遇到的各种小问题
lpcwstr类型问题 在使用VS2010开发C++程序时,由于系统默认字符集是unicode字符集,造成与早期的字符串格式不兼容问题 ①Properties — Configuration Prop ...
- Technical Committee Weekly Meeting 2016.06.21
Meeting time: 2016.June.21 1:00~2:00 Chairperson: Thierry Carrez Meeting summary: 1.Add current hou ...
- linux下文件比对功能
很想对吧两个文本有什么不同,可linux下有没有那么方便的工具,怎么办?其实也很简单:diff命令,一行搞定. 新建a.txt文件
- 详解在Hibernate中配置数据库方言的作用和好处以及各种数据库的方言连接
Hibernate底层依然使用SQL语句来执行数据库操作,虽然所有关系型数据库都支持使用标准SQL语句,但所有数据库都对标准SQL进行了一些扩展,所以在语法细节上存在一些差异,因此Hibernate需 ...
- WebGL 踩坑系列-1
WebGL 中的一些选项WebGL 中开启颜色混合(透明效果) gl.enable(gl.BLEND); gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALP ...
- C++ 虚函数、纯虚函数、虚继承
1)C++利用虚函数来实现多态. 程序执行时的多态性通过虚函数体现,实现运行时多态性的机制称爲动态绑定:与编译时的多态性(通过函数重载.运算符重载体现,称爲静态绑定)相对应. 在成员函数的声明前加上v ...
- Sql 本周当天本期日期转换
--查询当天: --查询24小时内的: --info为表名,datetime为数据库中的字段值 --查询当天: --查询24小时内的: select * from table where DateDi ...
- SSRS 参数 单选 多选
前段时间 公司要求报表的选项可以多选. 知道需求后,研究了下实现. 首先我们创建一个报表,然后添加3个数据集,2个参数,如下图. DataSet1数据集:存放主数据. ddl_emplid数据集:存放 ...
- [LeetCode]11. Container With Most Water 盛最多水的容器
Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). ...
- Vue.js基础语法(三)
vue学习的一系列,全部来自于表哥---表严肃,是我遇到过的讲课最通透,英文发音最好听的老师,想一起听课就去这里吧 https://biaoyansu.com/i/hzhj1206 1过滤器filte ...