一类定义为一个日期类,包含三个整数数据成员:月,日,年 [英] A class definition for a date class that contains three integer data members:month,day,year
本文介绍了一类定义为一个日期类,包含三个整数数据成员:月,日,年的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不知道他们所要求的在这里。一个例子将是巨大的。
下面是需求的完整列表。我工作过的一本书我一直在阅读的练习,但我在阅读的章节,并结束了,但我只是不能弄明白它。
-
一个类定义包含三个整数数据成员的日期级:月,日,年
-
一个构造函数指定的日期1/1/2000任何新的对象,不收到任何参数。
- 一个构造函数多数民众赞成接受的月和日arguements,并使用2004默认年
- 一个构造函数多数民众赞成接受月,日和年arguements
- 每个构造也应该输出信息给用户,说明当前正在使用哪个构造函数。
- 显示Date对象的值的方法。
解决方案
公共类WeirdRequirements
{
INT m_year,m_month,m_day;
公众委托无效MessagePrinter(字符串消息);
公共MessagePrinter PrintMessage = Console.WriteLine;
公共WeirdRequirements()
{
m_year = 2000;
m_month = 1;
m_day = 1;
PrintMessage(默认);
}
公共WeirdRequirements(INT月,日整型)
{
m_year = 2004;
m_month =月;
m_day =日;
PrintMessage(INT月,日整型);
}
公共WeirdRequirements(INT年,月整型,诠释日)
{
m_year =年;
m_month =月;
m_day =日;
PrintMessage(INT年,月整型,诠释节);
}
公共无效函数printValues()
{
PrintMessage(的String.Format(年= {0}月= {1}天= {2} ,m_year,m_month,m_day));
}
}
I am not sure what they are asking for here. An example would be great.
Here is the complete list of requirements. I am working through an exercise in a book I have been reading but I have read the chapter over and over but I just cant make sense out of it.
A class definition for a date class that contains three integer data members:month,day,year
One constructor that assigns the date 1/1/2000 to any new object that does not recieve any arguments.
- One constructor thats accepts month and day arguements and uses a default year of 2004
- One constructor thats accepts month, day,and year arguements
- Each constructor should also output a message to the user stating which constructor is currently being used.
- A method that displays the values in the date object.
解决方案
public class WeirdRequirements
{
int m_year, m_month, m_day;
public delegate void MessagePrinter(string message);
public MessagePrinter PrintMessage = Console.WriteLine;
public WeirdRequirements()
{
m_year = 2000;
m_month = 1;
m_day = 1;
PrintMessage("default");
}
public WeirdRequirements(int Month, int Day)
{
m_year = 2004;
m_month = Month;
m_day = Day;
PrintMessage("int Month, int Day");
}
public WeirdRequirements(int Year, int Month, int Day)
{
m_year = Year;
m_month = Month;
m_day = Day;
PrintMessage("int Year, int Month, int Day");
}
public void PrintValues()
{
PrintMessage(string.Format("Year={0} Month={1} Day={2}", m_year, m_month, m_day));
}
}
这篇关于一类定义为一个日期类,包含三个整数数据成员:月,日,年的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文