|
![]() | 作者: zhoen889 [zhoen889]
![]() |
登录 |
为什么在这个程序中文件不能被修改? 还有程序中的系统时间函数有什么毛病? 错误的地方在程序中有具体的标志。 谢谢您的指教!!! #include <iostream.h> #include <string.h> #include <fstream.h> #include <time.h> struct node { int Rno; char name[10]; char address[20]; int year; int month; int day; struct Lnode *next; }; struct node Lnode; bool BookRoom(int n)//定房 { int i=0; char string[10]; char address[20]; fstream fp; fp.open("demo.dat",ios::in|ios::out|ios::binary);//写入文件 for(i=0;i<n;i++) { cout<<"请输入房间号码:"; cin>>Lnode.Rno; cout<<"请输入客人姓名:"; cin>>string; cout<<"请输入客人地址:"; cin>>address; cout<<"请输入客人住房日期:"; cin>>Lnode.year>>Lnode.month>>Lnode.day; strcpy(Lnode.name,string); strcpy(Lnode.address,address); fp.write((char *)& Lnode,sizeof(Lnode)); } fp.close(); return true; } void check(int ); void Watch( ); bool Find(int ); void display( ) { cout<<"---------------酒店管理演示程序--------------"<<endl; cout<<"---------------1.定房------------------------"<<endl; cout<<"---------------2.结算------------------------"<<endl; cout<<"---------------3.经营项目--------------------"<<endl; cout<<"---------------4.查询------------------------"<<endl; cout<<"---------------5.退出------------------------"<<endl; cout<<"请输入您的选择:"<<endl; } void main() { int choice=0; int Rnum=0; int num=0; int no=0; do { display( ); cin>>choice; switch(choice) { case 1: cout<<"请问您要定的房间数目:"; cin>>Rnum; if(BookRoom(Rnum)) { cout<<"定房成功"<<endl; } else { cout<<"该房间已经有客人,请重新定房"<<endl; } break; case 2: cout<<" 请输入房间号码:"; cin>>num; check(num); break; case 3: Watch(); break; case 4: cout<<"请输入房间号码:"; cin>>no; if(!Find(no)) { cout<<"没有该客人"<<endl; } break; default: cout<<"请输入正确的选择"<<endl; break; } } while(choice!=5); cout<<"谢谢您的使用"<<endl; } void check(int no) { long int t=0; long int d; char ch; fstream fp; fp.open("demo.dat",ios::in|ios::out|ios::binary); while(fp.read((char *)&Lnode,sizeof(Lnode))) { if(Lnode.Rno==no) { t=365*24*60*Lnode.year+30*24*60*Lnode.month+24*60*Lnode.day; d=time(NULL)-t; d=d/86400; //这个地方有问题!!! cout<<"客人需要付款:"<<(d*50)<<" 元"<<endl; cout<<"客人是否退房(Y/N):"; cin>>ch; if(ch=='Y' || ch=='y') { Lnode.Rno=0; // 为什么这样不可以修改文件??? cout<<"客人已经退房"<<endl; } } } fp.close(); } void Watch( ) { cout<<"主要经营:"<<endl; cout<<" 餐饮, 娱乐, 通信等"<<endl; cout<<"营业时间:8:00-23:00"<<endl; cout<<"欢迎您随时光临"<<endl; } bool Find(int no) //查询 { fstream fp; fp.open("demo.dat",ios::in|ios::out|ios::binary); while(fp.read((char *)&Lnode,sizeof(Lnode))) { if(Lnode.Rno==no) { cout<<"房间号码:"<<Lnode.Rno<<endl; cout<<"客人姓名:"<<Lnode.name<<endl; cout<<"客人地址:"<<Lnode.address<<endl; cout<<"客人入住日期:"<<Lnode.year<<" 年"<<Lnode.month<<" 月"<<Lnode.day<<" 日"<<endl; return true; } } return false; fp.close(); } ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() [此贴被 zhoen889(zhoen889) 在 04月28日19时21分 编辑过] |
地主 发表时间: 04-04-28 19:20 |
![]() | 回复: ziaichen [ziaichen] ![]() |
登录 |
是啊 怎么不能删除呢 大家帮帮忙看看啊? 有谁会啊? |
B1层 发表时间: 04-04-30 23:55 |
|
20CN网络安全小组版权所有
Copyright © 2000-2010 20CN Security Group. All Rights Reserved.
论坛程序编写:NetDemon
粤ICP备05087286号