当前位置:首页 > C++学生信息管理系统(一卡通)
//由于对fsream的不熟练,不会对指定部分的数据的修改,因而删除了一些功能,同时也导致了只能对消费额进行加减,但不能导入txt文件。 Code:
Uni-card system.h
#include
public:
void buildAdmin(); void buildUndergraduate(); void buildPostgraduate(); protected:
char name[20]; char sex; char shape[10]; char tel[12]; };
class consumer:public person {
protected:
double money; };
class student :public consumer //定义学生类 {
protected:
char number[20]; int age;
char nowClass[20]; char birthPlace[20]; };
class admin :public person //定义管理员类 {
public:
void login(); void adminRegister();
void adminRegister2(); private:
char account[12]; char password[12]; char title; };
class undergraduate :public student //定义本科生类 {
public:
void searchUndergraduate(); void displayUndergraduate(); void inputUndergraduate_wrapper(); void inputUndergraduate(); void inputUndergraduate1(); void underPayout(char str[]); void monitorPower();
void outputClassStudent(char s[]); void underSearchAll(); private:
char monitor; };
class postgraduate :public student //定义研究生类 {
public:
void searchPostgraduate(); void displayPostgraduate(); void inputPostgraduate_wrapper(); void inputPostgraduate(); void inputPostgraduate1(); void postPayout(char str[]); void postSearchAll(); protected: double wage; };
//不清楚教职工是否配备有一卡通,所以暂不考虑教职工类
Uni-card system.cpp #include
#include
//------------------------------------------------------------------
//---------------------以下为person类中成员函数--------------------- //------------------------------------------------------------------ void person::buildAdmin() //建立Admin.txt {
fstream file(\打开文件,指针指向文件尾 }
void person::buildUndergraduate() //建立Undergraduate.txt {
fstream file(\打开文件,指针指向文件尾 }
void person::buildPostgraduate() //建立Postgraduate.txt {
fstream file(\打开文件,指针指向文件尾 }
//------------------------------------------------------------------
//--------------------以下为admin类中成员函数----------------------- //------------------------------------------------------------------ void admin::login() //管理员登录及验证 {
int ensurance=0;
char account2[12],password2[12]; admin ad; cout << endl
<< \ ★★★★★管理员登录界面★★★★★\ cout << \ 请输入您的账号: \ cin >> account2;
cout << \ 请输入您的密码:\ cin >> password2;
fstream file(\打开文件,指针在文件头
file.read((char*)&ad,sizeof(ad)); //读取类信息
while(!file.eof()) //判断文件指针是否到文件尾 {
file.close(); //关闭文件 file.close(); //关闭文件 file.close(); //关闭文件
if(comp(ad.account,account2)&&comp(ad.password,password2)) //判断输入的字符
是否与文件中的一样 {
cout << \ 登录成功!\ ensurance=1;break; } }
void admin::adminRegister() //管理员在文件外录入信息 {
admin adm; char choose; int loop=1,loop1=1; cout << endl
<< \ ★★★★★管理员注册★★★★★\ while(loop1) {
loop1=0;
cout << \ 输入您的账号(12位以内):\ fstream file(\打开文件,指针在文件头 file.read((char*)&adm,sizeof(adm)); //读取类信息
while(!file.eof()) //判断文件指针是否到文件尾 {
if(comp(adm.account,account)) //判断输入的字符是否与文件中的一样 {
cout << \ 账号已被占用!\ loop1=1; break; }
file.read((char*)&adm,sizeof(adm));//如果指针没到文件尾,继续读取 }
file.close(); }
cout << \ 输入您的密码(12位以内):\ cout << \ 输入您的姓名:\ while(loop) {
cout << \ 选择您的性别(A.男,B.女):\ cin >> choose;
}
file.close();
if(ensurance==0) cout << \ 您的账号或密码输入错误!\file.close(); //关闭文件 if(ensurance) adminOnLogin();
file.read((char*)&ad,sizeof(ad));//如果指针没到文件尾,继续读取
共分享92篇相关文档