日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

C++實現簡單學生信息管理系統_C 語言

作者:陸鳴笙 ? 更新時間: 2022-05-20 編程語言

本文實例為大家分享了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"
#include 
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<<"格式錯誤..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文件格式

學號 姓名 生日 性別 政治面貌 手機號 家庭住址

原文鏈接:https://blog.csdn.net/cjl1831050185/article/details/117710833

欄目分類
最近更新