⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 c.cpp

📁 这个程序可以查看景点简介,订票,查看各景点人数,查看各景点人数排序,选择所想参观的景点,计算时间和费用,查看推荐旅游景点等等。
💻 CPP
📖 第 1 页 / 共 3 页
字号:
		ch = getche();
		printf("\n\n");	
		switch(ch)
		{
			case '1':
				ViewSite("gugong.txt");
				Clear();
			break;
			case '2':
				ViewSite("yiheyuan.txt");
				Clear();
			break;
			case '3':
				ViewSite("changche.txt");
				Clear();
			break;
			case '4':
				ViewSite("beihai.txt");
				Clear();
			break;
			case '5':
				ViewSite("yuanming.txt");
				Clear();
			break;
			case '6':
				ViewSite("tiantan.txt");
				Clear();
			break;
			case '7':
				ViewSite("xiangsha.txt");
				Clear();
			break;
			case '8':
				ViewSite("yonghego.txt");
				Clear();
			break;
			case '9':
				return;
			default:
			break;
		}
	}
}

void ViewSite(char *FileName)	//Show brief introductions of toursites
{
	FILE *fp = NULL;
	int FileLen;
	char *FileBuffer;

	fp=fopen(FileName,"rb");
	if(fp == NULL)
	{
		printf("File %s is not found!\n",FileName);
		return;
	}
	fseek(fp,0L,SEEK_END);
	FileLen=ftell(fp);
	fseek(fp,0L,SEEK_SET);
	FileBuffer = (char *)malloc(FileLen+1);
	memset(FileBuffer,0,FileLen+1);
	fread(FileBuffer,1,FileLen,fp);
	fclose(fp);

	printf(FileBuffer);
	printf("\n\n");
	free(FileBuffer);

}
void TicketSystem()	//Function using for booking tickets
{
	CURRENTSELECT temp;
	int SelectedTourSite,Result,SelectedMonth,SelectedDay;
	int PeopleNumber,TouristIdentity,TotalPeople=0;
	int i=0,DataUpdate=FALSE;
	
	while(1)
	{
		SelectedTourSite = SelectTourSite();
		if(SelectedTourSite == -1)
			break;
		while(1)
		{
			Result = SelectDate(&SelectedMonth,&SelectedDay);
			if(Result == -1)
				break;
			while(1)
			{
				Result = GetPeopleInfo(&TouristIdentity,&PeopleNumber);
				if(Result == -1)
					break;
				memset(&temp,0,sizeof(CURRENTSELECT));

				strcpy(temp.TourSite,TourSiteStr[SelectedTourSite]);
				temp.Month = SelectedMonth;
				temp.Day = SelectedDay;
				strcpy(temp.TouristIdentity,TouristIdentityStr[TouristIdentity]);
				temp.PeopleNumber = PeopleNumber;
				if(SelectedMonth >= MIDSEASON_START && SelectedMonth <= MIDSEASON_END)
					temp.Price = TourSiteInfo[SelectedTourSite].MidseasonTicket;
				else
					temp.Price = TourSiteInfo[SelectedTourSite].LowseasonTicket;
				temp.Discount = GetDiscount(SelectedTourSite,TouristIdentity);
				temp.TotalPrice = (int)(temp.Discount * temp.Price * temp.PeopleNumber);
				memcpy(&CurrentSelect[CurrentSelectCount],&temp,sizeof(CURRENTSELECT));
				CurrentSelectCount++;
				DataUpdate = TRUE;
				printf("************************************\n");
				printf("Please choose next Tourist Identity!\n");
				printf("************************************\n");
			}
			if(DataUpdate)
			{
				for(i=0;i<CurrentSelectCount;i++)
					TotalPeople += CurrentSelect[i].PeopleNumber;
				TotalPeople += TourSiteData[SelectedTourSite].Date[SelectedMonth-1][SelectedDay-1];
				if(TotalPeople > TourSiteInfo[SelectedTourSite].Peoplelimit)
				{
					printf("%s People limit is %d\n",TourSiteStr[SelectedTourSite],TourSiteInfo[SelectedTourSite].Peoplelimit);
					printf("You select Total People is %d\n",TotalPeople);
					printf("People number at %d Day %d Month is excess in %s!\n\n",SelectedDay,SelectedMonth,TourSiteStr[SelectedTourSite]);
					printf("Please inquire about the number of people of every toursite And Choose Another Day!\n");
					FreeCurrentSelect();
					return;
				}

				Result = CheckAllData();
				if(Result)
				{
					SelectToDataFlag = TRUE;
					SelectToData();
				}
				else
					FreeCurrentSelect();
				TotalPeople = 0;
				DataUpdate = FALSE;
			}
			printf("************************\n");
			printf("Please choose next date!\n");
			printf("************************\n");

		}
		printf("****************************\n");
		printf("Please choose next TourSite!\n");
		printf("****************************\n");
	}

}
void QueryTourSitePeople()       //Inquire about the total number of tourists of a certain toursite
{
	int SelectedTourSite,SelectedMonth;
	int i=0;

	while(1)
	{
		SelectedTourSite = SelectTourSite();
		if(SelectedTourSite == -1)
			return;
		while(1)
		{
			SelectedMonth = SelectMonth();
			if(SelectedMonth == -1)
				break;
			printf("People statistics in TourSite\n\n");
			printf("TourSite:%s\t\tMonth:%d\n\n",TourSiteStr[SelectedTourSite],SelectedMonth);
			
			printf("Day");
			for(i=1;i<=7;i++)
				printf("\t%d",i);
			printf("\n");
			printf("People");
			for(i=1;i<=7;i++) 
				printf("\t%d",TourSiteData[SelectedTourSite].Date[SelectedMonth-1][i-1]);
			printf("\n\n");

			printf("Day");
			for(i=8;i<=14;i++)
				printf("\t%d",i);
			printf("\n");
			printf("People");
			for(i=8;i<=14;i++)
				printf("\t%d",TourSiteData[SelectedTourSite].Date[SelectedMonth-1][i-1]);
			printf("\n\n");
			
			printf("Day");
			for(i=15;i<=21;i++)
				printf("\t%d",i);
			printf("\n");
			printf("People");
			for(i=15;i<=21;i++)
				printf("\t%d",TourSiteData[SelectedTourSite].Date[SelectedMonth-1][i-1]);
			printf("\n\n");

			printf("Day");
			for(i=22;i<=28;i++)
				printf("\t%d",i);
			printf("\n");
			printf("People");
			for(i=22;i<=28;i++)
				printf("\t%d",TourSiteData[SelectedTourSite].Date[SelectedMonth-1][i-1]);
			printf("\n\n");
			
			if(SelectedMonth == 4 || SelectedMonth == 6 || SelectedMonth == 9 || SelectedMonth == 11)
			{
				printf("Day");
				for(i=29;i<=30;i++)
					printf("\t%d",i);
				printf("\n");
				printf("People");
				for(i=29;i<=30;i++)
					printf("\t%d",TourSiteData[SelectedTourSite].Date[SelectedMonth-1][i-1]);
				printf("\n\n");
			}
			else
			{
				printf("Day");
				for(i=29;i<=31;i++)
					printf("\t%d",i);
				printf("\n");
				printf("People");
				for(i=29;i<=31;i++)
					printf("\t%d",TourSiteData[SelectedTourSite].Date[SelectedMonth-1][i-1]);
				printf("\n\n");
			}

			Clear();
		}

	}

}
void QueryData()	//Inquire about the data function
{
	int ch,SelectedTourSite;

	if(!VerifyPassword())
		return;
	printf("\n");	

	while(1)
	{
		printf("1.Inquire about the income and profit\n");	
		printf("2.Caculate the incomes of every toursite and sequence them\n");	
		printf("3.Change The Password.\n");
		printf("4.Return\n\n");
		printf("Select:");
		ch = getche();
		printf("\n\n");	
		switch(ch)
		{
			case '1':
				SelectedTourSite = SelectTourSite();
				if(SelectedTourSite == -1)
					break;
				QueryIncomeAndGain(SelectedTourSite);
			break;
			case '2':
				TourSiteIncomeSort();
				Clear();
			break;
			case '3':
				ChangePassword();
				Clear();
			break;
			case '4':
				return;
			default:
			break;
		}
	}

}

BOOL VerifyPassword()	//Verify the password of administrator
{
	FILE *fp = NULL;
	char InputBuffer[MAX_PATH]="";
	char FilePassword[PASSWORDLEN+1]="";
	int count=3;			//Verify the password for three times	

	fp=fopen("tourinfo.dat","rb");		//The file storing the password
	if(fp == NULL)
	{
		strcpy(Password,"TurboC");	//Initializing the password to "Turbo"
		encrypt();
		fp=fopen("tourinfo.dat","wb");
		fwrite(Password,1,PASSWORDLEN,fp);
		fclose(fp);
		fp=fopen("tourinfo.dat","rb");
	}
	fseek(fp,0L,SEEK_SET);
	fread(FilePassword,1,PASSWORDLEN,fp);
	fclose(fp);

	while(1)
	{
		do{
			printf("Administrator Password = ");
			scanf("%s", InputBuffer );
			if(strlen(InputBuffer) > 16)
				printf("Only input less than 16 character!\n");
			else
				break;
		}while(1);

		memset(Password,0,PASSWORDLEN);
		strcpy(Password,InputBuffer);
		encrypt();

		if(memcmp(FilePassword,Password,PASSWORDLEN)==0)
			return TRUE;
		else
		{
			count--;
			if(count)
			{
				printf("Please re-enter your password!\n");
				continue;
			}
			else
				break;
		}
	}
	if(!count)
		printf("Password error for three times, Authentication fails!\n");
	return FALSE;
}

void ChangePassword()	//Modify the password of administrator
{
	FILE *fp = NULL;
	char InputBuffer1[MAX_PATH]="";
	char InputBuffer2[MAX_PATH]="";
	while(1)
	{
		do{
			printf("Administrator New Password = ");
			scanf("%s", InputBuffer1 );
			if(strlen(InputBuffer1) > 16)
				printf("input mast be less than 16 character!\n");
			else
				break;
		}while(1);
		do{
			printf("Administrator New Password Again = ");
			scanf("%s", InputBuffer2 );
			if(strlen(InputBuffer2) > 16)
				printf("input mast be less than 16 character!\n");
			else
				break;
		}while(1);

		if(strcmp(InputBuffer1,InputBuffer2)==0)
			break;
		else
			printf("The new password entered twice doesn't match!\n");
	}
	
	memset(Password,0,PASSWORDLEN);
	strcpy(Password,InputBuffer1);
	encrypt();
	fp=fopen("tourinfo.dat","wb");
	fwrite(Password,1,PASSWORDLEN,fp);
	fclose(fp);
	printf("Change Password Success!\n");
}

void QueryMidseasonIncome(int SelectedTourSite)	  //Inquire about the income in midseason
{
	int i,MidseasonDay=0,gain=0;
	int month[]={31,28,31,30,31,30,31,31,30,31,30,31};
	for(i=0;i<12;i++)
	{
		if(i >= MIDSEASON_START-1 && i <= MIDSEASON_END-1)
			MidseasonDay += month[i];
	}

	gain = TourSiteData[SelectedTourSite].MidseasonIncome - MidseasonDay*TourSiteInfo[SelectedTourSite].M_MaintenanceCost;
	printf("Midseason Income and Gain\n\n");
	printf("TourSite\tIncome\tGain\n");
	printf("%s\t%d\t%d\n",TourSiteStr[SelectedTourSite],TourSiteData[SelectedTourSite].MidseasonIncome,gain);
	printf("\n");	
}
void QueryLowseasonIncome(int SelectedTourSite)	  //Inquire about the income in lowseason
{
	int i,MidseasonDay=0,gain=0,LowseasonDay=0;
	int month[]={31,28,31,30,31,30,31,31,30,31,30,31};
	for(i=0;i<12;i++)
	{
		if(i >= MIDSEASON_START-1 && i <= MIDSEASON_END-1)
			MidseasonDay += month[i];
	}
	LowseasonDay = 365 - MidseasonDay;

	gain = TourSiteData[SelectedTourSite].LowseasonIncome - LowseasonDay*TourSiteInfo[SelectedTourSite].L_MaintenanceCost;
	printf("Lowseason Income and Gain\n\n");
	printf("TourSite\tIncome\tGain\n");
	printf("%s\t%d\t%d\n",TourSiteStr[SelectedTourSite],TourSiteData[SelectedTourSite].LowseasonIncome,gain);
	printf("\n");	
}

void QueryYearIncome(int SelectedTourSite)     //Inquire about the income of the whole year	
{
	int YearIncome,Yeargain;
	int i,MidseasonDay=0,LowseasonDay=0;
	int month[]={31,28,31,30,31,30,31,31,30,31,30,31};
	for(i=0;i<12;i++)
	{
		if(i >= MIDSEASON_START-1 && i <= MIDSEASON_END-1)
			MidseasonDay += month[i];
	}
	LowseasonDay = 365 - MidseasonDay;
	
	YearIncome = TourSiteData[SelectedTourSite].MidseasonIncome + TourSiteData[SelectedTourSite].LowseasonIncome;
	Yeargain =  YearIncome- MidseasonDay * TourSiteInfo[SelectedTourSite].M_MaintenanceCost
		- LowseasonDay * TourSiteInfo[SelectedTourSite].L_MaintenanceCost;
	printf("Year Income and Gain\n\n");
	printf("TourSite\tYear Income\tYear Gain\n");
	printf("%s\t%d\t\t%d\n",TourSiteStr[SelectedTourSite],YearIncome,Yeargain);
	printf("\n");	
}

int SelectTourSite()	//Choose the toursite you like
{
	int ch,i;
	
	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);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -