zoukankan      html  css  js  c++  java
  • A Typical Homework(学生信息管理系统)

    A Typical Homework(a.k.a Shi Xiong Bang Bang Mang)

    Hi, I am an undergraduate student in institute of foreign languages. As you know, C programming is a required course in our university, even if his/her major is far from computer science. I don‘t like this course at all, as I am not good at computer and I don‘t wanna even have a try of any programming!! But I have to do the homework in order to pass :( Sh... Could you help me with it? Please keep secret!! I know that you won‘t say NO to a poor little girl, boy. :)

    Task

    Write a Student Performance Management System (SPMS).

    Concepts

    In the SPMS, there will be at most 100 students, each has an SID, a CID, a name and four scores (Chinese, Mathematics, English and Programming).

    • SID (student ID) is a 10-digit number
    • CID (class ID) is a positive integer not greater than 20.
    • Name is a string of no more than 10 letters and digits, beginning with a capital letter. Note that a name cannot contain space characters inside.
    • Each score is a non-negative integer not greater than 100.

    Main Menu

    When you enter the SPMS, the main menu should be shown like this:

    Welcome to Student Performance Management System (SPMS).
    
    1 - Add
    2 - Remove
    3 - Query
    4 - Show ranking
    5 - Show Statistics
    0 - Exit
    

    Adding a Student

    If you choose 1 from the main menu, the following message should be printed on the screen:

    Please enter the SID, CID, name and four scores. Enter 0 to finish.
    

    Then your program should wait for user input. The input lines are always valid (no invalid SID, CID, or name, exactly four scores etc), but the SID may already exist. In that case, simply ignore this line and print the following:

    Duplicated SID.
    

    On the other hand, multiple students can have the same name. You should keep printing the message above until the user inputs a single zero. After that the main menu is printed again.

    Removing a Student

    If you choose 2 from the main menu, the following message should be printed on the screen:

    Please enter SID or name. Enter 0 to finish.
    

    Then your program should wait for user input, and remove all the students matching the SID or name in the database, and print the following message (it‘s possible xx=0):

    xx student(s) removed.
    

    You should keep printing the message above until the user inputs a single zero. After that the main menu is printed again.

    Querying Students

    If you choose 3 from the main menu, the following message should be printed on the screen:

    Please enter SID or name. Enter 0 to finish.
    

    Then your program should wait for user input. If no student matches the SID or name, simply do nothing, otherwise print out all the matching students, in the same order they‘re added to the database. The format is similar to the input format for "adding a student", but 3 more columns are added: rank (1st column), total score and average score (last two columns). The student with highest total score (considering all classes) received rank-1, and if there are two rank-2 students, the next one would be rank-4. You should keep printing the message above until the user inputs a single zero. After that the main menu is printed again.

    Showing the Ranklist

    If you choose 4 from the main menu, the following message should be printed on the screen:

    Showing the ranklist hurts students‘ self-esteem. Don‘t do that.
    

    Then the main menu is printed again.

    Showing Statistics

    If you choose 5 from the main menu, show the statistics, in the following format:

    Please enter class ID, 0 for the whole statistics.
    

    When a class ID is entered, print the following statistics. Note that "passed" means to have a score of at least 60.

    Chinese
    Average Score: xx.xx
    Number of passed students: xx
    Number of failed students: xx
    
    Mathematics
    Average Score: xx.xx
    Number of passed students: xx
    Number of failed students: xx
    
    English
    Average Score: xx.xx
    Number of passed students: xx
    Number of failed students: xx
    
    Programming
    Average Score: xx.xx
    Number of passed students: xx
    Number of failed students: xx
    
    Overall:
    Number of students who passed all subjects: xx
    Number of students who passed 3 or more subjects: xx
    Number of students who passed 2 or more subjects: xx
    Number of students who passed 1 or more subjects: xx
    Number of students who failed all subjects: xx


    Then, the main menu is printed again.

    Exiting SPMS

    If you choose 0 from the main menu, the program should terminate. Note that course scores and total score should be formatted as integers, 
    but average scores should be formatted as a real number with exactly two digits after the decimal point.

    Input

    There will be a single test case, ending with a zero entered in the main menu screen. The entire input will be valid. The size of input does not exceed 10KB.

    Output

    Print out everything as stated in the problem description. You should be able to play around this little program in your machine,

    with a keyboard and a screen. However, both the input and output may look silly when they‘re not mixed, as in the keyboard-screen case.

    Sample Input

    1
    0011223344 1 John 79 98 91 100
    0022334455 1 Tom 59 72 60 81
    0011223344 2 Alice 100 100 100 100
    2423475629 2 John 60 80 30 99
    0
    3
    0022334455
    John
    0
    5
    1
    2
    0011223344
    0
    5
    0
    4
    0
    

    Output for the Sample Input

    Welcome to Student Performance Management System (SPMS).
    
    1 - Add
    2 - Remove
    3 - Query
    4 - Show ranking
    5 - Show Statistics
    0 - Exit
    
    Please enter the SID, CID, name and four scores. Enter 0 to finish.
    Please enter the SID, CID, name and four scores. Enter 0 to finish.
    Please enter the SID, CID, name and four scores. Enter 0 to finish.
    Duplicated SID.
    Please enter the SID, CID, name and four scores. Enter 0 to finish.
    Please enter the SID, CID, name and four scores. Enter 0 to finish.
    Welcome to Student Performance Management System (SPMS).
    
    1 - Add
    2 - Remove
    3 - Query
    4 - Show ranking
    5 - Show Statistics
    0 - Exit
    
    Please enter SID or name. Enter 0 to finish.
    2 0022334455 1 Tom 59 72 60 81 272 68.00
    Please enter SID or name. Enter 0 to finish.
    1 0011223344 1 John 79 98 91 100 368 92.00
    3 2423475629 2 John 60 80 30 99 269 67.25
    Please enter SID or name. Enter 0 to finish.
    Welcome to Student Performance Management System (SPMS).
    
    1 - Add
    2 - Remove
    3 - Query
    4 - Show ranking
    5 - Show Statistics
    0 - Exit
    
    Please enter class ID, 0 for the whole statistics.
    Chinese
    Average Score: 69.00
    Number of passed students: 1
    Number of failed students: 1
    
    Mathematics
    Average Score: 85.00
    Number of passed students: 2
    Number of failed students: 0
    
    English
    Average Score: 75.50
    Number of passed students: 2
    Number of failed students: 0
    
    Programming
    Average Score: 90.50
    Number of passed students: 2
    Number of failed students: 0
    
    Overall:
    Number of students who passed all subjects: 1
    Number of students who passed 3 or more subjects: 2
    Number of students who passed 2 or more subjects: 2
    Number of students who passed 1 or more subjects: 2
    Number of students who failed all subjects: 0
    
    Welcome to Student Performance Management System (SPMS).
    
    1 - Add
    2 - Remove
    3 - Query
    4 - Show ranking
    5 - Show Statistics
    0 - Exit
    
    Please enter SID or name. Enter 0 to finish.
    1 student(s) removed.
    Please enter SID or name. Enter 0 to finish.
    Welcome to Student Performance Management System (SPMS).
    
    1 - Add
    2 - Remove
    3 - Query
    4 - Show ranking
    5 - Show Statistics
    0 - Exit
    
    Please enter class ID, 0 for the whole statistics.
    Chinese
    Average Score: 59.50
    Number of passed students: 1
    Number of failed students: 1
    
    Mathematics
    Average Score: 76.00
    Number of passed students: 2
    Number of failed students: 0
    
    English
    Average Score: 45.00
    Number of passed students: 1
    Number of failed students: 1
    
    Programming
    Average Score: 90.00
    Number of passed students: 2
    Number of failed students: 0
    
    Overall:
    Number of students who passed all subjects: 0
    Number of students who passed 3 or more subjects: 2
    Number of students who passed 2 or more subjects: 2
    Number of students who passed 1 or more subjects: 2
    Number of students who failed all subjects: 0
    
    Welcome to Student Performance Management System (SPMS).
    
    1 - Add
    2 - Remove
    3 - Query
    4 - Show ranking
    5 - Show Statistics
    0 - Exit
    
    Showing the ranklist hurts students‘ self-esteem. Don‘t do that.
    Welcome to Student Performance Management System (SPMS).
    
    1 - Add
    2 - Remove
    3 - Query
    4 - Show ranking
    5 - Show Statistics
    0 - Exit



    题意做一个学生管理系统
    结合李汝佳代码的一部分写出来的代码,注意处理小细节和各个操作之间的关系

    #include<iostream>
    #include<cstdio>
    #include<string.h>
    using namespace std;
    
    #define maxn 1000
    #define maxl 100
    #define ESP 1e-5
    
    int n = 0;
    char sid[maxn][maxl];       //学生编号
    int cid[maxn];              //班级编号
    char name[maxn][maxl];     
    int score[maxn][5];        //四科成绩加平均成绩
    int removed[maxn];          //记录名单中的学生是否被删除,删除了值为1
    
    const char* course_name[] = {"Chinese", "Mathematics", "English", "Programming"};
    
    void print_menu(void)
    {
        printf("Welcome to Student Performance Management System  (SPMS).
            
    
    1 - Add
    2 - Remove
    3 - Query
    4 - Show ranking
    5 - Show Statistics
    0 - Exit
    ");
    }
    
    int ranki(int k)
    {
        int r=1;
        for(int i=0;i<n;i++){
            if(removed[i]==0&&score[i][4]>score[k][4])r++;
        }
        return r;
    }
    
    void DQ(int isq)
    {
        char s[maxl];
        for(;;){
            printf("Please enter SID or name. Enter 0 to finish.
    ");
            scanf("%s",s);
            if(strcmp(s,"0")==0)break;
            int r=0;
            for(int i=0;i<n;i++)if(!removed[i]){
                if(strcmp(sid[i],s)==0||strcmp(name[i],s)==0){
                    if(isq)printf("%d %s %d %s %d %d %d %d %d %.2f
    ",
                        ranki(i),sid[i],cid[i],name[i],score[i][0],score[i][1],
                        score[i][2],score[i][3],score[i][4],score[i][4]/4.0+ESP);
                    else{
                        removed[i]=1;
                        r++;
                    }
                }
            }
            if(!isq)printf("%d student(s) removed.
    ",r);
        }
    }
    
    void add()
    {
        int flag;
        for(;;){
            flag=true;
            printf("Please enter the SID, CID, name and four scores. Enter 0 to finish.
    ");
            scanf("%s",sid[n]);
            if(strcmp(sid[n],"0")==0)break;
            scanf("%d%s%d%d%d%d",&cid[n],name[n],&score[n][0],&score[n][1],&score[n][2],&score[n][3]);
            score[n][4]=score[n][0]+score[n][1]+score[n][2]+score[n][3];
            removed[n]=0;
            for(int i=0;i<n;i++){
                if(removed[i]==0&&strcmp(sid[n],sid[i])==0){
                    flag=false;
                    printf("Duplicated SID.
    ");
                }
            }
            if(flag)n++;
        }
    }
    
    double get_class(int p,int q,int& passed,int& failed)
    {
        double sc=0;
        for(int i=0;i<n;i++){
            if(removed[i]==0){
                if(p==0){
                    sc+=score[i][q];
                    if(score[i][q]>=60)passed++;
                    else failed++;
                }
                else if(cid[i]==p){
                    sc+=score[i][q];
                    if(score[i][q]>=60)passed++;
                    else failed++;
                }
            }
        }
        sc/=(passed+failed);
        return sc;
    }
    
    void get_overall(int p)
    {
        int a=0,b=0,c=0,d=0,e=0,co;
        for(int i=0;i<n;i++){
            co=0;
            if(removed[i]==0){
                if(p==0){
                if(score[i][0]>=60)co++;
                if(score[i][1]>=60)co++;
                if(score[i][2]>=60)co++;
                if(score[i][3]>=60)co++;
                if(co>=1)a++;
                if(co>=2)b++;
                if(co>=3)c++;
                if(co==4)d++;
                else if(co==0)e++;
                }
                else if(cid[i]==p){
                    if(score[i][0]>=60)co++;
                if(score[i][1]>=60)co++;
                if(score[i][2]>=60)co++;
                if(score[i][3]>=60)co++;
                if(co>=1)a++;
                if(co>=2)b++;
                if(co>=3)c++;
                if(co==4)d++;
                else if(co==0)e++;
                }
            }
        }
        printf("Overall:
    ");
        printf("Number of students who passed all subjects: %d
    ",d);
        printf("Number of students who passed 3 or more subjects: %d
    ",c);
        printf("Number of students who passed 2 or more subjects: %d
    ",b);
        printf("Number of students who passed 1 or more subjects: %d
    ",a);
        printf("Number of students who failed all subjects: %d
    ",e);
    
    }
    
    void stat()
    {
        int p;        //班级,0代表全年级
        printf("Please enter class ID, 0 for the whole statistics.
    ");
        scanf("%d",&p);
        for(int i=0;i<4;i++){
            int passed=0,failed=0;
            double average;
            average=get_class(p,i,passed,failed);
            printf("%s
    ",course_name[i]);
            printf("Average Scored: %.2f
    ",average);
            printf("Number of passed students: %d
    ",passed);
            printf("Number of failed students: %d
    
    ",failed);
            }
        get_overall(p);
    
    }
    /*void f(){
        for(int i=0;i<n;i++){
            if(removed[i]==0)
                printf("%d %s %d %s %d %d %d %d %d %.2f*******
    ",
                        ranki(i),sid[i],cid[i],name[i],score[i][0],score[i][1],
                        score[i][2],score[i][3],score[i][4],score[i][4]/4.0+ESP);
        }
    }*/
    int main()
    {
       for(;;){
           int choice;
           print_menu();
           scanf("%d",&choice);
           if(choice==0)break;
           if(choice==1)add();
           if(choice==2)DQ(0);
           if(choice==3)DQ(1);
           if(choice==4)printf("Showing the ranklist hurts students' self-esteem.Don't do that.
    ");
           if(choice==5)stat();
          // f();
       }
       //system("pause");
        return 0;
    }
    
    
    
     
  • 相关阅读:
    好的学习资源
    对paper有用的idea
    斜杠青年
    简书随笔
    点云专业英文单词
    通过 UDP 发送数据的简单范例
    简单的聊天时范例(客户端)
    键盘输入
    简单的传输文件范例
    编写serversocket简单示例1
  • 原文地址:https://www.cnblogs.com/farewell-farewell/p/5330100.html
Copyright © 2011-2022 走看看