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 ...
随机推荐
- CentOS 7 Linux 卸载/安装 Mariadb MySQL mysql 5.7
[root@localhost mysql]# ls mysql-community-client--.el7.x86_64.rpm mysql-community-embedded-compat-- ...
- [转]jQuery实现图片轮播效果,jQuery实现焦点新闻
本文转自:http://blog.csdn.net/tsyj810883979/article/details/8986157 效果图: 实现代码: <!DOCTYPE html> < ...
- CentOS 6.5 & 7 的网络YUM源配置
中国科技大学CentOS 6.5的网络源 [base]name=CentOS-$releasever - Base#mirrorlist=http://mirrorlist.centos.org/?r ...
- SUN巡检命令
# hostname (主机名)# hostid# uname -X# uname -a # w (进程)# who# last# ps -eaf# /usr/ucb/ps -aux# prstat ...
- 【转】js弹出框、对话框、提示框、弹窗总结
js弹出框.对话框.提示框.弹窗总结 一.js的三种最常见的对话框 //====================== JS最常用三种弹出对话框 ======================== //弹 ...
- oracle笔记1:-安装-体系结构-基本查询
一.Oracle数据库的安装(安装在虚拟机的xp系统里) 1.安装虚拟机 2.虚拟机内安装xp系统,以下步骤在虚拟机内进行 3.双击setup.exe,在出现的界面中设置口令, ...
- [转]C# 单例模式
最近在学设计模式,学到创建型模式的时候,碰到单例模式(或叫单件模式),现在整理一下笔记. 在<Design Patterns:Elements of Resuable Object-Orient ...
- selenium中Alter等弹出对话框的处理
昨天使用selenium做自动化测试,发现部分页面会弹出alert对话框,找了写资料,大概的意思就是要给弹出的对话框做出相应,不然,后续的处理会失败. _driver.SwitchTo().Alert ...
- sql数据库常用操作
string connectionString = @"Data Source=(local)\sql2008r2;Initial Catalog=Movies;Uid=sa;Pwd=sql ...
- 初看Mybatis 源码 (一)
Mybatis 的使用,首先需要构建一个SqlSessionFactory 实例.而该实例可以通过SqlSessionFactoryBuilder来创建. String resource = &quo ...