星座计算函数
程序代码:
// 星座计算函数 std::string GetZodiacSign(int month, int day) { struct ZodiacSign { std::string name; int startMonth; int startDay; int endMonth; int endDay; }; // 定义星座数组 const std::array<ZodiacSign, 12> zodiacSigns = { { {"水瓶座", 1, 20, 2, 18}, {"双鱼座", 2, 19, 3, 20}, {"白羊座", 3, 21, 4, 19}, {"金牛座", 4, 20, 5, 20}, {"双子座", 5, 21, 6, 20}, {"巨蟹座", 6, 21, 7, 22}, {"狮子座", 7, 23, 8, 22}, {"处女座", 8, 23, 9, 22}, {"天秤座", 9, 23, 10, 22}, {"天蝎座", 10, 23, 11, 21}, {"射手座", 11, 22, 12, 21}, {"摩羯座", 12, 22, 1, 19} } }; for (const auto& sign : zodiacSigns) { if ((month == sign.startMonth && day >= sign.startDay) || (month == sign.endMonth && day <= sign.endDay)) { return sign.name; } } return "未知"; // 如果没有匹配的星座 }