首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

谁有兴趣把这段C++转成C# 万分感谢了

2012-04-06 
哪位高手有兴趣把这段C++转成C# 万分感谢了//每月还款金额doubledMonthMoneym_dMonthMoneyGive//还款月

哪位高手有兴趣把这段C++转成C# 万分感谢了
//   每月还款金额
double   dMonthMoney   =   m_dMonthMoneyGive;

//   还款月数
int   monthNum   =   m_nMonthNum;

if(m_nMoneyGiveType   ==   0)
{
if(monthNum   <=   0)
{
MessageBox( "[还款月数]输入不正确 ");
CEdit*   pWnd   =   (CEdit*)   GetDlgItem(IDC_MONTH_NUM);
pWnd-> SetFocus();
pWnd-> SetSel(0,   -1);
return;
}

dMonthMoney   =   GetMonthMoneyGive(m_lTotalMoney,   monthNum,   a);
}
else
{
monthNum   =   GetMonthNum(m_lTotalMoney,   dMonthMoney,   a);
}

if(monthNum   <   1)
{
return;
}

//   每月利息
double*   X   =   new   double[monthNum];

//   每月末剩余本金
double*   Y   =   new   double[monthNum];



X[0]   =   m_lTotalMoney   *   a;
Y[0]   =   m_lTotalMoney   -   (dMonthMoney   -   X[0]);

double   XTotalTmp   =   X[0];
int   nPrevGiveNum   =   0;

for(int   i   =   1;   i   <   monthNum;   ++   i)
{
X[i]   =   Y[i   -   1]   *   a;
XTotalTmp   +=   X[i];

Y[i]   =   m_lTotalMoney   -   ((   i   +   1)   *   dMonthMoney   -   XTotalTmp);
}

//   设置结算结果
m_dTotalMoneyGive   =   dMonthMoney   *   monthNum;
m_dMoneyInterestGive   =   0;
m_dBaseMoneyGive   =   m_lTotalMoney   -   Y[monthNum   -   1]   ;
m_dBaseMoneyLeave   =   Y[monthNum   -   1];
m_dMonthMoneyGive   =   dMonthMoney;
m_nMonthNum   =   monthNum;

for(int   k   =   0;   k   <   monthNum;   ++   k)
{
m_dMoneyInterestGive   +=   X[k];
}

if(X   !=   NULL)
{
delete   []X;
X   =   NULL;
}

if(Y   !=   NULL)
{
delete   []Y;
Y   =   NULL;
}

SetCursor(hCursorSrc);

UpdateData(FALSE);

}

double   TryGetMonth(long   totalMoney,   int   monthNum,  
  double   dInterestRate,   double   dPrevMoneyGive,   int   nPrevMoneyGiveMonth,   double   monthMoney)
{
double   dReturn   =   0;

bool   isPrevGive   =   dPrevMoneyGive   >   0;

//   每月利息
double*   X   =   new   double[monthNum];

//   每月末剩余本金
double*   Y   =   new   double[monthNum];

X[0]   =   totalMoney   *   dInterestRate;
Y[0]   =   totalMoney   -   (monthMoney   -   X[0]);

double   XTotalTmp   =   X[0];
int   nPrevGiveNum   =   0;
for(int   i   =   1;   i   <   monthNum;   ++   i)
{
X[i]   =   Y[i   -   1]   *   dInterestRate;
XTotalTmp   +=   X[i];

bool   isPrevCal   =   i   %   nPrevMoneyGiveMonth   >   0;
nPrevGiveNum   =   i   /   nPrevMoneyGiveMonth;



if(isPrevGive   &&   isPrevCal)
{
Y[i]   =   totalMoney   -   ((   i   +   1)   *   monthMoney   -   XTotalTmp)   -   dPrevMoneyGive   *   nPrevGiveNum;
}
else
{
Y[i]   =   totalMoney   -   ((   i   +   1)   *   monthMoney   -   XTotalTmp);
}
}

dReturn   =   Y[monthNum   -   1];

if(X   !=   NULL)
{
delete   []X;
X   =   NULL;
}

if(Y   !=   NULL)
{
delete   []Y;
Y   =   NULL;
}

return   dReturn;
}


double   GetMonthMoneyGive(long   totalMoney,   int   monthNum,  
  double   dInterestRate,   double   dPrevMoneyGive,   int   nPrevMoneyGiveMonth)
{
double   monthMoney   =   0;
double   dLeaveMoney   =   0;

while(true)
{
//dLeaveMoney   =   TryGetMonthMoneyGive(totalMoney,   monthNum,  
//   dInterestRate,   dPrevMoneyGive,   nPrevMoneyGiveMonth,   monthMoney);
if(dLeaveMoney   >   0)
{
monthMoney   +=   1;
}
else
{
break;
}
}

if(dLeaveMoney   <   0)
{
while(true)
{
//dLeaveMoney   =   TryGetMonthMoneyGive(totalMoney,   monthNum,  
//   dInterestRate,   dPrevMoneyGive,   nPrevMoneyGiveMonth,   monthMoney);
if(dLeaveMoney   >   0.00001   )
{
break;
}
else
{
monthMoney   -=   0.000001;
}
}
}

return   monthMoney;
}

//----------------------------------
double   TryGetMonthMoneyGive(long   totalMoney,   int   monthNum,   double   dInterestRate,   double   monthMoney,   bool   isCalMonth/*   =   false*/)
{
double   dReturn   =   0;

//   每月利息
double*   X   =   new   double[monthNum];

//   每月末剩余本金
double*   Y   =   new   double[monthNum];

X[0]   =   totalMoney   *   dInterestRate;
Y[0]   =   totalMoney   -   (monthMoney   -   X[0]);

if(isCalMonth   &&   X[0]   >   monthMoney)
{
char   szMsg[256];
memset(szMsg,   0,   sizeof(szMsg));
sprintf(szMsg,   "%s[%f] ",   "最低还款额要大于 ",   X[0]);
::MessageBox(NULL,   szMsg,   "error ",   MB_OK   |   MB_ICONERROR);

if(X   !=   NULL)
{
delete   []X;
X   =   NULL;
}

if(Y   !=   NULL)
{
delete   []Y;
Y   =   NULL;
}

return   INVALID_RET;
}

double   XTotalTmp   =   X[0];
int   nPrevGiveNum   =   0;
for(int   i   =   1;   i   <   monthNum;   ++   i)
{
X[i]   =   Y[i   -   1]   *   dInterestRate;
XTotalTmp   +=   X[i];

Y[i]   =   totalMoney   -   ((   i   +   1)   *   monthMoney   -   XTotalTmp);



}

dReturn   =   Y[monthNum   -   1];

if(X   !=   NULL)
{
delete   []X;
X   =   NULL;
}

if(Y   !=   NULL)
{
delete   []Y;
Y   =   NULL;
}

return   dReturn;
}


double   GetMonthMoneyGive(long   totalMoney,   int   monthNum,   double   dInterestRate)
{
double   monthMoney   =   0;
double   dLeaveMoney   =   0;

while(true)
{
dLeaveMoney   =   TryGetMonthMoneyGive(totalMoney,   monthNum,  
  dInterestRate,   monthMoney);

if(fabs(INVALID_RET   -   dLeaveMoney)   <   0.001)
{
return   INVALID_RET;
}

if(dLeaveMoney   >   0)
{
monthMoney   +=   1;
}
else
{
break;
}
}

if(dLeaveMoney   <   0)
{
while(true)
{
dLeaveMoney   =   TryGetMonthMoneyGive(totalMoney,   monthNum,  
  dInterestRate,   monthMoney);
if(dLeaveMoney   >   0.00001   )
{
break;
}
else
{
monthMoney   -=   0.0001;
}
}
}

return   monthMoney;
}


int   GetMonthNum(long   totalMoney,   double   dMonthMoney,   double   dInterestRate)
{
int   monthNum   =   1;
double   dLeaveMoney   =   0;

while(true)
{
dLeaveMoney   =   TryGetMonthMoneyGive(totalMoney,   monthNum,  
  dInterestRate,   dMonthMoney,   true);

if(fabs(INVALID_RET   -   dLeaveMoney)   <   0.001)
{
return   -1;
}

if(dLeaveMoney   <   0.1)
{
break;
}

if(dLeaveMoney   >   0)
{
monthNum   +=   1;
}
else
{
break;
}
}


return   monthNum;
}

void   CAcculateFundCalculateDlg::OnCal()  
{
//   TODO:   Add   your   control   notification   handler   code   here
m_calDlg.Create(IDD_DIALOG1,   this);
m_calDlg.ShowWindow(SW_SHOW);
}

void   CAcculateFundCalculateDlg::initMoneyGiveCtl()
{
UpdateData(TRUE);
CEdit*   pWnd1   =   (CEdit*)GetDlgItem(IDC_MONTH_NUM);
CEdit*   pWnd2   =   (CEdit*)GetDlgItem(IDC_MONTH_MONEY_GIVE);
pWnd1-> SetReadOnly(m_nMoneyGiveType   ==   1);
pWnd2-> SetReadOnly(m_nMoneyGiveType   ==   0);
m_nMonthNum   =   (m_nMoneyGiveType   ==   0   ?   m_nMonthNum   :   0);
m_dMonthMoneyGive   =   (m_nMoneyGiveType   ==   1   ?   m_nMonthNum   :   m_dMonthMoneyGive);
}

[解决办法]
好长 友情UP
[解决办法]
帮顶
[解决办法]
差不多,没有太大区别
[解决办法]
控件处理方面改一下就差不多了,主要是太长了楼主
------解决方案--------------------


这基本没啥好转的啊
[解决办法]
就是,一行行读下来...除了控件方面改一下,没什么地方要改.
[解决办法]
改的不多
[解决办法]
JF
[解决办法]
用C++\CLI封装一下直接变成托管类,编译成DLL就可以在C#中直接使用。
[解决办法]
何必 非的要转到C# 在vc中编译成dll
能很好的在C#里面调用(P/Invoke)

热点排行