C语言学生成绩管理系统(简易版)

时间:2022-09-06 08:03:42
 #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语言学生成绩管理系统(简易版)的更多相关文章

  1. c&plus;&plus;链表实现学生成绩管理系统&lpar;简易版&rpar;

    #include<iostream> using namespace std; typedef struct student{ int id;//学号 string sex; string ...

  2. 《C语言 学生成绩管理系统》

    /* (盯着先拔头筹程序) * 该计划的版权声明和版本号 * Copyright (c) 2011, 烟台大学计算机学院学生的学校 * All rights reserved. * 文件名: 学生成绩 ...

  3. 第一次写C语言小程序,可以初步理解学生成绩管理系统的概念

    1 成绩管理系统概述 1.1  管理信息系统的概念  管理信息系统(Management Information Systems,简称MIS),是一个不断发展的新型学科,MIS的定义随着科技的进步也在 ...

  4. 《C语言编写 学生成绩管理系统》

    /* (程序头部凝视開始) * 程序的版权和版本号声明部分 * Copyright (c) 2011, 烟台大学计算机学院学生 * All rights reserved. * 文件名: 学生成绩管理 ...

  5. 【学生成绩管理系统】 大二c语言作业

    几年前写的了,只能在命令行窗口运行,虽然比较挫,还是有一定参考价值... #include <cstdio> #include <conio.h> #include <i ...

  6. C语言项目:学生成绩管理系统

    C语言项目:学生成绩管理系统    1.数据结构:学生信息:学号.姓名.年龄.性别.3课成绩    2.功能:   (1)增加学生记录    (2)  删除学生记录    (3)  查找学生信息(学号 ...

  7. C语言实现---学生成绩管理系统

    C语言实现了学生成绩管理系统,可以进行学生成绩的增加,删除,更新,查询,计算和展示. 完整代码如下: #include<stdio.h> #include<stdlib.h> ...

  8. JAVA语言课堂测试01源代码(学生成绩管理系统)

    package 考试; /*信1807-8 * 20183798 * 向瑜 */ import java.util.Scanner; //ScoreInformation 类 class ScoreI ...

  9. 学生成绩管理系统-JAVA语言测试

     首先右键新建一个工程project 选择Java Project,单击next下一步 project命名为“学生成绩管理系统”,点击finish继续 右键src文件夹新建Package包,取名为te ...

随机推荐

  1. CCPC2016杭州现场赛

    A(hdu5933):(贪心) 题意:长度为n的数组: a1, a2,⋯, 每次操作要么可以merge两个相邻的数为一个, 值为两个数的和; 要么可以把一个数分裂成两个, 两个数的和为原数. 用最少的 ...

  2. Linux Ubuntu12&period;04下安装OpenCv2&period;4&period;10

    参考 http://blog.sina.com.cn/s/blog_53b0956801010lfu.html 捣鼓了一个晚上了,OpenCv还没装好,本来以为看个类似的比如Ubuntu安装OpenC ...

  3. IIS7 rename application or site

    rename site 比较容易,在IIS里面就可以直接 rename,也可以用 cmd 的方式 1. 打开 cmd 2. cd C:\Windows\System32\inetsrv 3. appc ...

  4. linux杂记(四)热键&lbrack;Tab&rsqb;&comma;&lbrack;ctrl&rsqb;-c&comma;&lbrack;ctrl&rsqb;-d,在线求助man page&sol;info page

    [Tab]按键 他具有[命令补全](接在一串指令的第一个字后面)与[档案补齐](接在第一串指令的第二字以后时)的功能.如 [KANO@kelvin ~]$ ca[tab][tab] cabextrac ...

  5. ubuntu ~&sol;&period;bash&lowbar;history

    sudo apt-get update sudo apt-get install python-pip sudo pip install Django==1.7.1 sudo apt-get inst ...

  6. Chronic sleep loss cannot be cured that easily

    Chronic sleep loss cannot be cured that easily Sleeping in on Saturday after a few weeks of too litt ...

  7. PHP工厂模式demo

    <?php//工厂模式 interface operstion{ function oper($a,$b);}//加class add implements operstion{ functio ...

  8. centos-yum离线源

    配置离线源 在个别开发环境中,我们可能有限制不能连外网. 这个情况可以通过用一台同内网的机器配置离线源,然后通过vsftp公用. 安装ftp rpm命令详解 $ rpm -ivh apache-1.3 ...

  9. Satisfiability of Equality Equations - LeetCode

    目录 题目链接 注意点 解法 小结 题目链接 Satisfiability of Equality Equations - LeetCode 注意点 必须要初始化pre 解法 解法一:典型的并查集算法 ...

  10. display的flex属性使用详解

    flex的兼容性在pc端还算阔以,但是在移动端,那就呵呵了.今天我们只是学习学习,忽略一些不重要的东西. 首先flex的使用需要有一个父容器,父容器中有几个items. 父容器:container 属 ...