作者matrixjimmy (Jimmy)
看板NTUBIME-99
标题[学业] C++习题翻译..
时间Sat Oct 14 21:24:41 2006
这是翻译文,稍後会再PO如何解题...
3.15 (Date Class)Create a class called Date that includes three pieces of
information as data members - a month (type int), a day (type int) and a
year (type int). Your class should have a constructor with three parameters
that uses the parameters to initialize the three data members. For the
purpose of this exercise, assume that the values provided for the year and
day are correct, but ensure that the month value is in the range 1-12; if
it is not, set the month to 1. Provide a set and a get function for each
data member. Provide a member function displayDate that displays the month,
day and year separated by forward slashes(/). Write a test program that
demonstrates class Date's capabilities.
建立一个名叫"Date"的资料类别(Class)。内容包含三个成员变数:
1.一个整数型态的变数叫"month"
2.一个整数型态的变数叫"day"
3.一个整数型态的变数叫"year"
这个Class必须包含三个启动成员变数的叙述(建构子 constructor),
这个题目的所要达成的目标就是
假设输入年、月、日,而其中月的范围是在1~12之间。
若年与日正确但月份错误,则将月份设为1。
这个Class也要为成员变数提供一个成员函式(function)叫"displayDate"
displayDate 要可以以这种格式显示年/月/日
写一个程式来验证你的资料类别是否正确。
--
燃烧吧,我的小宇宙!
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 61.62.101.203
1F:推 geniuswang35:感恩啊... 10/14 21:25
2F:推 taipei90437: 感恩啊...可不可以提供一下范例 这样比较清楚 谢谢^^ 10/14 21:56
3F:推 ted7726:天阿好复杂...!! 10/14 23:32
4F:推 pipaho:翻成中文还是不太懂..... 10/15 00:00