干支、生肖查询器 v3.0(增加公元前年份的查询)
2017-09-22 15:10
323 查看
//main.cpp //*************************************** //*程序名:判断干支与生肖 //*功 能:输入公元纪年,判断干支与生肖 //*编制人:刘聪 //*创建时间:2017年1月24日 //*修改时间:2017年9月22日(v2.0)(v3.0) //*************************************** #include <iostream> #include <cstring> #include <cstdlib> #include "class.h" using namespace std; int main() { int GetInteger(); void JudgeYear(int year); cout << "***********************************************************" << endl << endl; while(1){ cout << "正数代表公元后,负数代表公元前。" << "请输入需要判断的年号:"; int year = GetInteger(); cout << endl; if(year == 0){ system("pause"); return 0; } else{ if(year > 0){ JudgePositive obj; obj.JudgeYear(year); cout << endl; cout << "***********************************************************" << endl; cout << endl << "若要退出程序,请直接按数字0;否则请继续输入。" << endl << endl; } else{ JudgeNegative obj; obj.JudgeYear(year); cout << endl; cout << "***********************************************************" << endl; cout << endl << "若要退出程序,请直接按数字0;否则请继续输入。" << endl << endl; } } } return 0; } int GetInteger(){ char buf[100] = {0}; while(strlen(buf) == 0) //用户直接输入回车 cin.getline(buf, 100); return atoi(buf); //atoi函数是cstring头文件自带的 }
//class.h #ifndef class_h #define class_h class Judge{ public: virtual void JudgeYear(int year) = 0; }; class JudgePositive:public Judge{ public: void JudgeYear(int year); }; class JudgeNegative:public Judge{ public: void JudgeYear(int year); }; #endif
//class.cpp #include <iostream> #include "class.h" using namespace std; void JudgePositive::JudgeYear(int year){ int a, b, c; a = year % 10 + 7; if(a > 10) a = a - 10; c = b = year % 12 + 9; if(b > 12) c = b = b - 12; cout << year << "年是‘"; switch( a ){ case 1:cout<<"甲";break; case 2:cout<<"乙";break; case 3:cout<<"丙";break; case 4:cout<<"丁";break; case 5:cout<<"戊";break; case 6:cout<<"己";break; case 7:cout<<"庚";break; case 8:cout<<"辛";break; case 9:cout<<"壬";break; case 10:cout<<"癸";break; default:;break; } switch( b ){ case 1:cout<<"子";break; case 2:cout<<"丑";break; case 3:cout<<"寅";break; case 4:cout<<"卯";break; case 5:cout<<"辰";break; case 6:cout<<"巳";break; case 7:cout<<"午";break; case 8:cout<<"未";break; case 9:cout<<"申";break; case 10:cout<<"酉";break; case 11:cout<<"戌";break; case 12:cout<<"亥";break; default:;break; } switch( c ){ case 1:cout<<"鼠";break; case 2:cout<<"牛";break; case 3:cout<<"虎";break; case 4:cout<<"兔";break; case 5:cout<<"龙";break; case 6:cout<<"蛇";break; case 7:cout<<"马";break; case 8:cout<<"羊";break; case 9:cout<<"猴";break; case 10:cout<<"鸡";break; case 11:cout<<"狗";break; case 12:cout<<"猪";break; default:;break; } cout<<"年’。"; } void JudgeNegative::JudgeYear(int year){ int a, b, c; a = year % 10 - 7; if(a < -10) a = a + 10; c = b = year % 12 - 9; if(b < -12) c = b = b + 12; cout << year << "年是‘"; switch( a ){ case -1:cout<<"丁";break; case -2:cout<<"丙";break; case -3:cout<<"乙";break; case -4:cout<<"甲";break; case -5:cout<<"癸";break; case -6:cout<<"壬";break; case -7:cout<<"辛";break; case -8:cout<<"庚";break; case -9:cout<<"己";break; case -10:cout<<"戊";break; default:;break; } switch( b ){ case -1:cout<<"巳";break; case -2:cout<<"辰";break; case -3:cout<<"卯";break; case -4:cout<<"寅";break; case -5:cout<<"丑";break; case -6:cout<<"子";break; case -7:cout<<"亥";break; case -8:cout<<"戌";break; case -9:cout<<"酉";break; case -10:cout<<"申";break; case -11:cout<<"未";break; case -12:cout<<"午";break; default:;break; } switch( c ){ case -1:cout<<"蛇";break; case -2:cout<<"龙";break; case -3:cout<<"兔";break; case -4:cout<<"虎";break; case -5:cout<<"牛";break; case -6:cout<<"鼠";break; case -7:cout<<"猪";break; case -8:cout<<"狗";break; case -9:cout<<"鸡";break; case -10:cout<<"猴";break; case -11:cout<<"羊";break; case -12:cout<<"马";break; default:;break; } cout<<"年’。"; }
相关文章推荐
- VB.NET公元年份转干支(支持公元前)
- 给查询增加一个序列
- sql查询,如何增加一列
- Codeforces Round #348 E. Little Artem and Time Machine(给你一个n,有三种选择,1表示增加一个值,2表示删除这个数的一个值,3表示查询)
- Yii 框架里数据库操作详解-[增加、查询、更新、删除的方法 'AR模式']
- iPhone开发中现文件的增加 删除和查询
- postgreSQL 在日期的基础上增加年份再减去一天的方法
- ExtJs_Grid的增加、删除、修改、查询操作
- C# 查询 增加 修改 删除 操作数据库方法
- 增加删除修改完后跳转到查询页面
- C#使用XmlDocument操作XML进行查询、增加、修改、删除、保存应用的实例
- 让select查询结果额外增加自增的伪序号列
- iPhone开发 文件的增加删除查询
- mysql按照天、月份、年份统计查询
- 订单编号的查询增加(对于要不断删增的表)
- SQL查询时增加自动编号
- MySql每月增加一个分区以及查询所有分区
- .net连接数据库,实现增加,修改,删除,查询的四大功能完整代码。
- AngularJs球员的增加查询排序的方法
- 简单修改Hibernate源码,增加使用原生SQL查询时动态addEntity和addScalar功能