giaiptb2
#define IDR_MENU1 101
#define IDM_DIALOG1 102
#define IDR_ACCELERATOR1 103
#define IDC_EDIT1 1000
#define IDC_EDIT2 1001
#define IDC_EDIT3 1002
#define IDC_EDIT4 1003
#define IDC_BUTTON1 1004
#define ID_FILE_MAYTINH 40001
#define ID_FILE_THOAT 40003
IDR_MENU1 MENU DISCARDABLE
BEGIN
POPUP "&File"
BEGIN
MENUITEM "&May tinh\tCtrl+M", ID_FILE_MAYTINH
MENUITEM "&Close\tCtrl+Z", ID_FILE_THOAT
END
END
IDM_DIALOG1 DIALOG DISCARDABLE 0, 0, 344, 262
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Bai 1"
FONT 8, "MS Sans Serif"
BEGIN
DEFPUSHBUTTON "OK",IDOK,121,206,97,25
PUSHBUTTON "Giai phuong trinh",IDC_BUTTON1,121,126,95,26
LTEXT "He so a:",IDC_STATIC,19,63,30,12
EDITTEXT IDC_EDIT1,55,63,142,14,ES_AUTOHSCROLL
LTEXT "He so b:",IDC_STATIC,19,80,27,14
EDITTEXT IDC_EDIT2,55,81,142,13,ES_AUTOHSCROLL
LTEXT "He so c:",IDC_STATIC,19,98,31,22
EDITTEXT IDC_EDIT3,56,99,141,14,ES_AUTOHSCROLL
EDITTEXT IDC_EDIT4,25,172,281,14,ES_AUTOHSCROLL
LTEXT "CHUONG TRINH GIAI PHUONG TRINH BAC HAI",IDC_STATIC,80,
33,168,22
END
#include<afxwin.h>
#include<math.h>
#include"resource.h"
class CMyApp:public CWinApp
{
public:
BOOL InitInstance();
};
CMyApp theApp;
class CMyDialog:public CDialog
{
public:
CMyDialog(UINT ID, CWnd*owner=NULL):CDialog(ID,owner){}
BOOL OnInitDialog();
afx_msg void OnGiaiPT();
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(CMyDialog,CDialog)
ON_COMMAND(IDC_BUTTON1,OnGiaiPT)
END_MESSAGE_MAP()
BOOL CMyApp::InitInstance()
{
m_pMainWnd=new CMyDialog(IDM_DIALOG1,NULL);
int kq=((CMyDialog*)m_pMainWnd)->DoModal();
return true;
}
BOOL CMyDialog::OnInitDialog()
{
return true;
}
afx_msg void CMyDialog::OnGiaiPT()
{
double a,b,c,d,x1,x2;
char s[20];
CEdit*ed;
ed=(CEdit*)GetDlgItem(IDC_EDIT1);
ed->GetWindowText(s,20);
a=atof(s);
ed=(CEdit*)GetDlgItem(IDC_EDIT2);
ed->GetWindowText(s,20);
b=atof(s);
ed=(CEdit*)GetDlgItem(IDC_EDIT3);
ed->GetWindowText(s,20);
c=atof(s);
ed=(CEdit*)GetDlgItem(IDC_EDIT4);
d=b*b-4*a*c;
if(a==0)
sprintf(s,"He so a bang 0 khong thuc hien");
else
{
if(d<0)
sprintf(s,"Phuong trinh vo nghiem");
else
{
if(d==0)
sprintf(s,"PT co nghiem kep x1=x2=%-0.5lf",-b/(a*2));
else
{
x1=(-b+sqrt(d))/(2*a);
x2=(-b-sqrt(d))/(2*a);
sprintf(s,"PT co 2 nghiem x1=%-0.5lf & x2=%-0.5lf",x1,x2);
}
}
}
ed->SetWindowText(s);
}
Bạn đang đọc truyện trên: Truyen247.Pro