Information Management System

Information Management System

A. Code portion

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
typedef struct STU {
    char name[20];
    char sex[5];
    char num[20];
    char _class[20];
    char score[5];
};
void home(void) {                           //显示进入画面
    printf("\n\n\n\n");
    printf("================================================================================\n\n");
    printf("================================================================================\n\n");
    printf("*************************欢迎使用学生成绩管理系统*******************************\n\n");
    printf("-----------------------------------------------------------------制作人:Sogger\n\n");
    printf("****************************----Welcome!----************************************\n\n");
    printf("================================================================================\n\n");
    printf("================================================================================\n\n");
    printf("                                                        请按任意键进入学生成绩管理系统\n\n\n\n\n");
    system("pause >nul");
    system("cls");
}
void end(void) {                            //显示结束画面
    printf("\n\n\n");
    printf("================================================================================\n\n");
    printf("================================================================================\n\n");
    printf("*************************感谢使用学生成绩管理系统***********************************\n\n");
    printf("********************************************************************************\n\n");
    printf("================================================================================\n\n");
    printf("请按任意键退出学生管理系统\n");
    system("pause >nul");
    exit(0);
}
void Output(struct STU* stu2) {                 //对成绩排行进行输出
    system("cls");
    int i;
    printf("                                                            成绩排行如下\n\n");
    printf("\t姓名\t性别\t学号\t\t班级\t\t线代成绩\n");
    for (i = 0; i < 10; i++) {
        printf("    %s  %s  %s  %s  %s\n", stu2[i].name, stu2[i].sex, stu2[i].num, stu2[i]._class, stu2[i].score);
    }
}
void ScoreTotal(struct STU* stu) {              //对成绩进行排行
    struct STU temp;
    int i,j;
    for (i = 0; i < 9; i++) {
        for (int j = i + 1; j < 10; j++) {
            if (stu[j].score > stu[i].score) {
                temp = stu[j];
                stu[j] = stu[i];
                stu[i] = temp;
            }
        }
    }
    Output(stu);
}
int main() {
    FILE* fp;
    STU stu[10],stu2[10];
    int i,a;
    char temp[10][20];
    char stu1[10][100];
    system("title 学生成绩管理系统");                   //设置标题
    system("mode con cols=80 lines=25");                //调节窗口高度宽度
    system("color F5");                                 //调节背景和字体颜色
    home();
    for (i = 0; i < 10; i++) {
        printf("                                                            请录入学生信息\n\n");
        printf("    学生%d\n\n", i+1);
        printf("    姓名\t性别\t学号\t\t班级\t\t线代成绩\n");
        printf("    ");
        scanf("%s   %s  %s  %s  %s", stu[i].name, stu[i].sex, stu[i].num, stu[i]._class, &stu[i].score);
        strcpy(temp[i], stu[i].name);
        strcat(temp[i], ".txt");
        if ((fp = fopen(temp[i], "w+")) == NULL) {
            printf("File open error!\n");
            exit(0);
        }
        fprintf(fp, "%s %s %s %s %s", stu[i].name, stu[i].sex, stu[i].num, stu[i]._class, stu[i].score);
        if (fclose(fp)) {
            printf("Can not close the file!\n");
            exit(0);
        }
        system("cls");                      //清空当前界面
    }
    printf("                                                        以下是十位同学的信息\n\n");
    printf("\t姓名\t性别\t学号\t\t班级\t\t线代成绩\n");
    for (i = 0; i < 10; i++) {
        if ((fp= fopen(temp[i], "r")) == NULL) {
            printf("File open error!\n");
            exit(0);
        }
        strcpy(stu2[i].name, stu[i].name);
        fscanf(fp, "%s %s %s %s %s", stu2[i].name, stu2[i].sex, stu2[i].num, stu2[i]._class, stu2[i].score);
        printf("    %s  %s  %s  %s  %s\n", stu2[i].name, stu2[i].sex, stu2[i].num, stu2[i]._class, stu2[i].score);
    }
    printf("\n\n\n            是否查看排行?\n       【1】是      【2】 否\n");
    printf("\t\t\t\t");
    scanf("%d", &a);
    if (a == 1) ScoreTotal(stu2);
    if (fclose(fp)) {
        printf("Can not close the file!\n");
        exit(0);
    }
    system("pause >nul");                       //暂停且不显示任何东西
    system("cls");
    end();
    return 0;
}       

II. Run shot

Brief three .system () function

  Function name: system () (to be added to the header file <stdlib.h> must be called)

  Function: is actually equivalent to execute a DOS command

Usage: system ( "DOS command");

Here are a few usage:

(1) system ( "color color parameters")

  Role: change the background color and text color screen window

  Preferences: color attribute specified by two hexadecimal digits, the first background color, text color, compared with the second

Each digit can be any of the following values:

Parameters: 0 = Black 1 Blue 2 = light green = green = 3 = 4 = 5 Red Yellow Purple = 6 = 7 = 8 Gray White

9 = light blue light green A = B = C = light green light reddish purple D = E = F = bright white light yellow

   Such as: Add the code system ( "color 9F"), the window screen may be set as the background color blue, the text color is set to white.

Note: 1. If only a given parameter, only set the background color. Such as: system ( "color 9"), the background color is blue, text color change

2. If any of the given parameters, such as: system ( "color"), the command will revert to the default color of the color when starting cmd

(2)system("pause")

Role: to halt the program in order to observe the results of the implementation of the program on the screen

Under normal circumstances, the results will be displayed behind the run: Press any key to continue...

This time is very irritable, obsessive-compulsive disorder watching will be very unhappy, so ...

If you do not want to display the prompt, you can redirect the output using the command:

system("pause >nul");

The screen is no longer displayed on the "Press any key to continue..." The tips of the ~ ~ ~ ~

Note: It is nul, not null! ! !

Greater than>, indicates to redirect the output file to another device, such as a printer command results

​    nul是DOS中的一个虚拟的空设备,">nul"表示把命令产生的屏幕显示信息重定向(>)到虚拟空设备

​ (nul),这样在屏幕上就不会显示pause命令的执行结果了~~

(3)system("cls")

​ 作用:清除屏幕信息...

(4)system("title 标题内容")

​ 作用:为程序调试的DOS窗口加上标题

​ 效果如下:、

(5)system("mode con cols=窗口长度 lines=窗口宽度")

​ 作用:调整DOS窗口的高度和宽度

​ 。。。

。。。

​ 。。。

​ 。。。

Guess you like

Origin www.cnblogs.com/Sogger/p/12079999.html
Recommended