The realization of student information management system with C language array

Source: Internet
Author: User
Tags sorted by name strcmp
OverviewUsing only a number of arrays to manage student performance information, do not use the structure, the main difficulty of the program is based on the school number or the total score of the student Information ranking, with the help of a temporary array to mark the order of the subscript. The results of the operation are as follows:
Enter data:

Print Data:

Sort information according to the school number:

Sort the information according to the total score:

Delete a message according to the school number:
The code is as follows:
#include <stdio.h> #include <stdlib.h>//exit function header file #include <string.h>//String related exercise
As header file #define Max_student 30//MAX student//function declaration, this program has 10 sub functions, each function corresponds to an operation void student_scanf (int n);
void student_printf (int n);
int student_find_name (int n);
int student_find_num (int n);
void Student_sort_num (int n);
void Student_sort_sum (int n);
int student_alter_num (int n);
int student_alter_name (int n);
int student_delete_num (int n);
int student_delete_name (int n);
Global array variable, for storing student information Char names[max_student][50];
int math[max_student];
int english[max_student];
int computer[max_student];
int sum[max_student];
int num[max_student];
The following variables are used to sort the student information array as a temporary array int temp_num[max_student];
Char temp_names[max_student][50];
int temp_math[max_student];
int temp_english[max_student];
int temp_computer[max_student];
int temp_sum[max_student];
The sort array stores the ordered number or name subscript int sort[max_student];

Cyclic global variable int i, J;
    Main main function int main (void) {int choice,n;
    while (1){printf ("*************************************\n");
        printf ("Welcome to use the Student performance management system \ n");
        printf ("[1] Enter all student information \ n");
        printf ("[2] output all student scores \ n");
        printf ("[3] Find a student's information by school number \ n");
        printf ("[4] Find a student's information by name \ n");
        printf ("[5] sort the student by school number \ n");
        printf ("[6] ranking students by total score \ n");
        printf ("[7] Modify a student's information by school number");
        printf ("[8] Modify a student's information by name \ n");
        printf ("[9] Delete a student's information by school number \ n");
        printf ("[10] Delete a student's information by name \ n");
        printf ("[0] quits the program \ n");
        printf ("Please enter your choice (0-9):");
        scanf ("%d", &choice);

        printf ("**************************************)");
            Switch (choice) {case 1://input;
            printf ("Please enter the number of student information entered:"); 
            scanf ("%d", &n);
            STUDENT_SCANF (n);

        Break
            Case 2://output;
            STUDENT_PRINTF (n);

        Break
            Case 3://Find Student_find_num (n) According to the study number;

        Break
   Case 4://Search Student_find_name (n) based on name;         Break
            Case 5://sorted by school number Student_sort_num (n);

        Break
            Case 6://sorted by name Student_sort_sum (n);

        Break
            Case 7://Modify Student_alter_num (n) According to the school number;

        Break
            Case 8://Modify Student_alter_name (n) by name;

        Break
            Case 9://Delete student_delete_num (n) by school number;
            n--;

        Break
            Case 10://Delete student_delete_name (n) by name;
            n--;

        Break
            Case 0://Exit program printf ("Exit program \ n");
            printf ("End of program, thank you for using!\n");

        Exit (0); Default:printf ("The menu you entered is incorrect.) Please re-enter it.

        \ n ");
} return 0;
        //1. Enter information void student_scanf (int n) {for (i = 0; i<n; ++i) {printf ("\ n Please enter information for%d students: \ n", i + 1);
        printf ("\ n School Number:");
        scanf ("%d", &num[i]);
        printf ("\ n name:");
        scanf ("%s", Names[i]);
        printf ("\ n Math score:"); scanf ("%d", &math[i]);
        printf ("\ n English score:");
        scanf ("%d", &english[i]);
        printf ("\ n computer score:");
        scanf ("%d", &computer[i]);
    Computed total score Sum[i] = Math[i] + english[i] + computer[i];
    }//2. Print information void student_printf (int n) {printf ("\ n \ t name \ s math score \ t English score \ t computer results \ t total score \ n");

    printf ("----------------------------------------------------------\ n"); for (i = 0; i<n; ++i) {printf ("%d\t%s\t%d\t\t%d\t\t%d\t\t%d\n", Num[i), Names[i], math[i], english[i], com
    Puter[i], sum[i]);
printf ("-------------------------------------------------------\ n");
    //3. Find int Student_find_num (int n) {int nums by school number;
    int result;
    printf ("Please enter the student number to find:");
    scanf ("%d", &nums);
    result=-1;

            for (i = 0; i<n; ++i) {if (Nums = = Num[i]) {result = I;
        Break
        }//FINAL judge Q value if (result = = 1) {printf ("No Student Information!\n");
    return 0;
 }   else {///First print header printf ("\ r \ n \t\t name \t\t math score \ t English score \ t computer results \ t total score \ n"); Reprint data printf ("%d\t\t%s\t\t%d\t\t%d\t\t%d\t%d\n", Num[result], Names[result], Math[result], English[result], com
        Puter[result], Sum[result]);
    printf ("Print out Find results!\n");
return 1;
    //4. Find score int student_find_name (int n) {char name[200] by name;
    int result;
    printf ("Please enter the name of the student to be found:");
    scanf ("%s", name);
    result =-1;
            for (i = 0; i<n; ++i) {if (strcmp (name, names[i)) = = 0) {result = I;
        Break
        } if (result = = 1) {//No results were found printf ("No such student information!\n");
    return 0;
        else//found the result {printf ("\ n \ t name \ t math score \ t score \ t computer score \ t score \ \ n"); printf ("%d\t%s\t%d\t\t%d\t\t%d\t\t%d\n", Num[result], Names[result], Math[result], English[result], Computer[result
        ], Sum[result]);
    printf ("Completed lookup!\n");
return 1; //5. Sorting by school number void Student_sort_num (int n) {int miN,max;
    For (i=0 i<n; ++i)//Copy temporary array {temp_num[i] = Num[i];        max = 0; Finds the max value of the number and places it in the last value of the sort array for (J=1 j<n; j + +) {if (temp_num[max]<temp_num[j)) max =
    J    } sort[n-1] = max;        The last number of the sort array for (i=0; i<n-1; ++i) {min = i;
        Lookup number minimum for (j=0; j<n; ++j) {if (temp_num[min]>temp_num[j)) min = j;
        //sort the index of the student information sorted by the array record sort[i] = min;      Temp_num[min] = Temp_num[max]; 
        Use a temporary array to set the number of student information you have searched to maximum, exclude lookup interference} for (i=0; i<n; ++i)//And then copy the temporary array {temp_num[i] = Num[i];
        strcpy (Temp_names[i],names[i]);
        Temp_math[i] = Math[i];
        Temp_english[i] = English[i];
        Temp_computer[i] = Computer[i];
    Temp_sum[i] = Sum[i]; 
        For (i=0 i<n; i++)//To modify the original array by subscript {Num[i] = temp_num[sort[i]]; strcpy (Names[i],temp_names[sort[i]]); 
        Math[i] = temp_math[sort[i]]; 
        English[i] = temp_english[sort[i]]; 
        Computer[i] = temp_computer[sort[i]];
    Sum[i] = temp_sum[sort[i]]; printf ("Sorted out," click Menu key 2 to see the sort results.)
    \ n ");
return;
    //6. Sorted by total score void student_sort_sum (int n) {int min,max;
    For (i=0 i<n; ++i)//Copy temporary array {temp_sum[i] = Sum[i];        max = 0;  Find the maximum total score, place it next to the last value in the sort array for (J=1 j<n; j + +) {if (temp_sum[max]<temp_sum[j)) max =
    J    } sort[n-1] = max;        The last number of the sort array for (i=0; i<n-1; ++i) {min = i;
        Find the total score minimum for (j=0 j<n; ++j) {if (temp_sum[min]>temp_sum[j)) min = j;
        //sort the index of the student information sorted by the array record sort[i] = min;      Temp_sum[min] = Temp_sum[max]; 
        Use a temporary array to set the total score of the searched student information to the maximum, excluding lookup interference} for (i=0 i<n; ++i)//duplicate the temporary array {temp_num[i] = Num[i]; strcpy (temp_names[I],names[i]);
        Temp_math[i] = Math[i];
        Temp_english[i] = English[i];
        Temp_computer[i] = Computer[i];
    Temp_sum[i] = Sum[i]; 
        For (i=0 i<n; i++)//To modify the original array by subscript {Num[i] = temp_num[sort[i]]; 
        strcpy (Names[i],temp_names[sort[i]]); 
        Math[i] = temp_math[sort[i]]; 
        English[i] = temp_english[sort[i]]; 
        Computer[i] = temp_computer[sort[i]];
    Sum[i] = temp_sum[sort[i]]; printf ("Sorted out," click Menu key 2 to see the sort results.)
    \ n ");
return;
    //7. Modify student information by school number int Student_alter_num (int n) {int nums;
    int result;
    printf ("Please enter the student number to be modified:");
    scanf ("%d", &nums);
    result=-1;
            for (i = 0; i<n; ++i) {if (Nums = = Num[i]) {result = I;
        Break
        }//FINAL judge Q value if (result = = 1) {printf ("No Student Information!\n");
    return 0;
        else//Modify info Value {printf ("Please re-enter this student information: \ n");
        printf ("School Number: \ n"); scanf ("%d", &Amp;num[result]);
        printf ("Name: \ n"); 
        scanf ("%s", Names[result]);
        printf ("Math score: \ n");
        scanf ("%d", &math[result]);
        printf ("English score: \ n");
        scanf ("%d", &english[result]);
        printf ("Computer score: \ n");
        scanf ("%d", &computer[result]);
    Sum[result] = Math[result] + English[result] + Computer[result];
return 1;
    //8. Modify student information by name int student_alter_name (int n) {char name[50];
    int result;
    printf ("Please enter the name of the student to be modified:");
    scanf ("%s", name);
    result=-1;
            for (i = 0; i<n; ++i) {if (strcmp (name,names[i)) ==0) {result = I;
        Break
        }//FINAL judge Q value if (result = = 1) {printf ("No Student Information!\n");
    return 0;
        else//Modify info Value {printf ("Please re-enter this student information: \ n");
        printf ("School Number: \ n");
        scanf ("%d", &num[result]);
        printf ("Name: \ n"); 
        scanf ("%s", Names[result]);
        printf ("Math score: \ n"); scanf ("%d", &math[result]);
        printf ("English score: \ n");
        scanf ("%d", &english[result]);
        printf ("Computer score: \ n");
        scanf ("%d", &computer[result]);
    Sum[result] = Math[result] + English[result] + Computer[result];
return 1;
    //9. Delete Student information by school number int Student_delete_num (int n) {int nums;
    int result;
    printf ("Please enter the student number to be deleted:");
    scanf ("%d", &nums);
    result=-1;
            for (i = 0; i<n; ++i) {if (Nums = = Num[i]) {result = I;
        Break
        }//FINAL judge Q value if (result = = 1) {printf ("No Student Information!\n");
    return 0; 
        else///delete the current student information is to move the array from the position of result to the previous position {for (i=result; i<n-1; ++i)//Last in the main function, you want to subtract the value of N by 1 
            {Num[i] = num[i+1]; 
            strcpy (names[i],names[i+1]); 
            Math[i] = math[i+1]; 
            English[i] = english[i+1]; 
            Computer[i] = computer[i+1];
        Sum[i] = sum[i+1];
   } 

    } return 1;
    //10. Delete Student information by name int student_delete_name (int n) {char name[50];
    int result;
    printf ("Please enter the name of the student to be deleted:");
    scanf ("%s", name);
    result=-1;
            for (i = 0; i<n; ++i) {if (strcmp (name,names[i)) ==0) {result = I;
        Break
        }//FINAL judge Q value if (result = = 1) {printf ("No Student Information!\n");
    return 0; 
        else///delete the current student information is to move the array from the position of result to the previous position {for (i=result; i<n-1; ++i)//Last in the main function, you want to subtract the value of N by 1 
            {Num[i] = num[i+1]; 
            strcpy (names[i],names[i+1]); 
            Math[i] = math[i+1]; 
            English[i] = english[i+1]; 
            Computer[i] = computer[i+1];
        Sum[i] = sum[i+1];
} return 1; 

 }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.