c++,输入出生日期,求星座是什么?

/*
***********************************************************************************************************************
输入出生日期,求星座是什么?

思路:(在老九学堂学习的思路)创建一个二维数组,存放每个星座,因为每个月都有两个星座,然后再创一个一维数组,把每个月的分

       割的那一天依次存入一维数组里面,用输入的日期除以它,如果余数为0,则说明是这个月前者的 那个星座, 如果为1则为后者。
	   
       考虑闰年的2月只有28天。 输入年份限制为1900-3000年

************************************************************************************************************************
*/
#include<iostream>
#include<string>
using namespace std;
class Constell
{
private:
	string m_name;
	int m_year;
	int m_month;
	int m_date;
	string conste[12][2] = {
		{ "摩羯座" ,"水瓶座" },     //12-1
		{ "水瓶座" ,"双鱼座" },     //1-2
		{ "双鱼座" ,"白羊座" },     //2-3
                { "白羊座" ,"金牛座" },     //3-4
		{ "金牛座" ,"双子座" },     //4-5
		{ "双子座" ,"巨蟹座" },     //5-6
		{ "巨蟹座" ,"狮子座" },     //6-7
		{ "狮子座" ,"处女座" },     //7-8
		{ "处女座" ,"天秤座" },     //8-9
		{ "天秤座" ,"天蝎座" },     //9-10
		{ "天蝎座" ,"射手座" },     //10-11
		{ "射手座" ,"摩羯座" }      //11-12
	};
	int conste1[12] = { 20,19,21,20,21,22,23,23,23,24,23,22 };   
public:
	Constell();
	~Constell();
	void SetDate();
	void GetDate(int, int, int);

};

void Constell::SetDate()
{
	int year; int month; int day;
	cout << "输入出生年/月/日:";
	cin >> year >> month >> day;
	if (year >= 1900 && year <= 3000 && month >= 1 && month <= 12 && day >= 1 && day <= 31)
	{
		if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
		{
			if (month == 2 && day > 28)
			{
				cout << year << "年2月只有28天!请重新输入" << endl;
				SetDate();
			}
			else
			{
				GetDate(year, month, day);
				cout << "你的星座是: " << conste[m_month - 1][m_date / conste1[m_month - 1]];
			}
		}
		else
		{
			GetDate(year, month, day);
			cout << "你的星座是: " << conste[m_month - 1][m_date / conste1[m_month - 1]];
		}

	}
	else
	{
		cout << "请输入正确日期!" << endl;
		SetDate();
	}
	cout << endl;
}
void Constell::GetDate(int year, int month, int day)
{
	m_year = year;
	m_month = month;
	m_date = day;
}


Constell::Constell()
{
}
Constell::~Constell()
{
}
int main()
{
	Constell c;
	c.SetDate();
	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_42571882/article/details/80955577