📄 c.cpp
字号:
printf("Select:");
ch = getche() - '0';
printf("\n\n");
if(ch-1 == i)
return -1;
if(ch-1 > i || ch-1 < 0)
continue;
return ch-1;
}
}
int SelectMonth() //Enter the month when you visit
{
int ch;
char InputBuffer[MAX_PATH]="";
BOOL rtn;
while(1)
{
printf("Please select Month: Select 0 Return\n\n");
do{
printf("Month = ");
scanf("%s", InputBuffer );
rtn = IsdigitStr(InputBuffer);
if(!rtn)
printf("Only input digit!\n");
}while(!rtn);
ch = atoi(InputBuffer);
printf("\n\n");
if(ch == 0)
return -1;
if(ch > 12 || ch < 0)
continue;
return ch;
}
}
int SelectDate(int *SelectedMonth,int *SelectedDay) //Enter the days you need to visit
{
int Result,ch;
char InputBuffer[MAX_PATH]="";
BOOL rtn;
Result = SelectMonth();
if(Result == -1)
return Result;
else
*SelectedMonth = Result;
while(1)
{
printf("Please select Day: Select 0 Return\n\n");
do{
printf("Day = ");
scanf("%s", InputBuffer );
rtn = IsdigitStr(InputBuffer);
if(!rtn)
printf("Only input digit!\n");
}while(!rtn);
ch = atoi(InputBuffer);
printf("\n\n");
if(ch == 0)
{
*SelectedMonth = 0;
return -1;
}
if(*SelectedMonth == 2)
{
if(ch > 28 || ch < 0)
continue;
}
else if(*SelectedMonth == 4 || *SelectedMonth == 6 || *SelectedMonth == 9 || *SelectedMonth == 11)
{
if(ch > 30 || ch < 0)
continue;
}
else
{
if(ch > 31 || ch < 0)
continue;
}
break;
}
*SelectedDay = ch;
return TRUE;
}
void encrypt() //Encrypt the password of administrator
{
int i;
char *p = Password;
for(i=0; i<PASSWORDLEN; i++,p++)
{
Password[i]^=0xab;
Password[i]=(Password[i] & 0xff) << ((i+1)%8) | (Password[i] & 0xff) >> (8-((i+1)%8));
}
}
int GetPeopleInfo(int *TouristIdentity,int *PeopleNumber) //Gain the information of the customer(Including identify and the number of people visiting)
{
int ch,i;
char InputBuffer[MAX_PATH]="";
BOOL rtn;
while(1)
{
printf("Please select Tourist Identity:\n\n");
for(i=0; i<6; i++)
{
printf("%d. %s\n",i+1,TouristIdentityStr[i]);
}
printf("%d. Return\n\n",i+1);
printf("Select:");
ch = getche() - '0';
printf("\n\n");
if(ch-1 == i)
return -1;
if(ch-1 > i || ch-1 < 0)
continue;
break;
}
do{
printf("Please input People Number : ");
scanf("%s", InputBuffer );
rtn = IsdigitStr(InputBuffer);
if(!rtn)
printf("Only input digit!\n");
}while(!rtn);
*TouristIdentity = ch-1;
*PeopleNumber= atoi(InputBuffer);
return TRUE;
}
int CheckAllData() //Check all the information the customer enter
{
int ch;
BOOL DeleteFlag,rtn;
char InputBuffer[MAX_PATH]="";
while(1)
{
printf("Please check current selected all data\n\n");
ViewSelect();
while(1)
{
printf("1.OK\n");
printf("2.Delete \n");
printf("3.Abort\n");
printf("Select:");
ch = getche() - '0';
printf("\n");
if(ch < 1 || ch > 3)
continue;
if(ch == 1)
return TRUE;
if(ch == 2)
{
DeleteFlag = FALSE;
while(1)
{
printf("\n");
printf("Only choose one to delete. 0 for Quit\n");
do{
printf("Delete No = ");
scanf("%s", InputBuffer );
rtn = IsdigitStr(InputBuffer);
if(!rtn)
printf("Only input digit!\n");
}while(!rtn);
ch = atoi(InputBuffer);
printf("\n");
if(ch == 0)
break;
if(ch < 1 || ch > CurrentSelectCount)
continue;
DeleteCurrentSelect(ch-1);
DeleteFlag = TRUE;
break;
}
if(DeleteFlag)
break;
else
continue;
}
return FALSE;
}
}
}
double GetDiscount(int SelectedTourSite,int TouristIdentity) //Discount available
{
if(strcmp(TouristIdentityStr[TouristIdentity],"Child")==0)
return TourSiteInfo[SelectedTourSite].ChildDiscount;
else if(strcmp(TouristIdentityStr[TouristIdentity],"Student")==0)
return TourSiteInfo[SelectedTourSite].StudentDiscount;
else if(strcmp(TouristIdentityStr[TouristIdentity],"Soldier")==0)
return TourSiteInfo[SelectedTourSite].SoldierDiscount;
else if(strcmp(TouristIdentityStr[TouristIdentity],"Elder")==0)
return TourSiteInfo[SelectedTourSite].ElderDiscount;
else if(strcmp(TouristIdentityStr[TouristIdentity],"Group")==0)
return TourSiteInfo[SelectedTourSite].GroupDiscount;
else
return 1;
}
void FreeCurrentSelect() //Reset the resultant information the customer selecting
{
int i;
for(i=0;i<CurrentSelectCount;i++)
{
memset(&CurrentSelect[i],0,sizeof(CURRENTSELECT));
}
CurrentSelectCount = 0;
}
void DeleteCurrentSelect(int Index) //Delete the resultant information of a customer
{
int i;
memset(&CurrentSelect[Index],0,sizeof(CURRENTSELECT));
for(i=Index;i<CurrentSelectCount;i++)
{
memcpy(&CurrentSelect[i],&CurrentSelect[i+1],sizeof(CURRENTSELECT));
}
CurrentSelectCount--;
}
void QueryIncomeAndGain(int SelectedTourSite) //Inquire the income and profit of a certain toursite
{
int ch;
while(1)
{
printf("Query:\n\n");
printf("1.Inquire about the income and profit of midseason\n");
printf("2.Inquire about the income and profit of lowseason\n");
printf("3.Inquire about the income and profit of the whole year\n");
printf("4.Return\n\n");
printf("Select:");
ch = getche();
printf("\n\n");
switch(ch)
{
case '1':
QueryMidseasonIncome(SelectedTourSite);
Clear();
break;
case '2':
QueryLowseasonIncome(SelectedTourSite);
Clear();
break;
case '3':
QueryYearIncome(SelectedTourSite);
Clear();
break;
case '4':
return;
default:
break;
}
}
}
void TourSitePeopleSort() //Sequence the numbers of tourists of every toursite
{
int i;
for(i=0;i<TOURSITE_NUMBER;i++)
{
SortItem[i].Index = i;
SortItem[i].Val = TourSiteData[i].MidseasonPeople + TourSiteData[i].LowseasonPeople;
}
SortData();
printf("People statistics in TourSite\n\n");
printf("TourSite\tM-season People\tL-season People\tTotal People\n");
for(i=0;i<TOURSITE_NUMBER;i++)
{
printf("%s\t%d\t\t%d\t\t%d",
TourSiteStr[SortItem[i].Index],
TourSiteData[SortItem[i].Index].MidseasonPeople,
TourSiteData[SortItem[i].Index].LowseasonPeople,
SortItem[i].Val);
printf("\n");
}
}
void TourSiteIncomeSort() //Sequence the income of every toursite
{
int i;
for(i=0;i<TOURSITE_NUMBER;i++)
{
SortItem[i].Index = i;
SortItem[i].Val = TourSiteData[i].MidseasonIncome + TourSiteData[i].LowseasonIncome;
}
SortData();
printf("Income statistics in TourSite\n\n");
printf("TourSite\tM-season Income\tL-season Income\tTotal Income\n");
for(i=0;i<TOURSITE_NUMBER;i++)
{
printf("%s\t%d\t\t%d\t\t%d",
TourSiteStr[SortItem[i].Index],
TourSiteData[SortItem[i].Index].MidseasonIncome,
TourSiteData[SortItem[i].Index].LowseasonIncome,
SortItem[i].Val);
printf("\n");
}
}
void SortData() //Function using for sequencing
{
SORTITEM Temp;
int i,j,k;
for(i=0;i<TOURSITE_NUMBER-1;i++)
{
k=i;
memcpy(&Temp,&SortItem[i],sizeof(SORTITEM));
for(j=i+1;j<TOURSITE_NUMBER;j++)
{
if(SortItem[j].Val > Temp.Val)
{
k=j;
memcpy(&Temp,&SortItem[j],sizeof(SORTITEM));
}
}
memcpy(&SortItem[k],&SortItem[i],sizeof(SORTITEM));
memcpy(&SortItem[i],&Temp,sizeof(SORTITEM));
}
}
void EstimateCost() //Select the toursites you like and estimate the time and money needed
{
int SelectedMonth,TicketPrice,DayTotal,Total=0;
double Time=0;
int TourSite[TOURSITE_NUMBER];
int ch,i,j;
BOOL SelectedFlag = FALSE;
memset(&TourSite,0,sizeof(TourSite));
SelectedMonth = SelectMonth();
if(SelectedMonth == -1)
return;
while(1)
{
printf("Please choose TourSite\n\n");
for(i=0; i<TOURSITE_NUMBER; i++)
{
printf("%d. %s\n",i+1,TourSiteStr[i]);
}
printf("%d. Return\n\n",i+1);
printf("Select:");
while(1)
{
ch = getche() - '0';
printf("\n\n");
if(ch-1 == i)
break;
if(ch-1 > i || ch-1 < 0)
{
printf("Select:");
continue;
}
SelectedFlag = TRUE;
TourSite[ch-1] = 1;
printf("Please select next TourSite\n");
printf("Select:");
}
if(SelectedFlag)
break;
else
return;
}
printf("You selected is\n\n");
printf("TourSite\tTicketPrice\tCost\tTotal/Day\tVisitTime(Day)\n");
for(j=0;j<TOURSITE_NUMBER;j++)
{
if(TourSite[j])
{
if(SelectedMonth >= MIDSEASON_START && SelectedMonth <= MIDSEASON_END)
TicketPrice = TourSiteInfo[j].MidseasonTicket;
else
TicketPrice = TourSiteInfo[j].LowseasonTicket;
DayTotal = TicketPrice + TourSiteInfo[j].CostOfLiving;
Total += DayTotal;
Time += TourSiteInfo[j].VisitTime;
printf("%s\t%d\t\t%d\t%d\t\t%.1f\n",
TourSiteStr[j],TicketPrice,TourSiteInfo[j].CostOfLiving,DayTotal,TourSiteInfo[j].VisitTime);
}
}
printf("\n");
printf("Total\t\t\t\t\t%d\t\t%.1f\n\n",Total,Time);
}
void Recommendation() //Function used for toursite recommendation
{
int ch;
while(1)
{
printf("Please choose visit day.(0 to return)\n"); //Enter the days you want to visit
printf("Select:");
ch = getche();
printf("\n\n");
switch(ch)
{
case '1':
printf("One Day.Chengcheng is recommended.\n");
printf("Return to the main menu to inquire about details and book tickets.\n");
break;
case '2':
printf("Two Days.Gugong is recommended.\n");
printf("Return to the main menu to inquire about details and book tickets.\n");
break;
case '3':
printf("Three Days.Yiheyuan is recommended.\n");
printf("Return to the main menu to inquire about details and book tickets.\n");
case '0':
return;
default:
break;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -