看谁能把这个C程序改写成C++格式的程序!!(程序分两部分发)
程序其中可能部分还有错误~~
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#include<malloc.h>
#include<iostream.h>
#include<string.h>
#define NUM 100 //假设该旅店最多容纳100人
struct Client{
char Name[20];
int Sex;
int Age;
char ID_card[20];//居民身份证;
};
struct Hotel{
int Room_ID;//房间号
int Price;
bool Sign;//标记房间是否为空房间;
struct Client Client_list;//实现两个结构体的嵌套
}Room[NUM];
#define LENGTH sizeof(struct Hotel)
static int count=0,recount=0;//被使用的房间的统计数目和当前记录数
void Query_Client_List();
void Read_file(struct Hotel);
void Handle_menu();
void Delete_room(struct Hotel);
void Add_new_client(struct Hotel);
void Show_All_Client(struct Hotel,int);
void Query_Room_ID(struct Hotel);
void Query_room_Empty(struct Hotel Room[]);
void Write_file(struct Hotel);
void Initialize_room_ID(struct Hotel);
void main()
{
Read_file(struct Hotel Room[]);//能不能把这个函数设置为
Initialize_room_ID(struct Hotel Room[]);
Handle_menu();
}
//从硬盘读取文件,以便对下面进行操作,这里是程序的关键
void Read_file(struct Hotel Room[])
{
FILE *fp;
int i;
if((fp=fopen("Client_table","rb"))==NULL)
//检测文件是不是能打开,不能打开,将创建一个新的文件
{
if((fp=fopen("Client_table","wb"))==NULL)
{
cout<<"\n 文件不能被打开!"<<endl;
exit(1);
}
fclose(fp);
}
if((fp=fopen("Client_table","rb))==NULL)
{
cout<<"\n 文件出现问题,不能被打开,请重试!!!"<<endl;
exit(1);
}
i=0;
count=0;
recount;
while(!feof(fp))
//读文件一直到当前记录
{
if(1!=fread(&Room[i],LENGTH,1,fp)
break;
++recount;
++count;
i++;
}
fclose(fp);
cout<<"\n 总共记录条数:"<<count <<endl;
}
//这个函数是写文件操作,当有新的记录时,将记录写入文件
//初始化旅店的函数,但是我们也遇到了麻烦
void Initialize_room_ID(struct Hotel Room[])
{
int ID=100,mark=0;
//,k=0;
//动态分配存储空间
Room=(struct Hotel *)malloc(100*sizeof(struct Hotel));
//以下便是初始化过程
for(int i=1;i<=5;i++)
for(int j=1;j<=20;j++)
{
Room[mark].Room_ID=ID*i;
Room[mark].Price=100;
Room[mark].Sign=false;
//Room[mark].Tel=8500+k;
//k++;
}
}
//在每次运行该函数的时候,需要解决一些问题
//保存文件函数
void Write_file(struct Hotel Room[])
{
FILE *fp;
int i;
if((fp=fopen("Client_table","wb"))==NULL)
{
cout>>"\n不能打开该文件!"<<endl;
exit(1);
}
//以下部分也就是实现写操作
for(i=0;i<count;i++)
if(fwrite(&Room[i],LENGTH,1,fp)
cout<<"\n写文件发生错误"<<endl;
fclose(fp);
}
int Handle_menu()
{int Selection;
//读文件的过程
cout<<"\n *********欢迎进入客房管理信息系统********* "<<endl;
cout<<"\n 1、顾客登记入住 "<<endl;
cout<<"\n 2、信息查询 "<<endl;
cout<<"\n 3、订房 "<<endl;
cout<<"\n 4、退房 "<<endl;
cout<<"\n 0、退出 "<<endl;
cout<<"\n ****************************************** "<<endl;
cin>>Selection;
while(1)
{
switch(Selection)
{
case 1: Add_new_client(struct Hotel Room[]);Write_file(struct Hotel Room[]);break;
case 2: Query_Client_List();break;
case 3: Room_Book(struct Hotel Room[]);break;
case 4: Delete_room(struct Hotel Room[]);Write_file(struct Hotel Room[]);break;
case 0: exit(0);break;
defaut: cout<<"\n 请按任意键继续"<<endl;
}
}
}