C Language Course Design-student information management system, student management system C Language

Source: Internet
Author: User

C Language Course Design-student information management system, student management system C Language

# Include "stdio. h "// standard input/output function File Header description # include" math. h "// mathematical function header description # include" string. h "# include" stdlib. h "// use the function in the function header to change the background and color of the console # include" windows. h "// header file declaration. The following describes how to change the width and height of the console # define M 100 // macro definition description struct student {// struct definition and char name [25]; // name: char num [25]; // student ID: char credit [20]; // ID number: char native [35]; // Nationality: char tel [25]; // mobile phone number int special; // professional int banji; // class int math, yy, wl, cyy, pe; // mathematics, English, physics, C language, sports doub Le ave ;}; // average score //*********************************** ******************************** * *********** void input (struct student stu [M]); // Input Function void output (struct student stu [M]); // declaration of various user-defined functions void lookfor (struct student stu [M]); // query function void modify (struct student stu [M]); // modify function void order (struct student stu [M]); // sorting function void delete_student (struct student stu [M]); // delete function void xuehao (struct student Stu [M]); void xingming (struct student stu [M]); void fileread (struct student stu [M]); void filewrite (struct student stu [M]); void yanshi (char * p ); // description of the latency function //********************************* **************************************** * ******************** int count = 0; struct student t; int main () {int choice, sum; struct student stu [M]; system ("mode con: cols = 400 lines = 30000 "); // adjust the width and height of the console. system ("color 0b "); // Adjust the console background and font color point1: sum = 0; yanshi ("\ t \ 3 \ 3 \ 3 \ 3 \ 3 \ 3 \ 3 \ 3 \ 3 \ 3 \ 3 \ 3 \ 3 \ 3 welcome to the student information management system \ 3 \ 3 \ 3 \ 3 \ 3 \ 3 \ 3 \ 3 \ 3 \ 3 \ 3 \ n "); do {printf ("\ t ------------------------------------------------------- \ n "); printf ("\ t + student information management system + \ n "); printf ("\ t ------------------------------------------------------- \ n "); printf ("\ t ************** \ n "); printf ("\ t 1. Add Student Information \ n "); printf (" \ t 2. Browse student information \ n "); printf ("\ t 3. query student information \ n "); printf ("\ t 4. Modify student information \ n "); printf ("\ t 5. Delete student information \ n "); printf ("\ t 6. Arrange student information \ n "); printf ("\ t 7. Read File student \ n "); // read printf from the file ("\ t 8, save to file \ n "); // save to the printf file ("\ t 9, exit the System \ n "); printf ("\ t ************* ** \ N "); printf (" Enter your choice \ n "); scanf (" % d ", & choice); fflush (stdin ); // clear the input buffer if (choice> 9 | choice <= 0) {sum ++; if (sum> = 5) {printf ("too many input errors, the program starts again \ n "); system (" pause "); // The program pauses system (" cls "); // The clear screen statement goto point1 ;}} switch (choice) // call different functions to complete different tasks {case 1: input (stu); break; case 2: output (stu); break; case 3: lookfor (stu); break; case 4: modify (stu); break; case 5: delete_student (stu); break; case 6: order (stu); break; c Ase 7: fileread (stu); break; case 8: filewrite (stu); break; case 9: printf ("Thank you for using the student information management system. Please turn off the program !!! \ N "); system (" pause "); break; default: printf (" invalid choice !!! Please enter it again !!! \ N "); break;} while (choice! = 9); printf ("the program is over !!! \ N "); return 0;} void input (struct student stu [M]) // custom input Function {int len, size; system (" cls "); printf ("add student information to enter \ n"); do {printf ("Enter the student ID \ n" consisting of 11 digits "); // do-while loop application, prompting a certain number of input digits scanf ("% s", & stu [count]. num); len = strlen (stu [count]. num);} while (len! = 11); printf ("Enter your classmate's name \ n"); scanf ("% s", stu [count]. name); do {printf ("Enter the student ID number \ n" consisting of 18 digits); // same as scanf ("% s", & stu [count]. credit); size = strlen (stu [count]. credit);} while (size! = 18); printf ("Enter the student's nationality \ n"); scanf ("% s", & stu [count]. native); printf ("Enter the student's mobile phone number \ n"); scanf ("% s", & stu [count]. tel); printf ("Enter the required professional code: 1. Computer Science 2. Communication Engineering 3. network engineering \ n "); // This method solves the problem of difficult professional input scanf ("% d", & stu [count]. special); printf ("Enter the corresponding student class number: 1, 1301 2, 1302 \ n"); scanf ("% d", & stu [count]. banji); do {printf ("Please enter scores of different subjects not greater than 100 \ n"); scanf ("% d ", & stu [count]. math, & stu [count]. yy, & stu [count]. wl, & stu [count]. cyy, & stu [coun T]. pe);} while (stu [count]. math> 100 | stu [count]. yy> 100 | stu [count]. wl> 100 | stu [count]. cyy> 100 | stu [count]. pe> 100); // same as stu [count]. ave = (stu [count]. math + stu [count]. yy + stu [count]. wl + stu [count]. cyy + stu [count]. pe)/5.0; // calculate the average value count ++;} void output (struct student stu [M]) // custom output function {int j; system ("cls"); if (count = 0) {printf ("the current number of students is 0 \ n"); return ;}for (j = 0; j <count; j ++) {printf ("student ID \ t name \ t ID card number \ t nationality \ t mobile phone number \ t \ T major \ t class \ t mathematics \ t English \ t physics \ tC language \ t sports \ t average score \ n "); for (j = 0; j <count; j ++) {// for loop control the number of output printf ("% s \ t", stu [j]. num); printf ("% s \ t", stu [j]. name); printf ("% s \ t", stu [j]. credit); printf ("% s \ t", stu [j]. native); printf ("% s \ t", stu [j]. tel); if (stu [j]. special = 1) printf ("Computer Science \ t"); else if (stu [j]. special = 2) printf ("Communication Engineering \ t"); else printf ("network engineering \ t"); printf ("% d \ t", stu [j]. banji); printf ("% d \ t", stu [j]. math); printf ("% d \ t", stu [j]. y Y); printf ("% d \ t", stu [j]. wl); printf ("% d \ t", stu [j]. cyy); printf ("% d \ t", stu [j]. pe); printf ("%. 1lf \ t \ n ", stu [j]. ave) ;}} void lookfor (struct student stu [M]) // User-Defined student information query function {int j, flag = 0; char xh [25]; system ("cls"); if (count = 0) {printf ("the number of currently saved student information is 0, and cannot be queried !!! \ N "); return;} else {printf (" Enter your student ID \ n "); scanf (" % s ", & xh ); fflush (stdin); for (j = 0; j <count; j ++) {if (strcmp (stu [j]. num, xh) = 0) // compares the student information that has been saved through the character function, find the student {printf ("student ID \ t name \ t ID card number \ t nationality \ t mobile phone number \ t major \ t class \ t mathematics \ t \ t English \ t physical \ tC language \ t sports \ t average score \ n "); printf ("% s \ t", stu [j]. num); printf ("% s \ t", stu [j]. name); printf ("% s \ t", stu [j]. credit); printf ("% s \ t", stu [j]. native); printf ("% s \ t", stu [j]. tel); if (stu [j]. special = 1) printf ("count Computer Science \ t "); else if (stu [j]. special = 2) printf ("Communication Engineering \ t"); else printf ("network engineering \ t"); printf ("% d \ t", stu [j]. banji); // consider an alignment factor printf ("% d \ t", stu [j]. math); printf ("% d \ t", stu [j]. yy); printf ("% d \ t", stu [j]. wl); printf ("% d \ t", stu [j]. cyy); printf ("% d \ t", stu [j]. pe); printf ("%. 1lf \ t ", stu [j]. ave) ;}} if (j = count) printf ("sorry, no student information you need \ n ");}} void modify (struct student stu [M]) // UDF {int j, flag = 0, course; char xh [25]; syste M ("cls"); if (count = 0) {printf ("the number of currently saved student information is 0 and cannot be modified !!! \ N "); return;} else {printf (" Enter your student ID \ n "); scanf (" % s ", & xh ); fflush (stdin); for (j = 0; j <count; j ++) if (strcmp (stu [j]. num, xh) = 0) // same as {printf ("are you sure you want to modify the student information ??? If you are not sure, please turn off this program !!! \ N "); printf (" Selected Courses: 1, mathematics 2, English 3, physics 4, C language 5, sports \ n "); scanf (" % d ", & course); printf ("Enter your Student Score \ n"); switch (course) {case 1: scanf ("% d ", & stu [j]. math); break; case 2: scanf ("% d", & stu [j]. yy); break; // switch control statement case 3: scanf ("% d", & stu [j]. wl); break; case 4: scanf ("% d", & stu [j]. cyy); break; case 5: scanf ("% d", & stu [j]. pe); break; default: printf ("invalid choice !!! Please enter it again !!! \ N "); break ;}}} void delete_student (struct student stu [M]) // custom delete function {int choice; system (" cls "); if (count = 0) {printf ("the number of currently saved student information is 0 and cannot be deleted !!! \ N "); return;} else {printf (" select the method you want to delete: 1. Student ID 2. Name (if your name is in Chinese, it cannot be deleted, select the student ID to delete. 3. Cancel \ n "); scanf (" % d ", & choice); switch (choice) // The switch statement selects the method to delete the user {case 3: return; break; case 2: xingming (stu); break; // Use case 1: xuehao (stu); break; default: printf ("invalid choice !!! Please enter it again !!! \ N "); break ;}} void order (struct student stu [M]) // the definition of the sorting function {int j, k, choice, index; system ("cls"); printf ("Enter the method you want to sort (all sorting methods are in descending order )!!! \ N "); printf (" 1, mathematics 2, English 3, physics 4, C language 5, sports 6, average score \ n "); scanf (" % d ", & choice); switch (choice) {case 1: for (j = 0; j <count; j ++) {index = j; for (k = j + 1; k <count; k ++) if (stu [k]. math> stu [index]. math) {t = stu [k]; stu [k] = stu [index]; stu [index] = t ;}}; break; case 2: for (j = 0; j <count; j ++) {index = j; for (k = j + 1; k <count; k ++) if (stu [k]. yy> stu [index]. yy) {stu [k] = stu [index] ;}// the entire sorting part adopts the so-called method of selecting and sorting}; break; case 3: for (j = 0; j <count; J ++) {index = j; for (k = j + 1; k <count; k ++) if (stu [k]. wl> stu [index]. wl) {t = stu [k]; stu [k] = stu [index]; stu [index] = t ;}}; break; case 4: for (j = 0; j <count; j ++) {index = j; for (k = j + 1; k <count; k ++) if (stu [k]. cyy> stu [index]. cyy) {t = stu [k]; stu [k] = stu [index]; stu [index] = t ;}}; break; case 5: for (j = 0; j <count; j ++) {index = j; for (k = j + 1; k <count; k ++) if (stu [k]. pe> stu [index]. pe) {t = stu [k]; stu [k] = stu [index]; stu [index] = t ;}}; Break; case 6: for (j = 0; j <count; j ++) {index = j; for (k = j + 1; k <count; k ++) if (stu [k]. ave> stu [index]. ave) {t = stu [k]; stu [k] = stu [index]; stu [index] = t ;}// the force type conversion symbol can only be used with operands, according to the type conversion problem in the value assignment operation, we can see}; break; default: printf ("invalid choice !!! Please enter it again !!! \ N "); break ;}} void xuehao (struct student stu [M]) // you can customize the student information deletion function {int j, index = 0, k = count; char xh [25]; system ("cls"); printf ("Enter the student ID you want to delete \ n"); scanf ("% s ", xh); fflush (stdin); for (j = 0; j <count; j ++) {if (strcmp (stu [j]. num, xh) = 0) {for (j = index; j <count; j ++) stu [j] = stu [j + 1]; count --; if (count <k) printf ("You have deleted successfully \ n");} index ++;} if (j = count) printf ("Sorry !!! No student information you need to delete! *_*! \ N ");} void xingming (struct student stu [M]) // User-Defined student information deletion function {int flag = 0, j, k = count; char xm [25]; system ("cls"); printf ("enter the name of the student you want to delete \ n"); scanf ("% s", xm ); fflush (stdin); for (j = 0; j <count; j ++) {if (strcmp (stu [j]. num, xm) = 0) {for (j = flag-1; j <count; j ++) stu [j] = stu [j + 1]; count --; if (count <k) printf ("You have deleted successfully \ n");} flag ++;} if (j = count) printf ("Sorry !!! No student information you need to delete! *_*! \ N ");} void yanshi (char * p) // definition of the latency function {while (1) {if (* p! = 0) printf ("% c", * p ++); elsebreak; Sleep (100 ); // intermittent latency control statement} void filewrite (struct student stu [M]) // Write FILE function definition {int j = 0; char c; FILE * fp; printf ("Please choose whether to save the entered student information: 'y' or 'N '??? \ N "); scanf (" % c ", & c); fflush (stdin); while (c! = 'Y' & c! = 'N') {if (c! = 'Y' & c! = 'N') printf ("input error, please input \ n" again); printf ("the following operations will overwrite the stored data, are you sure you want to enter 'y' or 'N '??? \ N "); scanf (" % c ", & c); fflush (stdin);} if (c = 'y ') {if (fp = fopen ("d :\\ stu. dat "," wb ") = NULL) {printf (" file opening error, \ n cannot be performed by the program "); exit (0) ;}for (j = 0; j <count; j ++) {fwrite (& stu [j], sizeof (struct student), 1, fp) ;}fclose (fp ); if (count = 0) printf ("no file, cannot save \ n"); elseprintf ("Data Storage completed \ n"); system ("pause ");} elsereturn;} void fileread (struct student stu [M]) // function definition for reading FILE information {int j = 0; char c; FILE * fp; system ("cls "); printf ("Please select whether to save the entered student information: 'y 'Or 'N '??? \ N "); scanf (" % c ", & c); fflush (stdin); while (c! = 'Y' & c! = 'N') {if (c! = 'Y' & c! = 'N') printf ("input error, please input \ n" again); printf ("the following operations will overwrite the stored data, are you sure you want to enter 'y' or 'N '??? \ N "); scanf (" % c ", & c); fflush (stdin);} if (c = 'y ') {if (fp = fopen ("d :\\ stu. dat "," rb ") = NULL) {printf (" An error occurred while opening the file. The program cannot perform \ n "); exit (0 );} fread (& stu [j], sizeof (struct student), 1, fp); count = 0; count ++; j ++; while (fread (& stu [j], sizeof (struct student), 1, fp) {j ++; count ++;} fclose (fp ); printf ("Data Reading is complete !!! \ N "); system (" pause ");} elsereturn ;}

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.