一、
#include<iostream> using namespace std; void PrintfDay(int y, int m, int d); //声明PrintfDay函数 //年大于等于0 //月大于等于1,小于等于12 //日大于等于1-31 class date{ public: int JudgeWeekDay(int year, int month) { static int days[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31,30, 31 }; int day = days[month]; if ((year % 4 == 0 && year % 100 != 0) || ((year % 400 == 0) && month == 2)) { day += 1; } return day; } void Caculate(int y, int m, int d) { int Week = (d + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y / 400) % 7; switch (Week) { case 0: PrintfDay(y, m, d); cout << "是星期一" << endl; break; case 1: PrintfDay(y, m, d); cout << "是星期二" << endl; break; case 2: PrintfDay(y, m, d); cout << "是星期三" << endl; break; case 3: PrintfDay(y, m, d); cout << "是星期四" << endl; break; case 4: PrintfDay(y, m, d); cout << "是星期五" << endl; break; case 5: PrintfDay(y, m, d); cout << "是星期六" << endl; break; case 6: PrintfDay(y, m, d); cout << "是星期日" << endl; break; } } void Setday(int year, int month, int day) { if (year >= 1900 && month > 0 && month < 13 && day>0 && day <= JudgeWeekDay(year, month)) { _year = year; _month = month; _day = day; Caculate(year, month, day); } else { cout << "日期非法" << year << "-" << month << "-" << day << endl; } } void PrintfDay(int y, int m, int d) { if (m == 13 || m == 14) //把一月和二月换算成上一年的十三月和十四月 { m -= 12; y++; } cout << y << "年" << m << "月" << d << "日"; } private: int _year; int _month; int _day; }; int main() { date date1; int year, month, day; cout << "请输入年 月 日" << endl; cin >> year >> month >> day; date1.Setday(year, month, day); return 0; }
二、
#include<iostream> using namespace std; void zhaoling(int n) { int n50, n10, n5, n1; int s = n - 50; if (s == 0) { cout << "刚好购买,不需找零!"; exit(0); } n50 = (int)s / 50; s = s - (n50 * 50); n10 = (int)s / 10; s = s - (n10 * 10); n5 = (int)s / 5; s = s - (n5 * 5); n1 = s; cout << "找回零钱" << n - 50 << "元,其中五十元" << n50 << "张,10元" << n10 << "张,5元" << n5 << "张,1元" << n1 << "张" << endl; } int main() { int pay; cout << "请输入金额:" << endl; cin >> pay; if (pay <= 0 || pay > 100) { cout << "输入金额不正确!!!"; } else if (pay < 50) { cout << "金额不足!!!"; } else { zhaoling(pay); } }
三、
#include<iostream> using namespace std; void main() { int m, n; cout << "请投币:1、一元;2、五角" << endl; cin >> n; if (n == 1) { cout << "请选择商品:1、啤酒;2、橙汁" << endl; cin >> m; if (m == 1) { cout << "请取啤酒" << endl; cout << "找零五角!" << endl; } if (m == 2) { cout << "请取橙汁" << endl; cout << "找零五角!" << endl; } exit(0); } if (n == 2) { cout << "请选择商品:1、啤酒;2、橙汁" << endl; cin >> m; if (m == 1) { cout << "请取啤酒" << endl; } if (m == 2) { cout << "请取橙汁" << endl; } exit(0); } }
四、
#include<iostream> using namespace std; int main() { int hxian,cwei, fxsjian; cout << "请输入航线:1、欧美;2、国外非欧美;3、国内" << endl; cin >> hxian; cout << "请输入舱位:1、经济舱;2、商务舱" << endl; cin >> cwei; cout << "请输入飞行时间:1、两小时以内;2、超过两小时" << endl; cin >> fxsjian; cout << "该次航班服务有:" << endl; if (hxian == 1) { cout << "每个座位都有食物供应,每个座位都可以放电影。" << endl; } if (hxian == 2) { cout << "每个座位有食物供应" << endl; if (cwei == 2) { cout << "可以播放电影" << endl; } } if (hxian == 3) { if (cwei == 1) { if (fxsjian == 1) cout << "无" << endl; if (fxsjian == 2) cout << "食物供应" << endl; } if (cwei == 2) { cout << "食物供应" << endl; } } return 0; }