This is the first academic leave of the project, the main part of the train on the home completed, after a few days to continue processing, today finally completed, this is the student management system of the beta version, the follow-up will continue to improve.
Student information includes: School number, name, age, gender, date of birth, address, telephone, e-mail, etc. Try to design a student information management system, so that it can provide the following functions:
(1) The system works in menu mode
(2) Student Information entry function ( student information file saving )---input
(3) Student Information browsing function---output
(4) Query, sorting function
Inquiry by study number
Search by name
(5) Deletion and modification of student information (optional)
/* *copyright (c) 2015, Yantai University School of computer *all gight reserved. * File name: Temp.cpp * Shao * Completed: January 19, 2015 * version number: v1.0*/#include <fstream> #include <iostream> #include <cstdlib > #include <string>using namespace std;void showmeun (void); int Name_search (string, int); int Num_search (string , int), void showinfo (int num), void showchange (void), int open (void), void save (int num), struct student{string number; String name; string old; string sex; string birthday; string add; string phone; string Mail;}; File structure Student Stu[8000];int main () {int choice,i; String Numkey,namekey; int num=0,add,addsum,cut; while (1) {num=open (); Showmeun ();//Open Start Menu cin>>choice; if (choice==0) {cout<< "Thank you for using the @mayuko Student management system!" <<endl; Break } else if (choice==1) {cout<< "Please enter student's study number:"; cin>>numkey; I=num_search (Numkey,num); if (i==-1) {cout<< "No information for this student! "<<endl; Continue } else Showinfo (i); cout<<endl; } else if (choice==2) {cout<< "Please enter the student's name:"; cin>>namekey; I=name_search (Namekey,num); if (i==-1) {cout<< "does not have this student information! "<<endl; Continue } else Showinfo (i); cout<<endl; } else if (choice==3) {cout<< "The student's information is as follows:" <<endl; for (i=0; i<num; i++) {showinfo (i); cout<<endl; }} else if (choice==4) {cout<< "Please enter the number of writes;"; cin>>addsum; cout<< "Please enter student's number, name, age, gender (M or F), date of birth, address, telephone, e-mail" <<endl; cout<< "column such as: 201401 Xiao Van 19961218 Global village 17862817891 [email protected] "<<endl; Open File Ofstream outfile ("Students.txt", Ios::app); if (!outfile) {cout<< "Open file failed! "; Exit (1); } num+=addsum; for (Add=num; add< (addsum+num); add++) {cin>>stu[add].number>>stu[add].name>& Gt;stu[add].old>>stu[add].sex>>stu[add].birthday>>stu[add].add>>stu[add].phone>> Stu[add].mail; outfile<<stu[add].number<< "<<stu[add].name<<" "<<stu[add].old<<" "<< stu[add].sex<< "<<stu[add].birthday<<" "<<stu[add].add<<" "<<stu[add].phone << "" <<stu[add].mail<<endl; } outfile.close (); cout<< "Write End! A total of "<<num<<" records are written for "<<addsum<<" records. "<<endl; End of File Write} else if (choice==5) { cout<< "Please enter the student number to be modified:"; cin>>numkey; I=num_search (Numkey,num); cout<< "You are modifying" "; Showinfo (i); cout<< "" Information <<endl; Showchange (); cin>>cut; cout<< "Please enter the modified content:"; while (1) {if (cut==1) cin>>stu[i].number; else if (cut==2) cin>>stu[i].name; else if (cut==3) cin>>stu[i].old; else if (cut==4) cin>>stu[i].sex; else if (cut==5) cin>>stu[i].birthday; else if (cut==6) cin>>stu[i].add; else if (cut==7) cin>>stu[i].phone; else if (cut==8) cin>>stu[i].mail; else {cout<< "input error, coming back" ≪<endl; Break } save (NUM); cout<< "modified successfully! "<<endl; Break }}} return 0;} int open (void) {int num=0; Ifstream infile ("Students.txt", ios::in); if (!infile) {cout<< "Open file failed! "; Exit (1); } while (Infile>>stu[num].number) {infile>>stu[num].name; infile>>stu[num].old; infile>>stu[num].sex; infile>>stu[num].birthday; infile>>stu[num].add; infile>>stu[num].phone; infile>>stu[num].mail; num++; } infile.close (); File read end return num;} void save (int num) {int add; Ofstream outfile ("Students.txt", ios::out); if (!outfile) {cout<< "Open file failed! "; Exit (1); } for (add=0; add<num; add++) {outfile<<stu[add].number<< "" <<stu[add].name<< "" & lt;<stu[add].old<<"<<stu[add].sex<<" "<<stu[add].birthday<<" "<<stu[add].add<<" <<stu[ add].phone<< "" <<stu[add].mail<<endl; } outfile.close ();} void Showmeun (void) {cout<< "-----------------" <<endl; cout<< "Student Information Management system" <<endl; cout<< "-----------------" <<endl; cout<< "1, by study number search" <<endl; cout<< "2, Find by name" <<endl; cout<< "3, Student information browse" <<endl; cout<< "4, Student information entry" <<endl; cout<< "5, modify student information" <<endl; cout<< "Please select function (type 0 exit):";} void Showchange (void) {cout<< "--------------" <<endl; cout<< "1-Study No." <<endl; cout<< "2-Name" <<endl; cout<< "3-age" <<endl; cout<< "4-gender" <<endl; cout<< "5-date of birth" <<endl; cout<< "6-Address" <<endl; cout<< "7-Phone" <<endl; cout<< "8-e-mail" <<endl; cout<< "--------------" <<endl; cout<< "Please enter the options you want to modify:";} void showinfo (int num) {cout<<stu[num].number<< "" <<stu[num].name<< "" <<stu[num].old << "<<stu[num].sex<<" <<stu[num].birthday<< "<<stu[num].add<<" "< <stu[num].phone<< "" <<stu[num].mail; int Name_search (string key,int n) {int i; for (i=0; i<n; i++) {if (key==stu[i].name) return i; } return i;} int Num_search (string key,int n) {int i=-1; for (i=0; i<n; i++) {if (key==stu[i].number) return i; } return i;}
Operation Result:
Additionally, the file "Students.txt" file for the Temp folder:
@ Mayuko
Academic leave-Student information Management System v1.0