📄 rsistor.cpp
字号:
*(target+i) = str.GetAt(i);
}
*(target+i) = '\0';
}
CString CRsistor::ftos(CString str, double num)
{
__int64 integer;
char ch_temp[18];
int i,j;
double decimal;
//double d_tmp;
//str = "";
integer = (__int64)num;
_i64toa(integer, ch_temp, 10);
i = 0;
while(ch_temp[i] != '\0')
{
str.Insert(i, ch_temp[i]);
i++;
if(i >= 18)
break;
}
str.Insert(i, '.');
i++;
decimal = num - integer;
//d_tmp = decimal
j = 0;
while(decimal - (__int64)decimal > 0)
{
decimal = decimal * 10.0;
//d_tmp = ;
j++;
if(j > 18)
break;
}
integer = (__int64)decimal;
_i64toa(integer, ch_temp, 10);
j = 0;
while(ch_temp[j] != '\0')
{
str.Insert(i,ch_temp[j]);
i++;
j++;
if(j >= 18)
break;
}
//str.Insert(i, '\0');
return str;
}
int CRsistor::ransack(R_search *pR_search, double ratio)
{
int i,j,m,n,num,k;
double ratio_tmp;
double dispersion_tmp;
double r1_min;
double r1_max;
double r2_min;
double r2_max;
CString c_tmp;
if(m_SR1_Min.IsEmpty())
{
r1_min = 0.0;
}
else
{
r1_min = ConvertFromR(m_SR1_Min);
}
if(m_SR1_Max.IsEmpty())
{
r1_max = 22*M;
}
else
{
r1_max = ConvertFromR(m_SR1_Max);
}
if(m_SR2_Min.IsEmpty())
{
r2_min = 0.0;
}
else
{
r2_min = ConvertFromR(m_SR2_Min);
}
if(m_SR2_Max.IsEmpty())
{
r2_max = 22*M;
}
else
{
r2_max = ConvertFromR(m_SR2_Max);
}
//************* Select percision is 5% or 1% *****************************************
int R_table_m, R_table_n;
double (*R_table)[R_table_5_n]; //指向二维数组的指针
if( m_CR_Percision.GetCurSel() == 1 )
{
R_table_m = R_table_5_m;
R_table_n = R_table_5_n;
R_table = R_table_5_per;
}
else if( m_CR_Percision.GetCurSel() == 0 )
{
R_table_m = R_table_1_m;
R_table_n = R_table_1_n;
R_table = R_table_1_per;
}
//***************开始循环,遍历整个table********************************************
for(n=0; n<R_table_n; n++)
{
for(m=0; m<R_table_m; m++)
{
if( (R_table[m][n] >= r1_min) && (R_table[m][n] <= r1_max) )
{
for(i=0; i<R_table_n; i++)
{
for(j=0; j<R_table_m; j++)
{
if( (R_table[j][i] >= r2_min) && (R_table[j][i] <= r2_max) )
{
ratio_tmp = R_table[m][n] / R_table[j][i];
dispersion_tmp = ((ratio - ratio_tmp) / ratio) * 100;
num = 0;
while(fabs(dispersion_tmp) < fabs(pR_search[num].dispersion))
{
num++;
if(num >= GOOD_NUM)
{
num--;
pR_search[num].dispersion = dispersion_tmp;
pR_search[num].r1 = R_table[m][n];
pR_search[num].r2 = R_table[j][i];
pR_search[num].ratio = ratio_tmp;
num = 0;
break;
}
}
if((num > 0) && (num < GOOD_NUM))
{
num--;
for(k=0; k<num; k++)
{
pR_search[k].dispersion = pR_search[k+1].dispersion;
pR_search[k].r1 = pR_search[k+1].r1;
pR_search[k].r2 = pR_search[k+1].r2;
pR_search[k].ratio = pR_search[k+1].ratio;
}
pR_search[num].dispersion = dispersion_tmp;
pR_search[num].r1 = R_table[m][n];
pR_search[num].r2 = R_table[j][i];
pR_search[num].ratio = ratio_tmp;
}
}
}
}
}
}
}
return 1;
}
CString CRsistor::ConvertToR(CString str, double r)
{
int CurSel;
CurSel = m_CR_Percision.GetCurSel();
if(CurSel == 1)
{
if(r >= M)
{
r = r / M;
str.Format("%.1f", r);
str += "M";
}
else if(r >= K)
{
r = r / K;
str.Format("%.1f", r);
str += "K";
}
else
{
str.Format("%.1f", r);
}
}
else if(CurSel == 0)
{
if(r >= M)
{
r = r / M;
str.Format("%.2f", r);
str += "M";
}
else if(r >= K)
{
r = r / K;
str.Format("%.2f", r);
str += "K";
}
else
{
str.Format("%.2f", r);
}
}
return str;
}
CString CRsistor::DispersionToPercent(CString str, double dispersion, double ratio)
{
double percent;
percent = dispersion / ratio;
percent = percent * 100;
str.Format("%.3f", percent);
str += "%";
return str;
}
double CRsistor::ConvertFromR(CString str)
{
int position;
double r;
char ch_tmp[10];
if((position = str.Find('m')) > 0)
{
str.SetAt(position, '\0');
stoa(ch_tmp, str);
r = atof(ch_tmp);
r = r * M;
}
else if((position = str.Find('M')) > 0)
{
str.SetAt(position, '\0');
stoa(ch_tmp, str);
r = atof(ch_tmp);
r = r * M;
}
else if((position = str.Find('k')) > 0)
{
str.SetAt(position, '\0');
stoa(ch_tmp, str);
r = atof(ch_tmp);
r = r * K;
}
else if((position = str.Find('K')) > 0)
{
str.SetAt(position, '\0');
stoa(ch_tmp, str);
r = atof(ch_tmp);
r = r * K;
}
else
{
stoa(ch_tmp, str);
r = atof(ch_tmp);
}
return r;
}
BOOL CRsistor::OnInitDialog()
{
CDialog::OnInitDialog();
m_CR_Percision.AddString("%1");
m_CR_Percision.AddString("%5");
m_CR_Percision.SetCurSel(1);
return TRUE;
}
void CRsistor::OnOK()
{
OnBUTTONCalculate();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -