本文实例为大家分享了C++实现学生信息管理系统的具体代码,供大家参考,具体内容如下
编译环境:
Microsoft Visual Studio 2019
3个头文件:
Fileoperate.h
Interface.h
Student.h
4个源文件:
Fileoperate.cpp
Interface.cpp
Main.cpp
Student.cpp
Fileoperate.h
#ifndef STUDENT_H #define STUDENT_H #include#include #include //调用API using namespace std; class Student { private: int No; //序号 string Num; //学号 string Name; //姓名 string Birthday; //出生日期 string Sex; //性别 string Political_appearance; //政治面貌 string Phone_number; //手机号码 string Address; //家庭地址 public: void SetNo(int i) { No = i;}//设置学号 void Setinformation(string,string,string,string,string,string,string); // 修改函数 void SetNum(); //修改学号 void SetName() {cin>>Name;} //修改姓名 void SetBirthday(); //修改生日 void SetSex() {cin>>Sex;} //修改性别 void SetPolitical_appearance() {cin>>Political_appearance;} //修改政治面貌 void SetPhone_number(); //修改电话号码 void SetAddress() {cin>>Address ;} //修改家庭地址 void Numshow(int,int); //学号高亮显示 void Addressshow(int,int); //家庭地址高亮显示 void Show(); //普通显示 string GetNum() { return Num;} //获取学号 string GetName() { return Name;} //获取姓名 string GetBirthday(){ return Birthday;} //获取生日 string GetSex() { return Sex;} //获取性别 string GetPolitical_appearance() { return Political_appearance;}//获取政治面貌 string GetPhone_number() { return Phone_number;} //获取电话号码 string GetAddress() { return Address;} //获取家庭地址 };
Interface.h
#include#include #include //Sleep函数,system using namespace std; class Interface { public: void Startface(); //启动界面 void Loadface(); //主界面 void Subloadface(); //子界面 void Subloadface2(); //子界面2 char Inputcharface(); //提示导入文件界面 int Operateface(); //操作输入界面 int Operateface2(); //操作输入界面2 int Addface(); //增加信息界面 int Delface(); //删除信息界面 int Setface(); //修改信息界面 int Searchface(); //搜索信息界面 void Search_afterface(); //搜索后信息显示界面 void Mark(); //标签 };
Student.h
#ifndef STUDENT_H #define STUDENT_H #include#include #include //调用API using namespace std; class Student { private: int No; //序号 string Num; //学号 string Name; //姓名 string Birthday; //出生日期 string Sex; //性别 string Political_appearance; //政治面貌 string Phone_number; //手机号码 string Address; //家庭地址 public: void SetNo(int i) { No = i;} //设置学号 void Setinformation(string,string,string,string,string,string,string); // 修改函数 void SetNum(); //修改学号 void SetName() {cin>>Name;} //修改姓名 void SetBirthday(); //修改生日 void SetSex() {cin>>Sex;} //修改性别 void SetPolitical_appearance() {cin>>Political_appearance;} //修改政治面貌 void SetPhone_number(); //修改电话号码 void SetAddress() {cin>>Address ;} //修改家庭地址 void Numshow(int,int); //学号高亮显示 void Addressshow(int,int); //家庭地址高亮显示 void Show(); //普通显示 string GetNum() { return Num;} //获取学号 string GetName() { return Name;} //获取姓名 string GetBirthday(){ return Birthday;} //获取生日 string GetSex() { return Sex;} //获取性别 string GetPolitical_appearance() { return Political_appearance;}//获取政治面貌 string GetPhone_number() { return Phone_number;}//获取电话号码 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; //学号 string Name1; //姓名 string Birthday1; //出生日期 string Sex1; //性别 string Political_appearance1; //政治面貌 string Phone_number1; //手机号码 string Address1; //家庭地址 if(file.eof()) //文件结束,返回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() <
Interface.cpp
#include#include "Interface.h" using namespace std; void Interface::Startface() { cout< "; } system("cls"); } void Interface::Loadface() { cout< >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<<"请输入要添加学生的人数(若退出,输入0):"; cin>>num; return num; } int Interface::Delface() { int no; cout<<"请输入注销学生的序号(若退出,输入0):"; cin>>no; return no; } int Interface::Setface() { int no; cout<<"输入要修改的学生序号(若退出,输入0):"; cin>>no; if(no) { cout<<"输入你要改的学生的信息代号"< >no; return no; } void Interface::Search_afterface() //搜索结果 { int i; cout<
Student.cpp
#include#include #include #include //sort函数 #include "Interface.h" //界面类 #include "Student.h" //学生类 #include "Fileoperate.h" //文本类 using namespace std; const int student_num = 120 + 1; //人数上限 int No = 1; //序号 int Total = 0; //总人数 Interface face; //界面 Fileoperate Infile; //读入文件类对象 Fileoperate Outfile; //读出文件类对象 Student stu[student_num]; //学生类对象数组 int switchfun(int); //功能函数选择 void Allshow(); //显示所有学生信息 void Searchshow(int [],int,int,int,int); //显示搜索信息 void InFile(); //读入文件函数 void OutFile(); //读出文件函数 int main() { int op_num; //操作序数 char op_char; //选择数 char op_char2; //是否保存 face.Startface(); //启动界面 face.Loadface(); //登陆界面 int flag ,nflag = 0; //输入格式判断标记 do { flag = 0; if(nflag) cout<<"超出范围...Again:"< >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< >op_char2; if(op_char2 == 'Y'||op_char2 == 'y') { cout< >Num1; cout<<"姓名:"; cin>>Name1; cout<<"出生日期:"; cin>>Birthday1; cout<<"性别:"; cin>>Sex1; cout<<"政治面貌:"; cin>>Political_appearance1; cout<<"手机号码:"; cin>>Phone_number1; cout<<"家庭地址:"; cin>>Address1; cout< ='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<<"学号:"; cin>>Num1; cout<<"姓名:"; cin>>Name1; cout<<"出生日期:"; cin>>Birthday1; cout<<"性别:"; cin>>Sex1; cout<<"政治面貌:"; cin>>Political_appearance1; cout<<"手机号码:"; cin>>Phone_number1; cout<<"家庭地址:"; cin>>Address1; cout< >Num1; for( i = 0;i >Name1; for( i = 0;i >Sex1; for( i = 0;i >Political_appearance1; for( i = 0;i >Address1; for( i = 0;i
main.cpp
#include "Student.h" #includeusing 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<<"格式错误..Again:"; cin>>num; for(int i = 0;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<<"格式错误..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<<"格式错误..Again:"; cin>>phone_number; for(int i = 0;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<<"序号:"<
TXT文件格式
学号 姓名 生日 性别 政治面貌 手机号 家庭住址
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。