景区的门票实行的是淡季票价和旺季票价:
- 淡季从 11 月 01 日 - 03 月 31 日,票价为 40 元/张
- 旺季从 04 月 01 日 - 10 月 31 日,票价为 60 元/张
另外,景区为一些特殊人群提供了门票优惠政策:
- 成年人全票
- 学生半价
- 儿童免票
- 离休人员免票
- 60 岁及以上老年人享受半价优惠
根据参观月份和参观者的类型(用户参观时间直接获取系统时间),输出实际的门票价格。
运行示例:
程序源码:
using System;
namespace ImperialPalaceTicket
{
class ImperialPalaceTicket
{
static void Main(string[] args)
{
// 获取当前月份
int month = Int32.Parse(DateTime.Now.Month.ToString());
int ticketPrice = month > 4 && month < 10 ? 60 : 40;
int count1 = 0, count2 = 0, count3 = 0, count4 = 0, count5 = 0;
Console.WriteLine("欢迎进入故宫博物院售票系统!");
int choice;
do
{
Console.WriteLine("\n\t票价说明:\n淡季(11月1日-3月31日)全价40元/张 \n旺季(4月1日-10月31日)全价60元/张");
Console.WriteLine(" 当前时间:" + DateTime.Now.ToLongDateString().ToString());
Console.WriteLine("\n=====售票菜单=====");
Console.WriteLine("1-成人票(全价)");
Console.WriteLine("2-学生票(半价)");
Console.WriteLine("3-老人票(半价)");
Console.WriteLine("4-儿童票(免费)");
Console.WriteLine("5-离休票(免费)");
Console.WriteLine("0-结束选票\n");
Console.WriteLine("=================");
Console.Write("请输入您的选择:");
choice = Int32.Parse(Console.ReadLine());
switch (choice)
{
// 根据选择判断想要购买票种,提示输入张数
case 1: Console.Write("请输入您想要购买的张数:"); count1 = Int32.Parse(Console.ReadLine()); break;
case 2: Console.Write("请输入您想要购买的张数:"); count2 = Int32.Parse(Console.ReadLine()); break;
case 3: Console.Write("请输入您想要购买的张数:"); count3 = Int32.Parse(Console.ReadLine()); break;
case 4: Console.Write("请输入您想要购买的张数:"); count4 = Int32.Parse(Console.ReadLine()); break;
case 5: Console.Write("请输入您想要购买的张数:"); count5 = Int32.Parse(Console.ReadLine()); break;
case 0: Console.Write("\n选票结束!\n"); break;
default: Console.Write("\n您的输入有误!请重新输入!\n"); break;
}
} while (choice != 0);
// 打印购票信息
Console.WriteLine("您的购票信息如下:");
Console.WriteLine("成人票(" + ticketPrice + "元):" + count1 + "张");
Console.WriteLine("学生票(" + ticketPrice / 2 + "元):" + count2 + "张");
Console.WriteLine("老人票(" + ticketPrice / 2 + "元):" + count3 + "张");
Console.WriteLine("儿童票(0元):" + count4 + "张");
Console.WriteLine("离休票(0元):" + count5 + "张");
// 输出票价
int totalPrice = count1 * ticketPrice + count2 * ticketPrice / 2 + count3 * ticketPrice / 2;
Console.Write("您的票价为:" + totalPrice + "元\n");
}
}
}