我一直在做这个任务,希望我做一个类,当用户输入一个从 1 到 365 的数字时输出一个月和一天。我没有收到任何错误,但我似乎无法从我的print()
函数中获得任何输出。任何帮助,将不胜感激。:]
#include <iostream>
#include <string>
using namespace std;
class DayOfYear
{
public:
DayOfYear(){};
DayOfYear(int);
~DayOfYear(){};
void print();
private:
int day;
};
int main()
{
int numInput;
cout << "\n\n\tPlease enter a day number between 1 and 365.\n\t";
cin >> numInput;
while ((numInput < 1) || (numInput > 365))
{
cout << "\n\tError* Please enter a number between 1 and 365.\n\t";
cin >> numInput;
};
DayOfYear day1(numInput);
//cout << "\n\n\tThat day is ";
day1.print();
cout << " ";
system ("PAUSE");
return 0;
}
DayOfYear::DayOfYear(int numInput)
{
numInput = day;
}
void DayOfYear::print()
{
if (day>0 && day<=31)
{
cout << "January " << day;
};
if (day>31 && day<=59)
{
cout << "February " << (day-31);
};
if (day>59 && day<=90)
{
cout << "March " << (day-59);
};
if (day>90 && day<=120)
{
cout << "April " << (day-90);
};
if (day>120 && day<=151)
{
cout << "May " << (day-120);
};
if (day>151 && day<=181)
{
cout << "June " << (day-151);
};
if (day>181 && day<=212)
{
cout << "July " << (day-181);
};
if (day>212 && day<=243)
{
cout << "August " << (day-212);
};
if (day>243 && day<=273)
{
cout << "September " << (day-243);
};
if (day>273 && day<=304)
{
cout << "October " << (day-273);
};
if (day>304 && day<=334)
{
cout << "November " << (day-304);
};
if (day>334 && day<=365)
{
cout << "December " << (day-334);
};
}