赞
踩
case 3: //添加信息
cout << “请输入添加学生宿舍信息:” << endl;
cout << “学号:”; cin >> pnum;
stu.panduan(pnum);
cout << “姓名:”; cin >> pnam;
cout << “班级:”; cin >> pcla;
cout << “宿舍:”; cin >> psus;
cout << “床号:”; cin >> pchu;
stu.StuInsert(pnum, pnam, pcla, psus, pchu);
cout << “更新学生宿舍信息表…” << endl;
stu.ShowInfo();
break;
case 4:
cout << “请输入要删除学生学号:”;
cin >> pnum;
stu.StuDelete(pnum);
cout << “更新学生宿舍信息表…” << endl;
stu.ShowInfo();
break;
case 5:
cout << “请输入要查找学生学号:”;
cin >> pnum;
pfind = stu.StuFind(pnum);
cout << “查找学生学号:” << pfind->stu_num << " 姓名: " << pfind->stu_nam << " 班级: " << pfind->stu_cla << " 宿舍: " << pfind->stu_sus << " 床号: " << pfind->stu_chu << endl;
break;
case 6:
cout << “请输入要修改学生学号:”;
cin >> pnum;
cout << “请重新输入学生宿舍信息!”<<endl;
cout << “姓名:”; cin >> pnam;
cout << “班级:”; cin >> pcla;
cout << “宿舍:”; cin >> psus;
cout << “床号:”; cin >> pchu;
stu.StuModify(pnum, pnam, pcla, psus, pchu);
cout << “更新学生宿舍信息表…” << endl;
stu.ShowInfo();
break;
case 9:
stu.ShowInfo();
break;
case 10:
stu.StuQuit();
break;
}
}
}
#include “Ruzhu.h”
#define MAX_NUM 10000000
#include
#include
#include
using namespace std;
struct RuNode{
long ru_num = 0;
char ru_nam[40];
char ru_cla[40];
char ru_mon[40];
char ru_check_in[40];
char ru_check_out[40];
RuNode *nextru;
};
class Ruzhu{
RuNode *RuListHead;
public:
Ruzhu(); //构造函数
~Ruzhu(); //析构函数
void RuCreat(); //创建入住信息
void RuInsert(int num, char* nam, char* cla, char* mon, char* check_in,char* check_out); //插入入住信息
RuNode *RuFind(int num); //查找入住信息,传入参数学号
void RuRead(); //从文件读入入住信息
void RuSave(); //保存学生入住信息到文件
void RuQuit();
void RuShow(); //遍历输出学生入住信息
void panduan(int ru_num);
};
void pdweiru(int ru_num)
{
while (ru_num<10000 || ru_num>99999)
{
cout << “你输入的学号不正确,请输入一个五位数的学号” << endl;
cout << “学号:”;
cin >> ru_num;
}
}
void Ruzhu::panduan(int ru_num)
{
pdweiru(ru_num);
RuNode *p;
for (p = RuListHead->nextru; p != NULL; p = p->nextru)
{
while (p->ru_num == ru_num)
{
cout << “学号重复,请重新输入!” << endl;
cout << “学号:”;
cin >> ru_num;
}
}
}
void RuMenu()
{
time_t t;
time(&t);
cout << “---------------------------------学生入住信息模块-------------------------------” << endl;
cout << “\t\t\t 本地时间:” << ctime(&t);
cout << “--------------------------------------------------------------------------------\n” << endl;
cout << "\t\t 1.读入学生入住信息 " << endl;
cout << "\t\t 2.录入入住信息表格 " << endl;
cout << "\t\t 3.添加新的入住信息 " << endl;
cout << "\t\t 4.查找已有学生信息 " << endl;
cout << "\t\t 5.输出所有学生信息 " << endl;
cout << "\t\t 6.保存现有学生信息 " << endl;
cout << "\t\t 0.返回主菜单 " << endl;
cout << “\n\t\n\t\t请选择:”;
}
Ruzhu::Ruzhu() //构造函数
{
RuListHead = new RuNode;
RuListHead->nextru = NULL;
RuListHead->ru_num = 0;
}
Ruzhu::~Ruzhu() //析构函数
{
RuNode *p;
while (RuListHead)
{
p = RuListHead;
RuListHead = RuListHead->nextru;
delete p;
}
RuListHead = NULL;
}
void Ruzhu::RuRead() //从文件读入数据
{
RuNode *p;
p = RuListHead;
ifstream in(“ruzhua.txt”);
if (!in) { cout << “文件ruzhua.txt中没有入住信息,请先录入入住信息!” << endl; return; }
while (!in.eof())
{
int num; char nam[40]; char cla[40]; char mon[40]; char check_in[40]; char check_out[40];
in >> num >> nam >> cla >> mon >> check_in >> check_out;
RuInsert(num, nam, cla, mon, check_in, check_out);
}
}
void Ruzhu::RuCreat() //创建学生信息表
{
int n;
RuNode *p, *s;
p = RuListHead;
cout << “请输入学生宿舍入住人数:”;
cin >> n;
for (int i = 1; i <= n; i++)
{
s = new RuNode;
cout << “学号:”; cin >> s->ru_num;
panduan(s->ru_num);
cout << “姓名:”; cin >> s->ru_nam;
cout << “班级:”; cin >> s->ru_cla;
cout << “缴费金额:”; cin >> s->ru_mon;
cout << “入住时间:”; cin >> s->ru_check_in;
cout << “退房时间:”; cin >> s->ru_check_out;
s->nextru = p->nextru;
p->nextru = s;
p = p->nextru;
}
if (p == NULL) //判断学生信息表是否创建成功
{
cout << “创建失败请重新创建!” << endl;
RuCreat();
}
}
void Ruzhu::RuInsert(int num, char* nam, char* cla, char* mon, char* check_in, char* check_out) //插入学生入住信息(头插法)
{
RuNode *s, *p;
s = new RuNode;
s->ru_num = num;
strcpy(s->ru_nam, nam);
strcpy(s->ru_cla, cla);
strcpy(s->ru_mon, mon);
strcpy(s->ru_check_in, check_in);
strcpy(s->ru_check_out, check_out);
p = RuListHead;
s->nextru = p->nextru;
p->nextru = s;
}
void Ruzhu::RuShow() //遍历输出
{
RuNode *p;
cout << “学号” << ‘\t’ << “姓名” << ‘\t’ << “班级” << ‘\t’ << “缴费金额” << ‘\t’ << “入住时间” << ‘\t’<<“退房时间”<<endl;
for (p = RuListHead->nextru; p != NULL; p = p->nextru)
{
cout << p->ru_num << ‘\t’ << p->ru_nam << ‘\t’ << p->ru_cla << ‘\t’ << p->ru_mon << ‘\t’ << p->ru_check_in<<‘\t’<ru_check_out << endl;
}
}
RuNode *Ruzhu::RuFind(int num)
{
RuNode *p;
p = RuListHead->nextru;
while (p->nextru && p->ru_num != num) //循环终止条件为p->nextru不为空 而且没有找到相应学号的学生
{
p = p->nextru;
}
if (p->ru_num == num)
{
return p;
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。