用C++:给一个日期,判断它是何星座并给出该星座的特征。要求:面向对象编程,有关功能的实现封装在类中。

来源:百度知道 编辑:UC知道 时间:2024/05/12 10:31:15

#include<iostream>
#include<string>
using namespace std;

class Date
{
int month, day;
public:
Date(int m, int d)
{
set(m, d);
}
void set(int m, int d);

void constell();
};

void Date::set(int m, int d)
{
//在此最好检查日期是否输入正确...
month=m, day=d;
}

void Date::constell()
{
string c[12][2]={ {"魔蝎座", "水瓶座"}, {"水瓶座", "双鱼座"}, {"双鱼座", "白羊座"},
{"白羊座", "金牛座"}, {"金牛座", "双子座"}, {"双子座", "巨蟹座"},
{"巨蟹座", "狮子座"}, {"狮子座", "处女座"}, {"处女座", "天秤座"},
{"天秤座", "天蝎座"}, {"天蝎座", "射手座"}, {"射手座", "魔蝎座"}
};

int x=month-1;
int y=day/21;
cout<<c[x][y];
}