Student information Management system of C language course design

Source: Internet
Author: User
Tags clear screen fread function definition stdin strcmp

#include "stdio.h"//Standard input Output function file Header description # include "MATH.H"//Math Function Header Description # include "String.h" #include "stdlib.h"    Using the function in the head of the function, change the console background and color # include "windows.h"//header file declaration, the following is used to change the console width and height # # 100//Macro definition description struct student{     struct defines and declares Char name[25];     Name Char num[25];    Study number char credit[20];    Social Security Number char native[35];     Birthplace Char tel[25];     mobile number int special;      professional int Banji;   class int math,yy,wl,cyy,pe;     Mathematics, English, physics, C language, sports double Ave;}; Declaration of the average//**************************************** function ********************************************void input (     struct student stu[m]);     Input function void output (struct student stu[m]);    Declaration of various types of user-defined functions void lookfor (struct student stu[m]);     query function void Modify (struct student stu[m]);     Modify the function void order (struct student stu[m]);   sort 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); Delay Function Description//**********************************************************************************************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 background and font color of the console Point1:sum=0;yanshi ("\t\t\t\t\t\t\t\t\3\3\3\3\3\3\3\3\3\3\3\3\3 welcome you to use the Student information management system \3\3\3\3\3\3\3\3\3\ 3\n ");d o {printf (" \t\t\t\t\t\t\t\t-------------------------------------------------\ n ");p rintf (" \t\t\t\t\t\t\t\ t+ Student Information Management System +\n ");p rintf (" \t\t\t\t\t\t\t\t-------------------------------------------------\ n ");p rintf (" \t\t\t\t \t\t\t\t\t\t ***************\n ");p rintf (" \t\t\t\t\t\t\t\t\t\t 1, add student information \ n ");p rintf (" \t\t\t\t\t\t\t\t\t\t 2, browse student information \ n ");p rintf (" \t\t\t\t\t\t\t\t\t\t 3, inquiry student information \ n ");p rintf (" \t\t\t\t\t\t\t\t\t\t 4, modify student information \ n ");p rintf (" \t\t\t\t\t\t\t\t \t\t 5, delete student information \ n ");p rintf (" \t\t\t\t\t\t\t\t\t\t 6, arranging student information \ n "); printf ("\t\t\t\t\t\t\t\t\t\t 7, read file student \ n");//read printf from a file ("\t\t\t\t\t\t\t\t\t\t 8, save to file \ n");   Save to file printf ("\t\t\t\t\t\t\t\t\t\t 9, exit system \ n"); printf ("\t\t\t\t\t\t\t\t\t\t ***************\n");       printf ("Please enter your choice \ n"); scanf ("%d", &choice); Fflush (stdin); Clears the input buffer if (choice>9| |        choice<=0) {sum++;if (sum>=5) {printf ("The number of input errors is too many, the program will restart \ n"); system ("pause");   Program pauses system ("CLS"); Clear screen statement goto Point1;}}       Switch (choice)///depending on the selection, call different functions to accomplish different tasks {case 1:input (STU); 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;case 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 selection!!! Please re-enter!!! \ n "); break;}} while (choice!=9);p rintf ("the program was over!!! \ n "); return 0;} void input (struct student stu[m])//Custom input function {int Len,size;system ("cls");p rintf ("Please add information to enter students \ n");d o {printf ("Enter by 11 digits   The student number of the composition "\ n"); Do-while loop application, prompting the number of input digits for a certain number of scanf ("%s", &stu[count].num); Len=strlen (Stu[count].num);}   while (len!=11);p rintf ("Please enter the name of the classmate \ n"), scanf ("%s", Stu[count].name);d o {printf ("Please enter a student ID number consisting of 18 digits \ n"); Ibid. scanf ("%s", &stu[count].credit); Size=strlen (Stu[count].credit);} while (size!=18);p rintf ("Please enter the student's place of Origin \ n"), scanf ("%s", &stu[count].native);p rintf ("Please enter the student's mobile phone number \ n"); scanf ("%s",  &stu[count].tel);p rintf ("Please enter the required professional code: 1, Computer science 2, communications Engineering 3, network engineering \ n"); Using this method solves the difficulty of professional input scanf ("%d", &stu[count].special);p rintf ("Please enter the corresponding student class number: 1, 1301 2, 1302 \ n"); scanf ("%d",& Stu[count].banji);d o {printf ("Please enter not more than 100 students ' grades \ \") scanf ("%d%d%d%d%d", &stu[count].math,&stu[count].yy , &stu[count].wl,&stu[count].cyy,&stu[count].pe);} while (stu[count].math>100| | stu[count].yy>100| | stu[count].wl>100| | stu[count].cyy>100| |   STU[COUNT].PE&GT;100);       Ibid. stu[count].ave= (stu[count].math+stu[count].yy+stu[count].wl+stu[count].cyy+stu[count].pe)/5.0; Find the average count++;} void output (struct student stu[m])//Custom output function {int J;system ("CLS"); if (count==0) {printf ("Current saved student information is 0 \ n"); rEturn;} for (j=0;j<count;j++) {printf ("\t\t" name \t\t ID # \ t native number \ t phone number \t\t professional \t\t class \ t math \ t english \ \ Physical \TC language \ t sports \ t \ n "); for (j=0;j <count;j++) {//for loop control output number printf ("%s\t", Stu[j].num);p rintf ("%s\t", Stu[j].name);p rintf ("%s\t", Stu[j].credit) ;p rintf ("%s\t", stu[j].native);p rintf ("%s\t", Stu[j].tel), if (stu[j].special==1) printf ("Computer science \ T"); else if (stu[j].    special==2) printf ("Communications engineering \ T");      else printf ("Network engineering \ T"); printf ("%d\t", Stu[j].banji);p rintf ("%d\t", Stu[j].math);p rintf ("%d\t", Stu[j].yy);p rintf ("%d\t", STU[J].WL); printf ("%d\t", Stu[j].cyy);p rintf ("%d\t", stu[j].pe);p rintf ("%.1lf\t\n", Stu[j].ave);}}} void lookfor (struct student stu[m])//Custom query Student information function {int J,flag=0;char xh[25];system ("CLS"); if (count==0) {p rintf ("The current saved student information is 0 and cannot be queried!!! \ n "); return;} else{printf ("Please enter the student number you want to see \ n"), scanf ("%s", &xh), Fflush (stdin), for (j=0;j<count;j++) {if (strcmp, XH)////(==0)//through the character function to compare the deposited student information, find out the students to view {printf ("Student number \t\t name \t\t ID number \ t" T-phone number \t\t professional \t\t class \ t math T-English \ t physical \TC language \ t sports \ t average score \ n ");printf ("%s\t", Stu[j].num);p rintf ("%s\t", Stu[j].name);p rintf ("%s\t", Stu[j].credit);p rintf ("%s\t", stu[j].native)    ;p rintf ("%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");p rintf ("%d\t", Stu[j].banji); Consider an alignment factor of printf ("%d\t", Stu[j].math);p rintf ("%d\t", Stu[j].yy);p rintf ("%d\t", STU[J].WL);p rintf ("%d\t", Stu[j]. CYY);p rintf ("%d\t", stu[j].pe);p rintf ("%.1lf\t", Stu[j].ave);}} if (j==count) printf ("Sorry, there is no student information you need \ n");}} void Modify (struct student stu[m])//Custom modify function {int J,flag=0,course;char xh[25];system ("CLS"); if (count==0) {printf (" There are 0 currently saved student information and cannot be modified!!! \ n "); return;} else{printf ("Please enter the student number you want to modify \ n"), scanf ("%s", &xh), Fflush (stdin); for (j=0;j<count;j++) if (strcmp (Stu[j].num), XH) ==0)//ibid. {printf ("Are you sure you want to change the student's information??? If you are not sure, please turn off this program!!! \ n ");p rintf (" Select course: 1, Math 2, English 3, physical 4, C 5, sports \ n ") scanf ("%d ", &course);p rintf (" Please enter the student score you want to modify \ 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", &AMP;STU[J].WL), Break;case 4:scanf ("%d", &stu[j].cyy), Break;case 5:scanf ("%d", &AMP;STU[J].PE); break;default:printf ("Invalid selection!!! Please re-enter!!! \ n "); }}}void delete_student (struct student stu[m])//Custom delete function {int Choice;system ("CLS"); if (count==0) {printf ("Current saved student information is 0, Cannot delete!!! \ n "); return;} else{printf ("Please select the way you want to delete: 1, number 2, name (if your name is Chinese, you can not delete, please select the number to delete) 3, cancel \ n"); scanf ("%d", &choice); switch (choice)//         The switch statement selects the way the user wants to delete {case 3:return;break;case 2:xingming (STU); Apply Case 1:xuehao (STU) between user-defined functions, break;default:printf ("Invalid selection!!! Please re-enter!!! \ n "); break;}} void order (struct student stu[m])//The definition of the sort function {int J,k,choice,index;system ("cls");p rintf ("Enter the way you want to sort (all sorts are in descending order)!! !\n ");p rintf (" 1, Math 2, English 3, physical 4, C 5, sports 6, average \ 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[ind     ex]=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) {s Tu[k]=stu[index];} The whole for the sort part, using the so-called choice of sorting Method};break;case 3:for (j=0;j<count;j++) {index=j; for (k=j+1;k<count;k++) if (stu[k     ].WL&GT;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&GT;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;} Forcing a type conversion symbol can only be used with operands, depending on the type conversion problem in the assignment operation};break;default:printf ("Invalid selection!!! Please re-enter!!! \ n "); break;}} void Xuehao (struct student stu[m])//Custom Delete student information function {int by learning number methodJ,index=0,k=count;char Xh[25];system ("CLS");p rintf ("Please enter the student number 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 the success \ n");} index++;} if (j==count) printf ("Sorry!!! Without the student information you need to delete!*_*!\n ");} void xingming (struct student stu[m])//Customize delete student information by name the function {int Flag=0,j,k=count;char xm[25];system ("CLS");p rintf (" Please enter the name of the student you wish to delete \ n "), scanf ("%s ", XM), Fflush (stdin); for (j=0;j<count;j++) {if (strcmp (STU[J].NUM,XM) ==0) { flag-1;j<count;j++) stu[j]=stu[j+1];count--;if (count<k) printf ("You have deleted the success \ n");} flag++;} if (j==count) printf ("Sorry!!! Without the student information you need to delete!*_*!\n ");} void Yanshi (char *p)//delay function definition {while (1) {if (*p!=0) printf ("%c", *p++); elsebreak;               Sleep (100); Delay control discontinuity Statement}}void filewrite (struct student stu[m])//write file function definition {int J=0;char c; FILE *fp;printf ("Please select whether you want to deposit the student information you have entered: ' Y ' or ' n '??? \ n "); scanf ("%c ", &c); Fflush (stdin); while (c!= ' y ' &&c!= ' n ') {if (c!= ')Y ' &&c!= ' n ') printf ("Input error, re-enter \ n");p rintf ("The following actions will overwrite the stored data, make sure to enter ' y ' or ' n '??? \ n "); scanf ("%c ", &c); Fflush (stdin);} if (c== ' y ') {if ((Fp=fopen ("D:\\stu.dat", "WB") ==null) {printf ("File open error, program cannot do \ n"); 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 store complete \ n"); system ("pause"); Elsereturn;} void Fileread (struct student stu[m])//Read file information function definition {int J=0;char c; FILE *fp;system ("CLS");p rintf ("Select whether you want to deposit the student information you have entered: ' Y ' or ' n '??? \ n "), scanf ("%c ", &c), Fflush (stdin), while (c!= ' y ' &&c!= ' n ') {if (c!= ' y ' &&c!= ' n ') printf (" Input error, Please re-enter \ n ");p rintf (" The following actions will overwrite the stored data, make sure to enter ' y ' or ' n '??? \ n "); scanf ("%c ", &c); Fflush (stdin);} if (c== ' y ') {if ((Fp=fopen ("D:\\stu.dat", "RB") ==null) {printf ("File open error, program cannot do \ 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);p rintf ("Data read!!! \ n "); system (" Pause ");} Elsereturn;}

Student information Management system of C language course design

Related Article

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.