C++實(shí)現(xiàn)簡(jiǎn)單學(xué)生信息管理系統(tǒng)
本文實(shí)例為大家分享了C++實(shí)現(xiàn)學(xué)生信息管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
編譯環(huán)境:
Microsoft Visual Studio 2019
3個(gè)頭文件:
Fileoperate.h
Interface.h
Student.h
4個(gè)源文件:
Fileoperate.cpp
Interface.cpp
Main.cpp
Student.cpp
Fileoperate.h
#ifndef STUDENT_H #define STUDENT_H #include<iostream> #include<string> #include<windows.h>?//調(diào)用API using namespace std; class Student { private: ?? ? ?? ?int?? ? ? No;? ?//序號(hào) ?? ?string Num;?? ??//學(xué)號(hào) ?? ?string Name;?//姓名 ?? ?string Birthday;?? //出生日期 ?? ?string Sex;??//性別 ?? ?string Political_appearance;?? //政治面貌 ?? ?string Phone_number;??//手機(jī)號(hào)碼 ?? ?string Address;???//家庭地址 public: ?? ? ?? ?void SetNo(int i)?? ?{?? ?No = i;}//設(shè)置學(xué)號(hào) ?? ?void Setinformation(string,string,string,string,string,string,string); ?// 修改函數(shù) ?? ?void SetNum();?? //修改學(xué)號(hào)?? ??? ??? ? ?? ?void SetName()?? ??? ?{cin>>Name;}??//修改姓名 ?? ?void SetBirthday();? ?//修改生日 ?? ?void SetSex()?? ??? ?{cin>>Sex;}?? ?//修改性別 ?? ?void SetPolitical_appearance()?? ?{cin>>Political_appearance;}??//修改政治面貌 ?? ?void SetPhone_number();??//修改電話號(hào)碼 ?? ?void SetAddress() ? {cin>>Address ;}??//修改家庭地址 ?? ?void Numshow(int,int); ?//學(xué)號(hào)高亮顯示 ?? ?void Addressshow(int,int);???//家庭地址高亮顯示 ?? ?void Show();?? ?//普通顯示 ?? ? ?? ?string GetNum()?? ??? ?{ return Num;}??//獲取學(xué)號(hào) ?? ?string GetName()?? ?{ return Name;}? ?//獲取姓名 ?? ?string GetBirthday(){ return Birthday;}??//獲取生日 ?? ?string GetSex()?? ??? ?{ return Sex;}?? ?//獲取性別 ?? ?string GetPolitical_appearance() { return Political_appearance;}//獲取政治面貌 ?? ?string GetPhone_number()?? ??? ? { return Phone_number;}? ?//獲取電話號(hào)碼 ?? ?string GetAddress()?? ??? ??? ??? ? { return Address;}???//獲取家庭地址 };
Interface.h
#include <string> #include <iostream> #include <Windows.h>?//Sleep函數(shù),system using namespace std; class Interface { ?? ? public: ?? ? ?? ?void Startface();?//啟動(dòng)界面 ?? ?void Loadface();?? //主界面 ?? ?void Subloadface();???//子界面 ?? ?void Subloadface2();?? //子界面2 ?? ?char Inputcharface();??//提示導(dǎo)入文件界面 ?? ?int ?Operateface();?? ?//操作輸入界面 ?? ?int?? ? Operateface2();?//操作輸入界面2 ?? ?int ?Addface();?//增加信息界面 ?? ?int ?Delface();? ?//刪除信息界面 ?? ?int ?Setface();?? ?//修改信息界面 ?? ?int ?Searchface();?? ?//搜索信息界面 ?? ?void Search_afterface();?? ?//搜索后信息顯示界面 ?? ? ?? ?void Mark();? ?//標(biāo)簽 ?? ? };
Student.h
#ifndef STUDENT_H #define STUDENT_H #include<iostream> #include<string> #include<windows.h>??//調(diào)用API using namespace std; class Student { private: ?? ? ?? ?int?? ? ? No;??//序號(hào) ?? ?string Num;??//學(xué)號(hào) ?? ?string Name;???//姓名 ?? ?string Birthday;? ?//出生日期 ?? ?string Sex;??//性別 ?? ?string Political_appearance;??//政治面貌 ?? ?string Phone_number;???//手機(jī)號(hào)碼 ?? ?string Address;??//家庭地址 public: ?? ? ?? ?void SetNo(int i)?? ?{?? ?No = i;}?//設(shè)置學(xué)號(hào) ?? ?void Setinformation(string,string,string,string,string,string,string); ?// 修改函數(shù) ?? ?void SetNum(); //修改學(xué)號(hào)?? ??? ??? ? ?? ?void SetName()?? ??? ?{cin>>Name;}??//修改姓名 ?? ?void SetBirthday();???//修改生日 ?? ?void SetSex()?? ??? ?{cin>>Sex;}? ?//修改性別 ?? ?void SetPolitical_appearance()?? ?{cin>>Political_appearance;}??//修改政治面貌 ?? ?void SetPhone_number();?? ?//修改電話號(hào)碼 ?? ?void SetAddress() ? {cin>>Address ;}?//修改家庭地址 ?? ?void Numshow(int,int);?? ?//學(xué)號(hào)高亮顯示 ?? ?void Addressshow(int,int);??//家庭地址高亮顯示 ?? ?void Show();???//普通顯示 ?? ? ?? ?string GetNum()?? ??? ?{ return Num;}???//獲取學(xué)號(hào) ?? ?string GetName()?? ?{ return Name;}?? ?//獲取姓名 ?? ?string GetBirthday(){ return Birthday;}?? //獲取生日 ?? ?string GetSex()?? ??? ?{ return Sex;}??//獲取性別 ?? ?string GetPolitical_appearance() { return Political_appearance;}//獲取政治面貌 ?? ?string GetPhone_number()?? ??? ? { return Phone_number;}//獲取電話號(hào)碼 ?? ?string GetAddress()?? ??? ??? ??? ? { return Address;}???//獲取家庭地址 }; #endif
```cpp
Fileoperate.cpp
#include "Fileoperate.h" int Fileoperate::Judge()?? ??? ??? ??? ?? { ?? ?if( file.fail() ) ?? ?{ ?? ??? ?return 0; ?? ?} ?? ?else ?? ?{ ?? ??? ?return 1; ?? ?} } void Fileoperate::open_in_file() { ?? ?file.open(filename, ios::in); ?? ?if( !Judge() ) ?? ?{ ?? ??? ?exit(1); ?? ?} } void Fileoperate::open_out_file() { ?? ?file.open(filename, ios::out); ?? ?if( !Judge() ) ?? ?{ ?? ??? ?exit(1); ?? ?} } int Fileoperate::Filecin() { ?? ?string Num1;?//學(xué)號(hào) ?? ?string Name1;?//姓名 ?? ?string Birthday1;?//出生日期 ?? ?string Sex1;?? ?//性別 ?? ?string Political_appearance1;?//政治面貌 ?? ?string Phone_number1;? ?//手機(jī)號(hào)碼 ?? ?string Address1;??//家庭地址 ?? ?if(file.eof())? ?//文件結(jié)束,返回0 ?? ?{ ?? ??? ?return 0; ?? ?} ?? ? ?? ?file>>Num1>>Name1>>Birthday1>>Sex1>>Political_appearance1>>Phone_number1>>Address1; ?? ?stu.Setinformation(Num1,Name1,Birthday1,Sex1,Political_appearance1,Phone_number1,Address1); ?? ?return 1; } int Fileoperate::Filecout(Student s) { ?? ?file << s.GetNum() << endl ?? ??? ? << s.GetName() << endl ?? ??? ? << s.GetBirthday() << endl ?? ??? ? << s.GetSex() << endl ?? ??? ? << s.GetPolitical_appearance() << endl ?? ??? ? << s.GetPhone_number() << endl ?? ??? ? << s.GetAddress() <<endl<<endl; ?? ? ?? ?return 1; } void Fileoperate::Closefile() { ?? ?file.close(); }
Interface.cpp
#include <iostream> #include "Interface.h" using namespace std; void Interface::Startface() { ?? ?cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl ?? ??? ?<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl; ?? ?cout<<" 啟動(dòng)中..."; ?? ?cout<<endl; ?? ?for(int i = 0;i<80;i++) ?? ?{ ?? ??? ?Sleep(8); ?? ??? ?cout<<">"; ?? ?} ?? ?system("cls"); } void Interface::Loadface() { ?? ?cout<<endl<<endl; ?? ?cout<<" ? ? ? ? ? ? ? ? ? ? ? ? ?學(xué) 生 信 息 管 理 系 統(tǒng) "<<endl<<endl; ?? ?cout<<" ? ?##################################################################"<<endl; ?? ?cout<<" ? ?# ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#"<<endl; ?? ?cout<<" ? ?# ? 1.增加學(xué)生記錄 ? ?# ? 2.刪除學(xué)生記錄 ? # ? ?3.修改學(xué)生記錄 ? #"<<endl; ?? ?cout<<" ? ?# ? 4.找查學(xué)生記錄 ? ?# ? 5.顯示學(xué)生記錄 ? # ? ?6.退出 ? ? ? ? ? #"<<endl; ?? ?cout<<" ? ?# ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#"<<endl; ?? ?cout<<" ? ?##################################################################"<<endl; ?? ?cout<<endl; ?? ? } void Interface::Subloadface2() { ?? ?cout<<endl; ?? ?cout<<" ? ?=======================+++操 - 作 - 提 - 示+++===================="<<endl ?? ??? ?<<" ? ?| ? ?1.增加學(xué)生記錄 ? | ? ?6.退出 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?|"<<endl ?? ??? ?<<" ? ?=================================================================="<<endl; ?? ?cout<<endl; } void Interface::Subloadface() { ?? ?cout<<endl<<endl; ?? ?cout<<" ? ?=======================+++操 - 作 - 提 - 示+++===================="<<endl ?? ??? ?<<" ? ?| ? ?1.增加學(xué)生記錄 ? | ? ?2.刪除學(xué)生記錄 ? ?| ? 3.修改學(xué)生記錄 ?|"<<endl ?? ??? ?<<" ? ?| ? ?4.找查學(xué)生記錄 ? | ? ?5.顯示學(xué)生記錄 ? ?| ? 6.退出 ? ? ? ? ?|"<<endl ?? ??? ?<<" ? ?=================================================================="<<endl; ?? ?cout<<endl; } char Interface::Inputcharface() { ?? ?char op_char; ?? ?cout<<"需要導(dǎo)入文件嗎?(Y/N):"; ?? ?cin>>op_char; ?? ?return op_char; } int Interface::Operateface() { ?? ?string op_num; ?? ?int flag,nflag = 0 ; ?? ? ?? ?do ?? ?{ ?? ??? ?flag = 0; ?? ??? ?if(nflag) ?? ??? ?{ ?? ??? ??? ?cout<<"超出范圍..Again:"; ?? ??? ??? ?cin>>op_num; ?? ??? ?} ?? ??? ?else ?? ??? ?{ ?? ??? ??? ?cout<<"輸入你的操作:"; ?? ??? ??? ?cin>>op_num; ?? ??? ?} ?? ??? ? ?? ??? ?if (op_num.length() != 1) { flag ++; nflag ++;} ?? ??? ?if(op_num[0] >'6'||op_num[0]<'0') { flag ++; nflag ++;} ?? ?}while(flag); ?? ? ?? ?return op_num[0]-'0'; } int Interface::Operateface2() { ?? ?string op_num; ?? ?int flag,nflag = 0 ; ?? ? ?? ?do ?? ?{ ?? ??? ?flag = 0; ?? ??? ?if(nflag) ?? ??? ?{ ?? ??? ??? ?cout<<"超出范圍..Again:"; ?? ??? ??? ?cin>>op_num; ?? ??? ?} ?? ??? ?else ?? ??? ?{ ?? ??? ??? ?cout<<"輸入你的操作:"; ?? ??? ??? ?cin>>op_num; ?? ??? ?} ?? ??? ? ?? ??? ?if (op_num.length() != 1) { flag ++; nflag ++;} ?? ??? ?if(op_num[0] != '6'&&op_num[0] != '1') { flag ++; nflag ++;} ?? ?}while(flag); ?? ? ?? ?return op_num[0]-'0'; } int Interface::Addface() { ?? ?int num; ?? ?cout<<"請(qǐng)輸入要添加學(xué)生的人數(shù)(若退出,輸入0):"; ?? ?cin>>num; ?? ?return num; } int Interface::Delface() { ?? ?int no; ?? ?cout<<"請(qǐng)輸入注銷學(xué)生的序號(hào)(若退出,輸入0):"; ?? ?cin>>no; ?? ?return no; } int Interface::Setface() { ?? ?int no; ?? ?cout<<"輸入要修改的學(xué)生序號(hào)(若退出,輸入0):"; ?? ?cin>>no; ?? ? ?? ?if(no) ?? ?{ ?? ??? ?cout<<"輸入你要改的學(xué)生的信息代號(hào)"<<endl ?? ??? ??? ?<<"(1.學(xué)號(hào),2.姓名,3.出生日期,4.性別,5.政治面貌,6手機(jī)號(hào)碼,7.家庭地址)"<<endl ?? ??? ??? ?<<"如果你要全部修改,則輸入0..."<<endl; ?? ??? ?cout<<"代碼:"; ?? ?} ?? ?return no; } int Interface::Searchface() { ?? ?int no; ?? ?cout<<"輸入搜索的類型"<<endl<<"1.學(xué)號(hào),2.姓名,3.性別,4.政治面貌,5.家庭地址"<<endl; ?? ?cout<<"類型(若退出,輸入0):"; ?? ?cin>>no; ?? ? ?? ?return no; } void Interface::Search_afterface()?//搜索結(jié)果 { ?? ?int i; ?? ?cout<<endl; ?? ?for(i = 0;i<36;i++) cout<<"~"; ?? ?cout<<"搜索結(jié)果"; ?? ?for(i = 0;i<36;i++) cout<<"~"; }
Student.cpp
#include <iostream> #include <cstdlib> #include <string> #include <algorithm>???//sort函數(shù) #include "Interface.h"?? ?//界面類 #include "Student.h"? ?//學(xué)生類 #include "Fileoperate.h"?? ?//文本類 using namespace std; const int student_num = 120 + 1;?? ?//人數(shù)上限 int No = 1;?? //序號(hào) int Total = 0;???//總?cè)藬?shù) Interface face;?? //界面 Fileoperate Infile;?//讀入文件類對(duì)象 Fileoperate Outfile;?? ?//讀出文件類對(duì)象 Student stu[student_num];?//學(xué)生類對(duì)象數(shù)組 int ?switchfun(int);??//功能函數(shù)選擇 void Allshow();??//顯示所有學(xué)生信息 void Searchshow(int [],int,int,int,int);?? ?//顯示搜索信息 void InFile();?//讀入文件函數(shù) void OutFile();??//讀出文件函數(shù) int main() { ?? ?int op_num;?? ?//操作序數(shù) ?? ?char op_char;??//選擇數(shù) ?? ?char op_char2;?? ??//是否保存 ?? ?face.Startface();?? //啟動(dòng)界面 ?? ?face.Loadface();?? ?//登陸界面 ?? ? ?? ?int flag ,nflag = 0;??//輸入格式判斷標(biāo)記 ?? ?do ?? ?{ ?? ??? ?flag = 0; ?? ??? ?if(nflag) cout<<"超出范圍...Again:"<<endl; ?? ??? ?op_char = face.Inputcharface(); ?? ??? ?if(op_char !='Y'&&op_char !='y'&&op_char !='N'&&op_char !='n')? ?? ??? ?{ ?? ??? ??? ?flag = 1; ?? ??? ??? ?nflag = 1; ?? ??? ?} ?? ?}while(flag); ?? ? ?? ?if (op_char == 'Y'||op_char =='y')?//選擇是,讀入文件 ?? ?{ ?? ??? ?InFile();?? ?//讀入文件 ?? ??? ?char Sub_op_char; ?? ??? ?nflag = 0; ?? ??? ?do ?? ??? ?{ ?? ??? ??? ?flag = 0; ?? ??? ??? ?cout<<"已成功導(dǎo)入, 要顯示資料嗎?(Y/N):"; ?? ??? ??? ?cin>>Sub_op_char; ?? ??? ??? ?if(Sub_op_char !='Y'&&Sub_op_char !='y'&&Sub_op_char !='N'&&Sub_op_char !='n')? ?? ??? ??? ?{ ?? ??? ??? ??? ?flag = 1; ?? ??? ??? ?} ?? ??? ?}while(flag); ?? ??? ? ?? ??? ?if (Sub_op_char == 'Y'||Sub_op_char =='y')?//是否瀏覽已讀入文件的信息 ?? ??? ?{ ?? ??? ??? ?Allshow();??//顯示所有信息 ?? ??? ??? ?face.Subloadface(); ?? ??? ?} ?? ??? ?else? ?? ??? ?{ ?? ??? ??? ?if (Sub_op_char == 'N' || Sub_op_char == 'n') ?? ??? ??? ??? ?cout<<endl;//不顯示信息 ?? ??? ?} ?? ?} ?? ?else? ?? ?{ ?? ??? ?if(op_char == 'N'||op_char =='n') ?? ??? ?face.Subloadface2(); ?? ?} ?? ? ?? ?while(1)?? ?//程序執(zhí)行過程 ?? ?{ ?? ??? ?if(Total != 0) op_num = face.Operateface();??//獲取操作數(shù) ?? ??? ?else op_num = face.Operateface2();??//獲取操作數(shù) ?? ??? ?if(op_num == 6) break;?? ?//輸入6,跳出 ?? ??? ?switchfun(op_num);??//功能選擇 ?? ??? ?if(Total != 0 ) face.Subloadface();?? ??? ??? ? ?? ??? ?else? ?? ??? ?{ ?? ??? ??? ?cout<<endl; ?? ??? ??? ?cout<<"學(xué)生數(shù)為零!"; ?? ??? ??? ?face.Subloadface2(); ?? ??? ?} ?? ??? ? ?? ?}?? ? ?? ?cout<<"要保存數(shù)據(jù)嗎?(Y/N):"; ?? ?cin>>op_char2; ?? ? ? ? if(op_char2 == 'Y'||op_char2 == 'y')? ?? ?{ ?? ??? ?cout<<endl<<"已保存!"<<endl; ?? ??? ?OutFile();??//讀出文件 ?? ?} ?? ? ?? ?system("pause"); ?? ? ?? ?return 0; } int switchfun(int op_num) { ?? ?int i; ?? ?int num;?? ?//添加界面操作數(shù) ?? ?string Num1;?? ?//學(xué)號(hào) ?? ?string Name1;?? ?//姓名 ?? ?string Birthday1;?//出生日期 ?? ?string Sex1;?? ????//性別 ?? ?string Political_appearance1;?//政治面貌 ?? ?string Phone_number1;??//手機(jī)號(hào)碼 ?? ?string Address1; ?? ?if (op_num == 1) ?? ?{ ?? ??? ?num = face.Addface();??//獲取添加界面操作數(shù) ?? ??? ?if(num == 0) { cout<<"已退出,任意鍵繼續(xù)..."; getchar(); getchar(); return 0;} ?? ??? ?for(i = 0;i<num;i++) ?? ??? ?{ ?? ??? ??? ?cout<<"輸入第"<<i+1<<"個(gè)學(xué)生信息:\n"; ?? ??? ??? ?cout<<endl; ?? ??? ??? ?cout<<"學(xué)號(hào):"; ?? ??? ??? ?cin>>Num1; ?? ??? ??? ?cout<<"姓名:"; ?? ??? ??? ?cin>>Name1; ?? ??? ??? ?cout<<"出生日期:"; ?? ??? ??? ?cin>>Birthday1; ?? ??? ??? ?cout<<"性別:"; ?? ??? ??? ?cin>>Sex1; ?? ??? ??? ?cout<<"政治面貌:"; ?? ??? ??? ?cin>>Political_appearance1; ?? ??? ??? ?cout<<"手機(jī)號(hào)碼:"; ?? ??? ??? ?cin>>Phone_number1; ?? ??? ??? ?cout<<"家庭地址:"; ?? ??? ??? ?cin>>Address1; ?? ??? ??? ?cout<<endl; ?? ??? ??? ?Total ++; ?? ??? ??? ?stu[Total-1].SetNo(Total); //設(shè)置序號(hào)?? ? ?? ??? ??? ?stu[Total-1].Setinformation(Num1,Name1,Birthday1,Sex1,Political_appearance1, ?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ? ?Phone_number1,Address1); ?? ??? ?} ?? ??? ?if(i == num) cout<<"添加完成!"<<endl; ?? ?} ?? ?else if(op_num == 2) ?? ?{ ?? ??? ?int no;??//刪除界面操作數(shù) ?? ??? ?no = face.Delface();??//獲取刪除界面操作數(shù) ?? ??? ?if(no == 0) { cout<<"已退出,任意鍵繼續(xù)..."; getchar(); getchar(); return 0;} ?? ??? ?for (i = no;i<Total;i++) { stu[i].SetNo(i);stu[i-1] = stu[i];} ?? ??? ?cout<<endl<<"刪除該學(xué)生信息成功!"<<endl; ?? ??? ?cout<<"任意鍵繼續(xù)..."; ?? ??? ?getchar();getchar(); ?? ??? ?Total --;?? ? ?? ?} ?? ?else if(op_num == 3) ?? ?{ ?? ??? ?int no; ?? ??? ?char info[128]; ?? ??? ?int a[14]; ?? ??? ?int k = 0; ?? ??? ? ?? ??? ?int flag = 0; ?? ??? ?no = face.Setface();??//獲取修改界面操作數(shù) ?? ??? ?if(no == 0) { cout<<"已退出,按任意鍵繼續(xù)..."; getchar(); getchar(); return 0;} ?? ??? ?getchar();?? ??? ??? ??? ??? ? ?? ??? ?gets_s(info); ?? ??? ?int l = strlen(info); ?? ??? ?i = 0; ?? ??? ?while(i<l)?//字符輸入標(biāo)準(zhǔn)化 ?? ??? ?{ ?? ??? ??? ?if(info[i]>='0'&&info[i]<='9') a[k++] = info[i]-'0'; ?? ??? ??? ?if(a[k-1]==0) { flag = 1; break;} ?? ??? ??? ?i++; ?? ??? ?} ?? ??? ? ?? ??? ?sort(a,a+k);? ?//排序 ?? ??? ?if(flag)?? //如果輸入零,修改全部信息 ?? ??? ?{ ?? ??? ??? ?cout<<"學(xué)號(hào):"; ?? ??? ??? ?cin>>Num1; ?? ??? ??? ?cout<<"姓名:"; ?? ??? ??? ?cin>>Name1; ?? ??? ??? ?cout<<"出生日期:"; ?? ??? ??? ?cin>>Birthday1; ?? ??? ??? ?cout<<"性別:"; ?? ??? ??? ?cin>>Sex1; ?? ??? ??? ?cout<<"政治面貌:"; ?? ??? ??? ?cin>>Political_appearance1; ?? ??? ??? ?cout<<"手機(jī)號(hào)碼:"; ?? ??? ??? ?cin>>Phone_number1; ?? ??? ??? ?cout<<"家庭地址:"; ?? ??? ??? ?cin>>Address1; ?? ??? ??? ?cout<<endl; ?? ??? ??? ?stu[no-1].Setinformation(Num1,Name1,Birthday1,Sex1,Political_appearance1,Phone_number1,Address1); ?? ??? ?} ?? ??? ?else? ?? ??? ?{ ?? ??? ??? ?for(i = 0;i<k;i++) ?? ??? ??? ?{ ?? ??? ??? ??? ?switch(a[i])?//修改部分信息 ?? ??? ??? ??? ?{ ?? ??? ??? ??? ?case 1:? ?? ??? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ??? ?cout<<"輸入學(xué)號(hào):"; ?? ??? ??? ??? ??? ??? ?stu[no-1].SetNum(); ?? ??? ??? ??? ??? ??? ?break; ?? ??? ??? ??? ??? ?} ?? ??? ??? ??? ?case 2: ?? ??? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ??? ?cout<<"輸入姓名:"; ?? ??? ??? ??? ??? ??? ?stu[no-1].SetName(); ?? ??? ??? ??? ??? ??? ?break; ?? ??? ??? ??? ??? ?} ?? ??? ??? ??? ?case 3: ?? ??? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ??? ?cout<<"輸入出生日期:"; ?? ??? ??? ??? ??? ??? ?stu[no-1].SetBirthday(); ?? ??? ??? ??? ??? ??? ?break; ?? ??? ??? ??? ??? ?} ?? ??? ??? ??? ?case 4: ?? ??? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ??? ?cout<<"輸入性別:"; ?? ??? ??? ??? ??? ??? ?stu[no-1].SetSex(); ?? ??? ??? ??? ??? ??? ?break; ?? ??? ??? ??? ??? ?} ?? ??? ??? ??? ?case 5: ?? ??? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ??? ?cout<<"輸入政治面貌:"; ?? ??? ??? ??? ??? ??? ?stu[no-1].SetPolitical_appearance(); ?? ??? ??? ??? ??? ??? ?break; ?? ??? ??? ??? ??? ?} ?? ??? ??? ??? ?case 6: ?? ??? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ??? ?cout<<"輸入手機(jī)號(hào)碼:"; ?? ??? ??? ??? ??? ??? ?stu[no-1].SetPhone_number(); ?? ??? ??? ??? ??? ??? ?break; ?? ??? ??? ??? ??? ?} ?? ??? ??? ??? ?case 7: ?? ??? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ??? ?cout<<"輸入家庭地址:"; ?? ??? ??? ??? ??? ??? ?stu[no-1].SetAddress(); ?? ??? ??? ??? ??? ??? ?break; ?? ??? ??? ??? ??? ?} ?? ??? ??? ??? ?} ?? ??? ??? ?} ?? ??? ?} ?? ??? ? ?? ??? ?cout<<endl<<endl<<"已完成, 修改后:"<<endl;??//輸出修改后信息 ?? ??? ?for(i= 0;i<80;i++) cout<<"-";? ?? ??? ?stu[no-1].Show(); ?? ??? ?for(i= 0;i<80;i++) cout<<"-"; cout<<endl; ?? ??? ?cout<<"按任意鍵繼續(xù)..."; ?? ??? ?getchar();getchar(); ?? ??? ? ?? ?} ?? ?else if(op_num == 4) ?? ?{ ?? ??? ?int no; ?? ??? ?int Begin,End;?//開始,結(jié)束位置 ?? ??? ?int num = 0;? ?//符合搜索條件的人數(shù) ?? ??? ?string Ss;??//臨時(shí)對(duì)象 ?? ??? ?no = face.Searchface();??//獲取搜索界面操作數(shù) ?? ??? ?if(no == 0) { cout<<"已退出,按任意鍵繼續(xù)..."; getchar(); getchar(); return 0;} ?? ??? ?int flag = 0; ?? ??? ? ?? ??? ?switch(no) ?? ??? ?{ ?? ??? ?case 1:?//按學(xué)號(hào)搜索 ?? ??? ??? ?{ ?? ??? ??? ??? ?cout<<"輸入關(guān)鍵字:"; ?? ??? ??? ??? ?cin>>Num1; ?? ??? ??? ??? ? ?? ??? ??? ??? ?for( i = 0;i<Total;i++) ?? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ?Ss = stu[i].GetNum(); ?? ??? ??? ??? ??? ?Begin = Ss.find(Num1,0); ?? ??? ??? ??? ??? ?if(Begin != string::npos)? ?? ??? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ??? ?End = Num1.length() + Begin; ?? ??? ??? ??? ??? ??? ?flag ++; ?? ??? ??? ??? ??? ??? ?if(flag == 1) face.Search_afterface(); ?? ??? ??? ??? ??? ??? ?stu[i].Numshow(Begin,End); ?? ??? ??? ??? ??? ??? ?num++; ?? ??? ??? ??? ??? ?} ?? ??? ??? ??? ?} ?? ??? ??? ??? ?if(!flag) cout<<"沒此相關(guān)信息!"<<endl; ?? ??? ??? ??? ?else? ?? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ?cout<<endl<<"共有"<<num<<"條相關(guān)信息!"<<endl; ?? ??? ??? ??? ??? ?num = 0; ?? ??? ??? ??? ??? ?for(i = 0;i<80;i++) cout<<"~";? ?? ??? ??? ??? ?} ?? ??? ??? ??? ?break; ?? ??? ??? ?} ?? ??? ?case 2:??//按名字搜索 ?? ??? ??? ?{ ?? ??? ??? ??? ?cout<<"輸入關(guān)鍵字:"; ?? ??? ??? ??? ?cin>>Name1; ?? ??? ??? ??? ? ?? ??? ??? ??? ?for( i = 0;i<Total;i++) ?? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ?Ss = stu[i].GetName(); ?? ??? ??? ??? ??? ?Begin = Ss.find(Name1,0); ?? ??? ??? ??? ??? ?if(Begin != string::npos)? ?? ??? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ??? ?flag ++; ?? ??? ??? ??? ??? ??? ?if(flag == 1) face.Search_afterface(); ?? ??? ??? ??? ??? ??? ?stu[i].Show(); ?? ??? ??? ??? ??? ??? ?num++; ?? ??? ??? ??? ??? ?} ?? ??? ??? ??? ?} ?? ??? ??? ??? ?if(!flag) cout<<"沒此相關(guān)信息!"<<endl; ?? ??? ??? ??? ?else? ?? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ?cout<<endl<<"共有"<<num<<"條相關(guān)信息!"<<endl; ?? ??? ??? ??? ??? ?num = 0; ?? ??? ??? ??? ??? ?for(i = 0;i<80;i++) cout<<"~";? ?? ??? ??? ??? ?} ?? ??? ??? ??? ?break; ?? ??? ??? ?} ?? ??? ?case 3:?//按性別搜索 ?? ??? ??? ?{ ?? ??? ??? ??? ?cout<<"輸入關(guān)鍵字:"; ?? ??? ??? ??? ?cin>>Sex1; ?? ??? ??? ??? ? ?? ??? ??? ??? ?for( i = 0;i<Total;i++) ?? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ?Ss = stu[i].GetSex(); ?? ??? ??? ??? ??? ?Begin = Ss.find(Sex1,0); ?? ??? ??? ??? ??? ?if(Begin != string::npos)? ?? ??? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ??? ?flag ++; ?? ??? ??? ??? ??? ??? ?if(flag == 1) face.Search_afterface(); ?? ??? ??? ??? ??? ??? ?stu[i].Show(); ?? ??? ??? ??? ??? ??? ?num++; ?? ??? ??? ??? ??? ?} ?? ??? ??? ??? ?} ?? ??? ??? ??? ?if(!flag) cout<<"沒此相關(guān)信息!"<<endl; ?? ??? ??? ??? ?else? ?? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ?cout<<endl<<"共有"<<num<<"條相關(guān)信息!"<<endl; ?? ??? ??? ??? ??? ?num = 0; ?? ??? ??? ??? ??? ?for(i = 0;i<80;i++) cout<<"~";? ?? ??? ??? ??? ?} ?? ??? ??? ??? ?break; ?? ??? ??? ?} ?? ??? ?case 4:??//按政治面貌搜索 ?? ??? ??? ?{ ?? ??? ??? ??? ?cout<<"輸入關(guān)鍵字:"; ?? ??? ??? ??? ?cin>>Political_appearance1; ?? ??? ??? ??? ? ?? ??? ??? ??? ?for( i = 0;i<Total;i++) ?? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ?Ss = stu[i].GetPolitical_appearance(); ?? ??? ??? ??? ??? ?Begin = Ss.find(Political_appearance1,0); ?? ??? ??? ??? ??? ?if(Begin != string::npos)? ?? ??? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ??? ?flag ++; ?? ??? ??? ??? ??? ??? ?if(flag == 1) face.Search_afterface(); ?? ??? ??? ??? ??? ??? ?stu[i].Show(); ?? ??? ??? ??? ??? ??? ?num++; ?? ??? ??? ??? ??? ?} ?? ??? ??? ??? ?} ?? ??? ??? ??? ?if(!flag) cout<<"沒此相關(guān)信息!"<<endl; ?? ??? ??? ??? ?else? ?? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ?cout<<endl<<"共有"<<num<<"條相關(guān)信息!"<<endl; ?? ??? ??? ??? ??? ?num = 0; ?? ??? ??? ??? ??? ?for(i = 0;i<80;i++) cout<<"~";? ?? ??? ??? ??? ?} ?? ??? ??? ??? ?break; ?? ??? ??? ?} ?? ??? ?case 5:? ?//按家庭地址搜索 ?? ??? ??? ?{ ?? ??? ??? ??? ?cout<<"輸入關(guān)鍵字:"; ?? ??? ??? ??? ?cin>>Address1; ?? ??? ??? ??? ? ?? ??? ??? ??? ?for( i = 0;i<Total;i++) ?? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ?Ss = stu[i].GetAddress(); ?? ??? ??? ??? ??? ?Begin = Ss.find(Address1,0); ?? ??? ??? ??? ??? ? ?? ??? ??? ??? ??? ?if(Begin != string::npos)? ?? ??? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ??? ?End = Address1.length() + Begin; ?? ??? ??? ??? ??? ??? ?flag ++; ?? ??? ??? ??? ??? ??? ?if(flag == 1) face.Search_afterface(); ?? ??? ??? ??? ??? ??? ?stu[i].Addressshow(Begin,End); ?? ??? ??? ??? ??? ??? ?num++; ?? ??? ??? ??? ??? ?} ?? ??? ??? ??? ?} ?? ??? ??? ??? ?if(!flag) cout<<"沒此相關(guān)信息!"<<endl; ?? ??? ??? ??? ?else? ?? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ?cout<<endl<<"共有"<<num<<"條相關(guān)信息!"<<endl; ?? ??? ??? ??? ??? ?num = 0; ?? ??? ??? ??? ??? ?for(i = 0;i<80;i++) cout<<"~";? ?? ??? ??? ??? ?} ?? ??? ??? ??? ?break; ?? ??? ??? ?} ?? ??? ?} ?? ??? ?cout<<"任意鍵繼續(xù)..."; getchar();getchar(); ?? ?} ?? ?else if(op_num == 5)?? ?//顯示所有信息 ?? ?{ ?? ??? ?Allshow(); ?? ?} ?? ?return 1; }?? ? void Allshow() { ?? ?int i; ?? ?cout<<endl; ?? ?for(i = 0;i<36;i++) cout<<"~"; ?? ?cout<<"顯示結(jié)果"; ?? ?for(i = 0;i<36;i++) cout<<"~"; ?? ?for(i = 0;i<Total;i++)? ?? ??? ?stu[i].Show(); ?? ?for(i = 0;i<80;i++) cout<<"~"; ?? ?cout<<"繼續(xù)按任意鍵...."; ?? ?getchar();getchar(); } void InFile() { ?? ?int i; ?? ?Infile.open_in_file();? ?? ?int total = 0;?? ??? ??? ? ?? ?while(Infile.Filecin())?? ?//把文件中的所有數(shù)據(jù)導(dǎo)入學(xué)生對(duì)象中 ?? ?{ ?? ??? ? ?? ??? ?stu[total++] = Infile.Getstudent(); ?? ?} ?? ?Total = total -1 ; ?? ?for (i = 0;i<Total;i++) stu[i].SetNo(i+1); ?? ?Infile.Closefile();? } void OutFile() { ?? ?int i; ?? ?Outfile.open_out_file(); ? ? ? ? ? ? ? ? ? ? ? ?? ?? ? ?? ?for(i = 0; i < Total; i++)?//把學(xué)生對(duì)象中的數(shù)據(jù)讀入到文件中 ?? ?{ ?? ??? ?Outfile.Filecout(stu[i]); ?? ?} ?? ?Outfile.Closefile();?? ??? ??? ??? ??? ??? ??? ? }
main.cpp
#include "Student.h" #include <iostream> using namespace std; void Student::Setinformation(string num,string name,string birthday,string sex, ?? ??? ??? ??? ??? ??? ??? ? string political_app,string phone_num,string address) { ?? ?Num = num; ?? ?Name = name; ?? ?Birthday = birthday; ?? ?Sex = sex; ?? ?Political_appearance = political_app; ?? ?Phone_number = phone_num; ?? ?Address = address; } void Student::SetNum() { ?? ?unsigned int i = 0; ?? ?int flag,nflag = 0; ?? ?string num; ?? ? ?? ?do ?? ?{ ?? ??? ?flag = 0; ?? ??? ?if (nflag) cout<<"格式錯(cuò)誤..Again:"; ?? ??? ?cin>>num; ?? ??? ?for(int i = 0;i<num.length();i++) ?? ??? ?{ ?? ??? ??? ?if(num[i] > '9'||num[i] < '0')? ?? ??? ??? ?{ ?? ??? ??? ??? ?flag = 1; ?? ??? ??? ??? ?nflag++; ?? ??? ??? ??? ?break; ?? ??? ??? ?} ?? ??? ?} ?? ??? ? ?? ?}while(flag); ?? ?if(!flag) Num = num; } void Student::SetBirthday() { ?? ?unsigned int i = 0; ? ? int flag,nflag = 0; ?? ?string birthday; ?? ? ?? ?do ?? ?{ ?? ??? ?flag = 0; ?? ??? ?if (nflag) cout<<"格式錯(cuò)誤..Again:"; ?? ??? ?cin>>birthday; ?? ??? ?for(int i = 0;i< birthday.length();i++) ?? ??? ?{ ?? ??? ??? ?if((birthday[i] > '9'||birthday[i] < '0')&&birthday[i]!='/')? ?? ??? ??? ?{ ?? ??? ??? ??? ?flag = 1; ?? ??? ??? ??? ?nflag++; ?? ??? ??? ??? ?break; ?? ??? ??? ?} ?? ??? ?} ?? ??? ? ?? ?}while(flag); ?? ? ?? ?if(!flag) Birthday = birthday; } void Student::SetPhone_number() { ?? ?int i = 0; ?? ?int flag,nflag = 0; ?? ?string phone_number; ?? ? ?? ?do ?? ?{ ?? ??? ?flag = 0; ?? ??? ?if (nflag) cout<<"格式錯(cuò)誤..Again:"; ?? ??? ?cin>>phone_number; ?? ??? ?for(int i = 0;i<phone_number.length();i++) ?? ??? ?{ ?? ??? ??? ?if(phone_number[i] > '9'||phone_number[i] < '0')? ?? ??? ??? ?{ ?? ??? ??? ??? ?flag = 1; ?? ??? ??? ??? ?nflag++; ?? ??? ??? ??? ?break; ?? ??? ??? ?} ?? ??? ?} ?? ??? ? ?? ?}while(flag); ?? ? ?? ?if(!flag) Phone_number = phone_number; } void Student::Numshow(int Begin,int End) { ?? ?int i = 0; ?? ?cout<<"序號(hào):"<<No<<endl; ?? ?cout<<"學(xué)號(hào)"; ?? ?HANDLE ohandle = GetStdHandle(STD_OUTPUT_HANDLE); ?? ? ?? ?for(int i = 0;i<Begin;i++) cout<<Num[i]; ?? ?SetConsoleTextAttribute(ohandle,BACKGROUND_INTENSITY);? ?//背景高亮 ?? ? ?? ?for(i = Begin;i<End;i++) cout<<Num[i]; ?? ?SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),?//恢復(fù)默認(rèn)系統(tǒng)顏色 ?? ??? ?FOREGROUND_RED| FOREGROUND_GREEN| FOREGROUND_BLUE); ? ?? ?for(i = End;i<Num.length();i++) cout<<Num[i]; ?? ?cout<<" ? " ?? ??? ?<<"姓名:"<<Name<<" ? ?"? ?? ??? ?<<"出生日期:"<<Birthday<<" ?" ?? ??? ?<<"性別:"<<Sex<<" ?" ?? ??? ?<<"政治面貌:"<<Political_appearance<<endl ?? ??? ?<<"手機(jī)號(hào)碼:"<<Phone_number<<" ?"; ?? ?cout<<endl<<endl; } void Student::Addressshow(int Begin,int End) { ?? ?int i = 0; ?? ?cout<<"序號(hào):"<<No<<endl ?? ??? ?<<"學(xué)號(hào)"<<Num<<" ? " ?? ??? ?<<"姓名:"<<Name<<" ? ?"? ?? ??? ?<<"出生日期:"<<Birthday<<" ?" ?? ??? ?<<"性別:"<<Sex<<" ?" ?? ??? ?<<"政治面貌:"<<Political_appearance<<endl ?? ??? ?<<"手機(jī)號(hào)碼:"<<Phone_number<<" ?"; ?? ?HANDLE ohandle = GetStdHandle(STD_OUTPUT_HANDLE); ?? ? ?? ?for(int i = 0;i<Begin;i++) cout<<Address[i]; ?? ?SetConsoleTextAttribute(ohandle,BACKGROUND_INTENSITY);??//背景高亮 ?? ? ?? ?for(i = Begin;i<End;i++) cout<<Address[i]; ?? ?SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),??//恢復(fù)默認(rèn)系統(tǒng)顏色 ?? ??? ?FOREGROUND_RED| FOREGROUND_GREEN| FOREGROUND_BLUE); ? ?? ?for(i = End;i<Address.length();i++) cout<<Address[i]; ?? ?cout<<endl<<endl; } void Student::Show()?//普通方式顯示信息 { ?? ?cout<<"序號(hào):"<<No<<endl ?? ??? ?<<"學(xué)號(hào)"<<Num<<" ? " ?? ??? ?<<"姓名:"<<Name<<" ? ?"? ?? ??? ?<<"出生日期:"<<Birthday<<" ?" ?? ??? ?<<"性別:"<<Sex<<" ?" ?? ??? ?<<"政治面貌:"<<Political_appearance<<endl ?? ??? ?<<"手機(jī)號(hào)碼:"<<Phone_number<<" ?" ?? ??? ?<<"家庭地址:"<<Address<<endl<<endl; }
TXT文件格式
學(xué)號(hào) 姓名 生日 性別 政治面貌 手機(jī)號(hào) 家庭住址
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- C++使用文件實(shí)現(xiàn)學(xué)生信息管理系統(tǒng)
- C++實(shí)現(xiàn)學(xué)生考勤信息管理系統(tǒng)
- C++實(shí)現(xiàn)學(xué)生信息管理系統(tǒng)
- linux下C/C++學(xué)生信息管理系統(tǒng)
- C++學(xué)生信息管理系統(tǒng)
- C++實(shí)現(xiàn)簡(jiǎn)單學(xué)生管理系統(tǒng)
- C++實(shí)現(xiàn)學(xué)生管理系統(tǒng)示例解析
- C++實(shí)現(xiàn)學(xué)生管理系統(tǒng)
- C++基礎(chǔ)學(xué)生管理系統(tǒng)
- C++實(shí)現(xiàn)簡(jiǎn)單的學(xué)生管理系統(tǒng)
相關(guān)文章
詳解_beginthreadex()創(chuàng)建線程
這篇文章主要介紹了詳解_beginthreadex()創(chuàng)建線程,使用_beginthreadex(),需要的頭文件支持#include <process.h> 下面我們就來看看具體的實(shí)現(xiàn)吧2022-01-01C語言實(shí)現(xiàn)商品管理系統(tǒng)開發(fā)
這篇文章主要為大家詳細(xì)介紹了C語言實(shí)現(xiàn)商品管理系統(tǒng)開發(fā),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-08-08pybind11: C++ 工程提供 Python 接口的實(shí)例代碼
這篇文章主要介紹了pybind11: C++ 工程如何提供 Python 接口,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-09-09VisualStudio2022提交git代碼的方法實(shí)現(xiàn)
本文主要介紹了VisualStudio2022提交git代碼的方法實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-07-07