|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
贴个c代码上去,这样要怎样连接oracle数据库???
#define M 40#include<stdlib.h>
#include<stdio.h>
#include<string.h>
/*全部功能*/
void welcome(); //欢迎界面
int dengji(); //登记入住
int lookfor_room(); //查询房间入住情况
int lookfor_price(); //查询当前费用
int tuifang(); //结账退房
int find(); //找入住人数
long h_calculate(); //按小时计费
long d_calculate(); //按天计费
int per_infor(); //个人信息
void yingzhifu(); //结账付款
int quit(); //退出函数
/*创建结构体date,记录入住和结账时间*/
struct date
{int mon;
int day;
int hour;
};
/*创建结构体hotel,包括房间号、房间种类、入住客户信息、身份证号、按日收费价格
按小时收费价格、入住时间、是否处于入住状态、押金等*/
struct hotel
{int num;
int kind; /*房间种类 1-单人间 2-双人间*/
char name[20];
char ID[19];
int h_money;
int d_money;
struct date time;
int flag; /*flag含义 0-无人入住 1-按小时入住 2-按天入住*/
int deposit;
}room[M];
/*找入住人数*/
int find()
{int count=0,i;
for(i=0;i<M;i++)
if(room[i].flag!=0)
count++;
return count;
}
/*按小时计费*/
long h_calculate(struct date end,struct date start,int money)
{long fee;
int a,b;
a=end.hour-start.hour; //计算小时
b=end.day-start.day; // 计算天数
if(a<0)
{a=a+24;
b=b-1;
}
fee=(a+b*24)*money;//计算费用
return fee;
}
/*按天计费*/
long d_calculate(struct date end,struct date start,int money)
{long fee;
int a,b;
a=end.hour-start.hour; //计算小时
b=end.day-start.day; // 计算天数
if(a>=8)fee=(b+1)*money; //如果小时数大于8,则算为一天
else if(a>=0)fee=b*money; //如果小时数大于0而小于8,则不计算小时
else {a=a+24; //如果小时数小于0,则小时数加24,天数减一,重新计算
b=b-1;
if(a>=8)fee=(b+1)*money;
else fee=b*money;
}
return fee; //有返回值
}
/*个人信息*/
int per_infor(int k)
{char zhonglei[30],fangshi[30];
switch(room[k].flag)
{case 1:strcpy(fangshi,"按小时计费");break;
case 2:strcpy(fangshi,"按天计费");break;
default:break;
}
switch(room[k].kind)
{case 1:strcpy(zhonglei,"单人间");break;
case 2:strcpy(zhonglei,"双人间");break;
}
printf("\n\n\t\t----姓名: "); puts(room[k].name);printf("\n\n");
printf("\t\t----身份证号: ");puts(room[k].ID);printf("\n\n");
printf("\t\t----房间种类: ");puts(zhonglei);printf("\n\n");
printf("\t\t----房间号: "); printf("%d",k+1);printf("\n\n");
printf("\t\t----计费方式: ");puts(fangshi);printf("\n\n");
printf("\t\t----押金: "); printf("%d元",room[k].deposit);printf("\n\n");
printf("\t\t----入住时间: ");
printf("2012年%d月%d日%d时\n\n",room[k].time.mon,room[k].time.day,room[k].time.hour);
return(0);
}
/*最后收费*/
void yingzhifu(long money,int dep)
{long dif=(long)dep-money;
if(dif==0)printf("押金余总费用相等");
else if(dif>0)printf("酒店应找还顾客%ld元",dif);
else printf(" 顾客应再支付%ld元",dif*(-1));
}
/*退出函数,返回主函数*/
int quit()
{int z;
printf("返回欢迎界面吗?1-是 2-否\n\n");
scanf("%d",&z);
if(z==1)
// return(1);
welcome();
else printf("****** 谢谢惠顾 ******!\n\n");
exit(0);
}
/*主菜单*/
void welcome()
{int n=find();
int i,j;
printf("************************************************************************");
printf("\n\n\t\t---------- 欢迎来到爱华酒店 ----------\n\n");
printf("\t\t ((( 1. 登记入住 )))\n\n");
printf("\t\t ((( 2. 查询房间入住情况 )))\n\n");
printf("\t\t ((( 3. 查询当前费用 )))\n\n");
printf("\t\t ((( 4. 结账退房 )))\n\n");
printf("\t\t ((( 5. 退出系统 )))\n\n");
printf("\t\004总房间数: %-3d \004入住人数: %-3d \004空房间数: %-3d",M,n,M-n);
printf("\n\n*************************************************************************\n\n");
printf("\t\t\t-- 请选择您所需的服务: ");
scanf("%d",&i);
switch(i)
{case 1:j=dengji();break;
case 2:j=lookfor_room();break;
case 3:j=lookfor_price();break;
case 4:j=tuifang();break;
default:printf("************* 欢迎下次光临 *************\n\n");exit(0);
}
while(j!=0)
{ welcome();
scanf("%d",&i);
switch(i)
{case 1:j=dengji();break;
case 2:j=lookfor_room();break;
case 3:j=lookfor_price();break;
case 4:j=tuifang();break;
default:printf("\n\n************* 欢迎下次光临 *************\n\n");exit(0);
}
}
}
/*登记入住功能*/
int dengji()
{int i,j,k,yajin,s,a,n;
char ch,fangshi[30];
printf("\n\n-------- 登记入住 --------\n\n");
if(find()==M) //入住人数与房间总数相等
{printf("当前房间已满,是否返回(Y/N): ");
ch=getchar();
if(ch=='y')return(1); //返回主菜单
else exit(0);
}
printf("请选择房间类型:\n\n");
printf("1.单人间 2.双人间\n\n");
printf("\001 ");
scanf("%d",&n);
printf("可供您选择的房间有: \n\n");
for(i=20*(n-1)+1,j=0;i<20*n+1;i++)
if(room[i-1].flag==0)
{printf("%d\t",i);
j=j+1;
if(j%5==0)printf("\n\n");
}
printf("请输入您准备入住的房间号: "); //房间号k--room[k-1]
scanf("%d",&k);
room[k-1].kind=n;
room[k-1].num=k;
printf("\n\n请选择您的计费方式:(1.按小时收费为%d元/时--2.按天计费为%d元/天)",room[k-1].h_money,room[k-1].d_money);
printf("----");
scanf("%d",&s);
while(s!=1&&s!=2)
{printf("输入有误,请重新输入: ");
scanf("%d",&s);
}
if(s==1)room[k-1].flag=1;
else room[k-1].flag=2;
printf("\n\n请输入您的姓名: ");scanf("%s",room[k-1].name);
printf("\n\n请输入您的身份证号: ");scanf("%s",room[k-1].ID);
switch(n)
{case 1:yajin=25;break;
case 2:yajin=50;break;
}
printf("\n\n您应当缴纳的押金金额为 %d元",yajin);
printf("\n\n请输入您实际缴纳的押金金额: ");
scanf("%d",&room[k-1].deposit);
while(room[k-1].deposit<0)
{printf("\t\t\n\n! 输入有误,请重新输入 !\n\n");
printf("\n\n请输入您实际缴纳的押金金额: ");
scanf("%d",&room[k-1].deposit);
}
printf("\n\n请输入是否入住(1.是 2.否): ");
scanf("%d",&a);
while(a!=1&&a!=2){printf("\n\n\t\t 输入有误,请重新输入: ");
scanf("%d",&a);}
if(a==1){printf("\n\n请输入您的入住时间(分别输入月日时): ");
scanf("%d月",&room[k-1].time.mon);
scanf("%d日",&room[k-1].time.day);
scanf("%d时",&room[k-1].time.hour);
switch(room[k-1].flag)
{case 1:strcpy(fangshi,"按小时计费");break;
case 2:strcpy(fangshi,"按天计费");break;
default:break;
}
printf("\n\n您选择的计费方式为----%s",fangshi);
printf("\n\n您已成功登记!\n\n");
}quit();
return(0);
}
/*查询房间入住函数*/
int lookfor_room()
{int i,j,k,s;
struct date tim_t;
char a[20];
printf("\n\n---------- 查询房间入住 ----------\n\n");
printf("\t\t1. 按房号查询\n\n\t\t2. 按客户信息查询\n\n\t\t3. 按入住时间查询\n\n\t\t4. 退出");
printf("\n\n请选择: ");
scanf("%d",&i);
while(1)
{if(i>5||i<1){printf("\n\n\t\t 输入有误,请重新输入: ");
scanf("%d",&i);}
else if(i==1){printf("\n\n请输入房间号: "); //按房号查询
scanf("%d",&j);
if(room[j-1].flag==0)printf("\n\n此房间无人住\n\n");
else{printf("您的个人信息为: ");
per_infor(j-1);}break;
}
else if(i==2){printf("\n\n请输入您的身份证号: "); //按客户信息查询
scanf("%s",a);
while(1)
{for(k=0;k<M;k++)
if(strcmp(a,room[k].ID)==0)break;
if(k!=M)
{printf("\n\n您的个人信息为: ");
per_infor(k);break;
}
else {printf("\t\t\n\n1. 输入有误,请重新输入 2.不存在此人信息,退出 \n\n");
scanf("%d",&s);
if(s==1){printf("\n\n请输入您的身份证号: ");
scanf("%s",a);}
else return(1);}}break;}
else if(i==3)
{printf("\n\n请输入入住时间: ");
scanf("%d月",&tim_t.mon);
scanf("%d日",&tim_t.day);
for(k=0;k<M;k++)
if(tim_t.mon==room[k].time.mon&&tim_t.day==room[k].time.day)break;
if(k==M){printf("\n\n此时间无入住登记\n\n");}
else{printf("\n\n您的个人信息为: ");
per_infor(k);
printf("\n\n");}break;}
else if(i==4)break;
else{printf("\t\t\n\n1. 输入有误,请重新输入 \n\n");
printf("\t\t1. 按房号查询\n\n\t\t2. 按客户信息查询\n\n\t\t3. 按入住时间查询\n\n\t\t4. 退出");
printf("\n\n请选择: ");
scanf("%d",&i);}
}quit();
return(0);
}
/*查询当前费用*/
int lookfor_price()
{int i,s;
struct date end;
printf("\n\n-------- 查询当前费用 ----------\n\n");
if(find()==0)printf("全为空房,没有可查数据!\n\n");
else {printf("请输入房间号: ");
scanf("%d",&i);
while(1)
{if(room[i-1].flag==0){printf("\n\n该房为空房,1.重输2.退出\n\n");
scanf("%d",&s);
if(s==1)
{printf("请输入房间号: ");
scanf("%d",&i);}
else break;}
else{printf("\n\n您的个人信息为: ");
per_infor(i-1);
printf("\n\n请输入您的查询时间: ");
scanf("%d月",&end.mon);
scanf("%d日",&end.day);
scanf("%d时",&end.hour);
printf("\n\n您当前费用为: ");
if(room[i-1].flag==1) //分两种计费方式
printf("H %ld\n\n",h_calculate(end,room[i-1].time,room[i-1].h_money));
else
printf("D %ld\n\n",d_calculate(end,room[i-1].time,room[i-1].d_money));
break;}break;
}}quit();
return(0);
}
/*结账退房*/
int tuifang()
{struct date end;
char zhonglei[30],fangshi[30];
int n,m;
long money;
printf("\n\n---------- 结账退房 ----------\n\n");
if(find()==0)printf("当前房间尚未有人住,无法办理退房手续!\n\n");
else {printf("请输入退房的房间号: ");
scanf("%d",&n);
while(n>M||n<1)
{printf("\n\n输入有误,请重新输入退房的房间号(1~%d):",M);
scanf("%d",&n);
}
if(room[n-1].flag==0)
printf("当前房间尚未有人住,无法办理退房手续!\n\n");
switch(room[n-1].kind)
{case 1:strcpy(zhonglei,"单人间");break;
case 2:strcpy(zhonglei,"双人间");break;
}
switch(room[n-1].flag)
{case 1:strcpy(fangshi,"按小时计费");break;
case 2:strcpy(fangshi,"按天计费");break;
default:break;
}
printf("房间号: %d\n\n房间类型: %s\n\n入住客人姓名: %s\n\n身份证号: %s\n\n",room[n-1].num,
zhonglei,room[n-1].name,room[n-1].ID);
printf("入住时间: ");
printf("2012年%d月%d日%d时",room[n-1].time.mon,room[n-1].time.day,room[n-1].time.hour);
printf("\n\n请输入结账时间: ");
scanf("%d月",&end.mon);
scanf("%d日",&end.day);
scanf("%d时",&end.hour);
printf("\n\n押金: %d",room[n-1].deposit);
printf("\n\n计费方式: ");
printf("%s",fangshi);
if(room[n-1].flag==1)
printf("\n\n当前费用: %ld",money=h_calculate(end,room[n-1].time,room[n-1].h_money));
else
printf("\n\n当前费用: %ld",money=d_calculate(end,room[n-1].time,room[n-1].d_money));
printf("\n\n应支付: ");
yingzhifu(money,room[n-1].deposit);
printf("\n\n是否退房(1.是2.否) : ");
scanf("%d",&m);
if(m==1)
{room[n-1].flag=0;
strcpy(room[n-1].name,"--empty--");
room[n-1].deposit=0;
printf("\n\n您已成功退房,欢迎下次光临!\n\n");
}
}quit();
return(0);
}
/*主函数*/
void main()
{int k,i,j;
for(k=1;k<=M;k++)
{if(k>=1&&k<=20){room[k-1].h_money=20;
room[k-1].d_money=150;}
else if(k>20&&k<=40){room[k-1].h_money=40;
room[k-1].d_money=300;}
}
welcome();
}
|
|