| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1803 人关注过本帖
标题:[求助]问一个关于C#重载的问题!
只看楼主 加入收藏
zone0356224
Rank: 1
等 级:新手上路
帖 子:86
专家分:0
注 册:2007-2-1
收藏
 问题点数:0 回复次数:18 
[求助]问一个关于C#重载的问题!

我是初学者,对重载很不了解,但是作业要求又要在函数中实现重载,所以特来请教!!!
希望大家帮帮我!!!谢谢!!!!
这是我写的一个类,里面有函数,算法。(算法是经济预测里面的一次指数平滑和二次指数平滑)
intArrayNumber:数据的组数。
decWeight:加权系数。
strTime:时间。
decQuantity:实际需求量。
decInitial1:一次平滑初始值。
decInitial2:二次平滑初始值。
这个 method_once(int intArrayNumber,decimal decWeight,string strTime,decimal decQuantity,decimal decInitial1)
算是重载么????
我希望能够写出下面有重载要求的函数。
method(int intArrayNumber,decimal decWeight,string strTime,decimal decQuantity,decimal decInitial1)
时函数计算一次指数平滑。
method(int intArrayNumber,decimal decWeight,string strTime,decimal decQuantity,decimal decInitial1,decimal decInitial2)
时函数计算二次指数平滑。


我先写了类,然后在Button事件中调用类中的函数。
下面是一次指数平滑的代码:
using System;

namespace ForecastSystem
{
/// <summary>
/// method_weight 的摘要说明。
/// </summary>
public class method_once
{
//private variables to hold class properties
private string strTime;
private int intArrayNumber;
private decimal decQuantity,decWeight,decInitial1,decSingleTotal,decResult,decMSE;
private static int intCount;
private static decimal []decSingle=new decimal[100];
private static decimal []decTotal_number=new decimal1[100];

public method_once(int intArrayNumber,decimal decWeight,string strTime,decimal decQuantity,decimal decInitial1)
{
//
this.Time=strTime;
this.Quantity=decQuantity;
this.Weight=decWeight;
this.Initial=decInitial1;
this.ArrayNumber=intArrayNumber;
AddTotals();
Add_number();
Forecast();
CalculateMSE();
//
}

public string Time
{
get
{
return strTime;
}
set
{
strTime=value;
}
}

public int ArrayNumber
{
get
{
return intArrayNumber;
}
set
{
intArrayNumber=value;
}
}

public decimal Initial
{
get
{
return decInitial;
}
set
{
decInitial=value;
}
}

public decimal Quantity
{
get
{
return decQuantity;
}
set
{
decQuantity=value;
}
}

public decimal Weight
{
get
{
return decWeight;
}
set
{
decWeight=value;
}
}

public decimal SingleTotal
{
get
{
return decSingleTotal;
}
set
{
decSingleTotal=value;
}
}

public decimal Result
{
get
{
return decResult;
}
set
{
decResult=value;
}
}

public decimal MSE
{
get
{
return decMSE;
}
set
{
decMSE=value;
}
}

public static int Count
{
get
{
return intCount;
}
}

protected void AddTotals()
{
decTotal_number1[0]=decInitial;
decSingle[intCount]=decQuantity;
intCount++;

}

protected void Add_number()
{
if(intArrayNumber<=intCount)
{
for(int a=0;a<intArrayNumber;a++)
{
decTotal_number1[a+1]=decWeight*decSingle[a]+(1-decWeight)*decTotal_number1[a];
}
}
}

protected void Forecast()
{
decResult=decTotal_number1[intArrayNumber];
}

protected void CalculateMSE()
{
if(intArrayNumber<=intCount)
{
for(int a=0;a<intArrayNumber;a++)
{
decSingleTotal+=(decSingle[a]-decTotal_number1[a])*(decSingle[a]-decTotal_number1[a]);
}
decMSE=decSingleTotal/intArrayNumber;
decSingleTotal=0;
}
}
}
}
下面是二次指数平滑的代码
using System;

namespace ForecastSystem
{
/// <summary>
/// method_weight 的摘要说明。
/// </summary>
public class method_twice
{
//private variables to hold class properties
private string strTime;
private int intArrayNumber;
private decimal decQuantity,decWeight,decInitial1,decInitial2,decSingleTotal,decResult,decMSE;
private static int intCount;
private static decimal []decSingle=new decimal[100];
private static decimal []decTotal_number1=new decimal[100];
private static decimal []decTotal_number2=new decimal[100];

public method_twice(int intArrayNumber,decimal decWeight,string strTime,decimal decQuantity,decimal decInitial1,decimal decInitial2)
{
//
this.Time=strTime;
this.Quantity=decQuantity;
this.Weight=decWeight;
this.Initial1=decInitial1;
this.Initial2=decInitial2;
this.ArrayNumber=intArrayNumber;
AddTotals();
Add_number();
Forecast();
CalculateMSE();
//
}

public string Time
{
get
{
return strTime;
}
set
{
strTime=value;
}
}

public int ArrayNumber
{
get
{
return intArrayNumber;
}
set
{
intArrayNumber=value;
}
}

public decimal Initial1
{
get
{
return decInitial1;
}
set
{
decInitial1=value;
}
}

public decimal Initial2
{
get
{
return decInitial2;
}
set
{
decInitial2=value;
}
}

public decimal Quantity
{
get
{
return decQuantity;
}
set
{
decQuantity=value;
}
}

public decimal Weight
{
get
{
return decWeight;
}
set
{
decWeight=value;
}
}

public decimal SingleTotal
{
get
{
return decSingleTotal;
}
set
{
decSingleTotal=value;
}
}

public decimal Result
{
get
{
return decResult;
}
set
{
decResult=value;
}
}

public decimal MSE
{
get
{
return decMSE;
}
set
{
decMSE=value;
}
}

public static int Count
{
get
{
return intCount;
}
}

protected void AddTotals()
{
decTotal_number1[0]=decInitial1;
decTotal_number2[0]=decInitial2;
decSingle[intCount]=decQuantity;
intCount++;

}

protected void Add_number()
{
if(intArrayNumber<=intCount)
{
for(int a=0;a<intArrayNumber;a++)
{
decTotal_number1[a+1]=decWeight*decSingle[a]+(1-decWeight)*decTotal_number1[a];
decTotal_number2[a+1]=decWeight*decTotal_number1[a]+(1-decWeight)*decTotal_number2[a];
}
}
}

protected void Forecast()
{
decResult=decTotal_number2[intArrayNumber];
}

protected void CalculateMSE()
{
if(intArrayNumber<=intCount)
{
for(int a=0;a<intArrayNumber;a++)
{
decSingleTotal+=(decSingle[a]-decTotal_number2[a])*(decSingle[a]-decTotal_number2[a]);
}
decMSE=decSingleTotal/intArrayNumber;
decSingleTotal=0;
}
}
}
}



搜索更多相关主题的帖子: 重载 decimal 需求量 decQuantity decWeight 
2007-02-01 14:55
jacklee
Rank: 7Rank: 7Rank: 7
来 自:XAplus
等 级:贵宾
威 望:32
帖 子:1769
专家分:104
注 册:2006-11-3
收藏
得分:0 

这也重载。分析程序都得要好久哦。


XAplus!
讨论群:51090447
删吧删吧,把我的号给删了!
2007-02-01 14:58
zone0356224
Rank: 1
等 级:新手上路
帖 子:86
专家分:0
注 册:2007-2-1
收藏
得分:0 
不好意思,急啊!!!其实主要呈现都差不多,主要看二次吧!!!
一有的二基本都有,就是加个参数decInitial2后,改变算法!

2007-02-01 15:06
jacklee
Rank: 7Rank: 7Rank: 7
来 自:XAplus
等 级:贵宾
威 望:32
帖 子:1769
专家分:104
注 册:2006-11-3
收藏
得分:0 
mothod(int x);
mothod(int x,int y);
这样行啊。

XAplus!
讨论群:51090447
删吧删吧,把我的号给删了!
2007-02-01 15:11
zone0356224
Rank: 1
等 级:新手上路
帖 子:86
专家分:0
注 册:2007-2-1
收藏
得分:0 
我就是希望能把两个类中的2个函数,弄成一个可以重载的函数。
当调用函数的参数为
method(int intArrayNumber,decimal decWeight,string strTime,decimal decQuantity,decimal decInitial1)时函数计算一次指数平滑。
当调用函数的参数为
method(int intArrayNumber,decimal decWeight,string strTime,decimal decQuantity,decimal decInitial1,decimal decInitial2)时函数计算二次指数平滑。

2007-02-01 15:17
zone0356224
Rank: 1
等 级:新手上路
帖 子:86
专家分:0
注 册:2007-2-1
收藏
得分:0 
但是怎么改呢?
他们两个在两个类里面阿??

2007-02-01 15:18
jacklee
Rank: 7Rank: 7Rank: 7
来 自:XAplus
等 级:贵宾
威 望:32
帖 子:1769
专家分:104
注 册:2006-11-3
收藏
得分:0 

在两个类里面那再写个类把它们拉出来好了。


XAplus!
讨论群:51090447
删吧删吧,把我的号给删了!
2007-02-01 15:28
zone0356224
Rank: 1
等 级:新手上路
帖 子:86
专家分:0
注 册:2007-2-1
收藏
得分:0 
怎么拉阿???完全不明白
我不会阿!能教我下么?

2007-02-01 15:38
zone0356224
Rank: 1
等 级:新手上路
帖 子:86
专家分:0
注 册:2007-2-1
收藏
得分:0 
讲一下怎么操作可以么??
没接触过这个阿!!
完全找不到方向。

2007-02-01 15:46
jacklee
Rank: 7Rank: 7Rank: 7
来 自:XAplus
等 级:贵宾
威 望:32
帖 子:1769
专家分:104
注 册:2006-11-3
收藏
得分:0 
我还没这样做过,继承他们就在一起 了,应该是间接重载吧。你可以试一把

XAplus!
讨论群:51090447
删吧删吧,把我的号给删了!
2007-02-01 15:52
快速回复:[求助]问一个关于C#重载的问题!
数据加载中...
 
   



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

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