编写过程简单:附代码
void CMyDlg::OnButton1()
{
// TODO: Add your control notification handler code here
double H, L, r, A, C;
CString str;
((CEdit *)(GetDlgItem(IDC_EDIT1)))->GetWindowText(str); //拱高
H = atof(str);
((CEdit *)(GetDlgItem(IDC_EDIT2)))->GetWindowText(str); //弦长
L = atof(str);
if(H<=0 || L<=0)
{
AfxMessageBox("拱高,或弦长数值输入错误!!");
return;
}
((CStatic *)(GetDlgItem(IDC_STATIC1)))->SetWindowText("0.0"); //0.0
((CStatic *)(GetDlgItem(IDC_STATIC2)))->SetWindowText("0.0"); //0.0
((CStatic *)(GetDlgItem(IDC_STATIC3)))->SetWindowText("0.0"); //0.0
((CStatic *)(GetDlgItem(IDC_STATIC4)))->SetWindowText("0.0"); //0.0
r = H/2 + L*L/(8*H);
str.Format("%0.3f", r);
((CStatic *)(GetDlgItem(IDC_STATIC1)))->SetWindowText(str);
str.Format("%0.3f", r*2);
((CStatic *)(GetDlgItem(IDC_STATIC2)))->SetWindowText(str);
A =2*asin((L/2)/r);
str.Format("%0.3f", A*180/3.1415);
((CStatic *)(GetDlgItem(IDC_STATIC4)))->SetWindowText(str);
C=A*r;
str.Format("%0.3f", C);
((CStatic *)(GetDlgItem(IDC_STATIC3)))->SetWindowText(str);
}
推导过程