The Student information management system in the design of the curriculum of the freshman C language

Source: Internet
Author: User
Tags strcmp


the first time to write such a long program, the code is only for reference, there are questions please leave a message.


/*** Student Information Management system **ide:dev-cpp 4.9.9.2**2014-6-15*/#include <stdio.h> #include <stdlib.h> #include < string.h> #include <algorithm> #include <vector>using std::sort;using std::vector;/*== storage Unit node ==*/ struct student{//character array for easy unified input char name[50], address[100], email[50], id[20],age[5], birth[20], tel[20], gender[5];}; vector<student> myvec;/*========== function declaration Area ==========*//*-Print Main Menu declaration-*/void Printmainmenu ();/*-main interface function declaration-*/void  Enterinformation ();  1void browseinformation ();  2void inquireinformation ();  3void modifyinformation ();  4void deleteinformation ();  5void SaveToFile ();//6void readfromfile ();//7void exitinformation (); 0/*--declaration of the main interface function--*/void inquireonestudent (student *); void modifyonestudent (student *);/*--Change individual information--*/void Modifyoneid (student *); void Modifyonename (student *); void Modifyoneage (student *); void Modifyonegender (student *); void Modifyonebirth (student *), void Modifyonetel (student *), void modifyoneaddress (student *), void Modifyoneemail ( Student *); void Modifytomain (student *); This fact does not require a form of participation, just for unified jump table Interface/*--Delete a student--*/void deleteonestudent (student *);/*--Show all information about a student--*/void displayonestudent (student *);/*--browsing mode--*/void browseplain (); Direct view of void Browsebyid (); void Browsebyname (); void Browsebybirth (); void Browsetomain ();/*--query mode--*/void Inquirebyid () ; void Inquirebyname ();/*-function pointer array-*/void (*mainpointerarr[]) () = {exitinformation, enterinformation, browseinformation , Inquireinformation,modifyinformation, Deleteinformation, SaveToFile, Readfromfile};void (*modifyOne[]) (student *) = {modifytomain, Modifyoneid, Modifyonename,modifyoneage, Modifyonegender, Modifyonebirth,modifyonetel, Modifyoneaddress, Modifyoneemail};void (*browsearray[]) () = {Browsetomain, browseplain, Browsebyid, BrowseByName, browsebybirth};/*========== function Definition Area ==========*//*-main interface menu function-*/void Printmainmenu () {printf ("\t\t\t Student information Management system of Henan Polytechnic University \ n" );p rintf ("\t\t ======================================\n");p rintf ("\t\t | | \T\T1, Student Information Entry \t| | \ n ");p rintf (" \t\t | | \T\T2, Student information Browse \t| | \ n ");printf ("\t\t | | \T\T3, Student Information Inquiry \t| | \ n ");p rintf (" \t\t | | \T\T4, Student information Change \t| | \ n ");p rintf (" \t\t | | \T\T5, Student information Delete \t| | \ n ");p rintf (" \t\t | | \T\T6, Student Information Archive \t| | \ n ");p rintf (" \t\t | | \T\T7, Student information reading \t| | \ n ");p rintf (" \t\t | | \T\T0, Exit management System \t| | \ n ");p rintf (" \t\t ======================================\n ");p rintf (" \t\t\t\t\t\t original Chu Zhenggang \ n ");p rintf (" \t\t\t\t\t\ T completion time: June 17, 2014 \ n ");p rintf (" \t\t\t\t\t\temail:[email protected]\n ");p rintf (" Please select function: "); int num;scanf ("%d ", &num);(*mainpointerarr[num]) ();} /*-Information Entry-*/void enterinformation () {//1system ("CLS");p rintf ("Enter student information: \ n");p rintf ("Please enter study number:"); int len; student temp; while (gets (temp.id) &&!strlen (temp.id)); Filter Cache Enter printf ("Please enter Name:"); while (Temp.name &&!strlen (temp.name)); Filter Cache Enter printf ("Please enter Age:"); while (gets (temp.age) &&!strlen (temp.age)); Filter Cache Enter printf ("Please enter Gender:"); while (gets (Temp.gender) &&!strlen (Temp.gender)); Filter Cache Enter printf ("Please enter Birthday:"); while (Temp.birth &&!strlen (Temp.birth)); Filter cache return to printf ("Please enter Phone:"); while (gets (tEmp.tel) &&!strlen (Temp.tel)); Filter Cache Enter printf ("Please enter Address:"); while (Temp.address &&!strlen (temp.address)); Filter Cache Enter printf ("Please enter email:"); while (Temp.email &&!strlen (temp.email)); Filter Cache carriage return Myvec.push_back (temp), System ("CLS");p rintf ("OK, entry successful, the student information such as the following: \ n"); len = Myvec.size ()-1; Inquireonestudent (&myvec[len]);} void BrowseInformation () {//2if (Myvec.empty ()) {printf ("There is no student information detected whatsoever!") Please browse after inputting! \ nthe system will be returned to the main interface \ n "); system (" pause "); Browsetomain ();} printf ("Please select function: \ n");p rintf ("1, browse \ n");p rintf ("2, browse \ n by School number");p rintf ("3, browse \ n by name");p rintf ("4, browse by birthdays"); printf ("0, return to main menu \ n"); int num; scanf ("%d", &num);(*browsearray[num]); BrowseInformation (); void Inquireinformation () {//3if (Myvec.empty ()) {printf ("No data, no query!") The system will return to the main menu \ n "), System (" pause "); Browsetomain (); return;} printf ("Please select function:");p rintf ("1, enter the study number \ n");p rintf ("2, enter name query \ n");p rintf ("0, return to main menu \ n"); int num; scanf ("%d", &num), if (num = = 1) Inquirebyid (), else if (num = = 2) inquirebyname (); System ("pause"); Browsetomain ();} void MoDIfyinformation () {//4 printf ("Please enter the student number to be changed:"), Char buf[20];while (Get (BUF),!strlen (BUF));//filter empty string still vector< Student>::iterator it = Myvec.begin (); for (; It! = Myvec.end (); ++it) {if (strcmp (buf, it->id) = = 0) {modifyonestudent (&myvec[it-myvec.begin ()]); return;}} printf ("No find! \ n ");} void Deleteinformation () {//5if (Myvec.empty ()) {printf ("No data is available for deletion and the system returns to the main menu.") \ n "); system (" pause "); Browsetomain (); return;} printf ("Choose function: \ n");p rintf ("1, clear all data \ n");p rintf ("2, delete information for a specific student \ n");p rintf ("0, return to main menu \ n"); int num; scanf ("%d", &num), if (1 = = num) {myvec.clear ();p rintf ("successfully clears all information \ n"); else if (2 = = num) {char buf[20];p rintf ("Please enter student number:"), while (Gets (BUF),!strlen (BUF)); Vector<student>::iterator it = Myvec.begin (); for (; It! = Myvec.end (); ++it) {if (!strcmp (buf, It->id)) {deleteonestudent (&myvec[it-myvec.begin ()]); return;}} printf ("The student was not found!") \ n ");} System ("pause"); Browsetomain ();} void SaveToFile () {//6if (Myvec.empty ()) {printf ("The data is empty and cannot be stored, please save it to the file after entering the information!") The system will return to the main menu! \ n "); system (" pause "); Browsetomain(); return;} FILE *FP = fopen ("StudentInformation.txt", "w"); Vector<student>::iterator it = Myvec.begin (); for (; it < MYVEC.E nd (); ++it) {fprintf (FP, "%s\n", It->id), fprintf (FP, "%s\n", It->name), fprintf (FP, "%s\n", It->age); fprintf (FP, "%s" \ n ", It->gender); fprintf (FP,"%s\n ", It->birth); fprintf (FP,"%s\n ", It->tel); fprintf (FP,"%s\n ", it-> address); fprintf (FP, "%s\n", It->email);} Fclose (FP);p rintf ("OK, archive finished! The system returns to the main interface. \ n "); system (" pause "); Browsetomain ();} void ReadFromFile () {//7 file *FP = fopen ("StudentInformation.txt", "RB"), if (fp = = NULL) {printf ("Not detected to archive file!") The system returns to the main interface. \ n "); system (" pause "); Browsetomain (); return;} Student It;myvec.clear (); while (FSCANF (FP, "%s", it.id) = = 1) {fscanf (FP, "%s", It.name), fscanf (FP, "%s", it.age); FSCANF ( FP, "%s", It.gender), fscanf (FP, "%s", It.birth), fscanf (FP, "%s", It.tel), fscanf (FP, "%s", it.address), fscanf (FP, "%s", It.email); Myvec.push_back (it);} Fclose (FP); if (Myvec.empty ()) {printf ("Read archive failed!") The system will return to the main interface! \ n ");} else{printf ("Read archive succeeded!") The system will returnBack to the main screen! \ n ");} System ("pause"); Browsetomain ();} void Exitinformation () {//0printf ("Thank you for your use! Goodbye \ "); System (" pause "); exit (exit_success);} void Displayonestudent (student *stu) {printf ("*****************************\n");p rintf ("study number:%s\n", stu->id); printf ("Name:%s\n", Stu->name);p rintf ("Age:%s\n", Stu->age);p rintf ("Gender:%s\n", Stu->gender);p rintf ("Birthday:%s\n" , Stu->birth);p rintf ("Tel:%s\n", Stu->tel);p rintf ("Address:%s\n", stu->address);p rintf ("email:%s\n", stu-> email);p rintf ("*****************************\n");} void Inquireonestudent (student *stu) {displayonestudent (stu);p rintf ("Please select action: \ n");p rintf ("1, change this student information \ n");p rintf ("2, Delete the student information \ n ");p rintf (" 0, return to main menu \ n "); int num; LABEL:SCANF ("%d", &num), if (num = = 1) modifyonestudent (STU), else if (num = = 2) deleteonestudent (STU); else if (num = = 0) m Odifytomain (stu); Else goto label;} void Modifyonestudent (Student *stu) {System ("CLS");p rintf ("Change current student information: \ n");p rintf ("1, change number \ n");p rintf ("2, change name \ n"); printf ("3, change age \ n");p rintf ("4, change sex \ n");p rintf ("5, change birthday \ n");p rintf ("6, change phone \ n ");p rintf (" 7, change address \ n ");p rintf (" 8, Change email\n ");p rintf (" 0, return to main menu \ n "); int num; scanf ("%d", &num);(*modifyone[num]) (STU);} void Modifyoneid (student *stu) {printf ("Please enter a new number:"), while (Gets (stu->id) &&!strlen (stu->id)); Filter Cache Enter printf ("Change succeeded!") The changed student information such as the following: \ n "); Inquireonestudent (Stu);} void Modifyonename (student *stu) {printf ("Please enter a new name:"), while (Gets (stu->name) &&!strlen (stu->name)); Filter Cache Enter printf ("Change succeeded!") The changed student information such as the following: \ n "); Inquireonestudent (Stu);} void Modifyoneage (student *stu) {printf ("Please enter a New Age:"), while (Gets (stu->age) &&!strlen (stu->age)); Filter Cache Enter printf ("Change succeeded!") The changed student information such as the following: \ n "); Inquireonestudent (Stu);} void Modifyonegender (student *stu) {printf ("Enter new gender:"); while (gets (Stu->gender) &&!strlen (stu->gender )); Filter Cache Enter printf ("Change succeeded!") The changed student information such as the following: \ n "); Inquireonestudent (Stu);} void Modifyonebirth (student *stu) {printf ("Please enter a new birthday:"), while (Gets (Stu->birth) &&!strlen (Stu->birth)); Filter Cache Enter printf ("Change succeeded!") The changed student information such as the following: \ n "); Inquireonestudent (Stu);}void Modifyonetel (student *stu) {printf ("Please enter a new phone:"), while (Gets (Stu->tel) &&!strlen (Stu->tel)); Filter Cache Enter printf ("Change succeeded!") The changed student information such as the following: \ n "); Inquireonestudent (Stu);} void modifyoneaddress (student *stu) {printf ("Please enter a new address:"); while (gets (stu->address) &&!strlen (stu-> address)); Filter Cache Enter printf ("Change succeeded!") The changed student information such as the following: \ n "); Inquireonestudent (Stu);} void Modifyoneemail (student *stu) {printf ("Please enter a new email:"); while (Stu->email) &&!strlen (stu->email )); Filter Cache Enter printf ("Change succeeded!") The changed student information such as the following: \ n "); Inquireonestudent (Stu);} void Modifytomain (Student *stu) {System ("CLS");p Rintmainmenu (); void Deleteonestudent (student *stu) {Vector<student>::iterator it;it = Myvec.begin () + (STU-&myvec[0]); Myvec.erase (IT);p rintf ("Delete succeeded! \ n ");} /*--cmp function Definition--*/bool Cmpbyid (student A, student B) {if (strcmp (a.id, b.ID) < 0) return true;} BOOL Cmpbyname (Student A, student B) {if (strcmp (A.name, B.name) < 0) return true;} BOOL Cmpbybirth (Student A, student B) {if (strcmp (A.birth, B.birth) < 0) return true;} /*--Browse mode--*/void browseplain () {//browse directly if (Myvec.empty ()) {printf ("Data is empty! The main menu is returned. \ n "); system (" pause "); Modifytomain (NULL);} Vector<student>::iterator stu = Myvec.begin (); for (; Stu! = Myvec.end (); ++stu) displayonestudent (&myvec[stu- Myvec.begin ()]);} void Browsebyid () {if (Myvec.empty ()) {printf ("Data is empty!") The main menu is returned. \ n "); system (" pause "); Modifytomain (NULL);} Sort (Myvec.begin (), Myvec.end (), Cmpbyid), Vector<student>::iterator stu = Myvec.begin (); for (; Stu! = Myvec.end () ; ++stu) Displayonestudent (&myvec[stu-myvec.begin ());} void Browsebyname () {if (Myvec.empty ()) {printf ("Data is empty!") The main menu is returned. \ n "); system (" pause "); Modifytomain (NULL);} Sort (Myvec.begin (), Myvec.end (), cmpbyname), Vector<student>::iterator stu = Myvec.begin (); for (; Stu! = Myvec.end (); ++stu) Displayonestudent (&myvec[stu-myvec.begin ());} void Browsebybirth () {if (Myvec.empty ()) {printf ("Data is empty!") The main menu is returned. \ n "); system (" pause "); Modifytomain (NULL);} Sort (Myvec.begin (), Myvec.end (), Cmpbybirth); vector<student>::iterator Stu = Myvec.begin (); for (; Stu! = Myvec.end (); ++stu) Displayonestudent (&myvec[stu-myvec.begin ()]);} void Browsetomain () {System ("CLS");p Rintmainmenu ();} /*--Query Method--*/void Inquirebyid () {printf ("Please enter the student number to query:"); char buf[20]; int ok = 0;while (Get (BUF),!strlen (BUF)); is still filtered empty string vector<student>::iterator it = Myvec.begin (); for (; It! = Myvec.end (); ++it) {if (strcmp (buf, it->id) = = 0) {displayonestudent (&myvec[it-myvec.begin ())); ok = 1;}} if (0 = = OK) printf ("Not Found! \ n ");} void Inquirebyname () {printf ("Enter the name of the student to be queried:"), char buf[20]; int ok = 0;while (Get (BUF),!strlen (BUF));//Still filter the empty string vector <student>::iterator it = Myvec.begin (); for (; It! = Myvec.end (); ++it) {if (strcmp (buf, it->name) = = 0) {Displayone Student (&myvec[it-myvec.begin ())); ok = 1;}} if (0 = = OK) printf ("Not Found! \ n ");} /*========== main function ==========*/int main () {printmainmenu (); return 0;}


The Student information management system in the design of the curriculum of the freshman C language

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.