| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 609 人关注过本帖
标题:[求助]关于类之间传值的问题(我已经想了好久了)
只看楼主 加入收藏
娃娃想你
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2006-11-30
收藏
 问题点数:0 回复次数:5 
[求助]关于类之间传值的问题(我已经想了好久了)

这可能是明天的考试题目,老师让我们提前准备的
但是传值问题我到现在都没解决,所以很着急
PS:我已经很努力的想过了,也试过很多的方法了的
   希望高手有空帮我看看哦

namespace DATE
{
public interface CalendarUnit
{
bool decrement();
}

class Testlt
{
static void Main(string[] args)
{
int a, b, c;
Date date;
Console.WriteLine("请输入你要查询的年!");
a= Convert.ToInt16(Console.ReadLine());
Console.WriteLine("请输入你要查询的月!");
b= Convert.ToInt16(Console.ReadLine());
Console.WriteLine("请输入你要查询的日!");
c = Convert.ToInt16(Console.ReadLine());
date = new Date(a,b,c);
date.printfDate(date.year, date.month, date.day);
date.decrement();
date.printfDate(date.year, date.month, date.day);
}
}

public class Date
{
public Year year = new Year();
public Month month = new Month();
public Day day = new Day();
public Date(int a, int b, int c)
{
if (a < 1 || a > 2006 || b < 1 || b > 12) Console.WriteLine("输入出错!");
if (a == 1 || a == 3 || a == 5 || a == 7 || a == 8 || a == 10 || a == 12)
{
if (c < 1 || c > 31) Console.WriteLine("输入出错!");
}
if (a == 4 || a == 6 || a == 9 || a == 11)
{
if (c < 1 || c > 30) Console.WriteLine("输入出错!");
}
if (year.isleap() == true && b== 2)
{
if (c < 1 || c > 29) Console.WriteLine("输入出错!");
}
if (year.isleap() == false && b == 2)
{
if (c < 1 || c > 28) Console.WriteLine("输入出错!");
}
year .year = a;
month .month = b;
day .day = c;
Console.Read();
}

public bool decrement()
{
day.decrement();
return true;
}

public void printfDate(Year a, Month b, Day c)
{
Console.WriteLine("{0}年{1}月{2}日", a.year , b.month , c.day );
}
}

public class Day :CalendarUnit
{
public int[] sizeIndex ={ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
Year year2 = new Year();
Month month2 = new Month();
private int day_n;

public int day
{
get
{
return day_n;
}
set
{
day_n = value;
}

}
public bool decrement()
{
if (day == 1)
{
if (month2.num ())
day = 29;
else
day = month2.yyf();

month2.decrement();
return false;
}
else
{
day --;
return true;
}
}
}

public class Month : CalendarUnit
{
Year year1 = new Year();
int month_n;
public int[] sizeIndex ={ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
public int month
{
get
{
return month_n;
}
set
{
month_n = value;
}
}
public bool num()
{
if (year1.isleap() && month == 3)
return true;
else
return false;
}
public int yyf()
{
if (month == 1) month = month + 12;
return sizeIndex[month - 1];

}
public bool decrement()
{
if (month == 1)
{
month =12;
year1.decrement();
return false;
}
else
{
month --;
return true;
}
}
}

public class Year : CalendarUnit
{
int year_n;

public int year
{
get
{
return year_n;
}
set
{
year_n = value;
}
}

public bool decrement()
{
year--;
return true;
}

public bool isleap()
{
if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0))
return true;
else
return false;
}
}
}

搜索更多相关主题的帖子: 传值 
2007-01-15 15:06
娃娃想你
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2006-11-30
收藏
得分:0 
整体框架是不能改了的

减肥,编程,背单词一个都不能少!!
2007-01-15 15:07
娃娃想你
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2006-11-30
收藏
得分:0 
老师的要求就是这样的
只有里面的num和yyf这两个方法和所有的属性是我自己加的
为了传值
但是失败了

减肥,编程,背单词一个都不能少!!
2007-01-15 15:08
jacklee
Rank: 7Rank: 7Rank: 7
来 自:XAplus
等 级:贵宾
威 望:32
帖 子:1769
专家分:104
注 册:2006-11-3
收藏
得分:0 
很多代码啊。发晕了。

XAplus!
讨论群:51090447
删吧删吧,把我的号给删了!
2007-01-15 15:22
yelang7
Rank: 1
等 级:新手上路
威 望:1
帖 子:265
专家分:0
注 册:2006-11-3
收藏
得分:0 
注意:
if (a == 1 || a == 3 || a == 5 || a == 7 || a == 8 || a == 10 || a == 12) //这个地方应该是b吧,不是a的(a是年,b是月)
{
if (c < 1 || c > 31) Console.WriteLine("输入出错!");
}
还有这里:
if (a == 4 || a == 6 || a == 9 || a == 11) //这里的a也应该是b,不是a的,注意的地.
{
if (c < 1 || c > 30) Console.WriteLine("输入出错!");
}

[此贴子已经被作者于2007-1-15 16:04:28编辑过]


想象和行动一致,做最棒的 IT 人. http://yelang7.
2007-01-15 15:59
今何在
Rank: 1
等 级:新手上路
帖 子:31
专家分:0
注 册:2007-1-12
收藏
得分:0 

不明白你在问什么
传值有什么问题?


长期稳定接受各类型c/s b/s项目 实现代码可以为vb c c# java jsp asp php QQ:886372
2007-01-15 16:23
快速回复:[求助]关于类之间传值的问题(我已经想了好久了)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015980 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved