计算器的设计C++

计算器的设计1、设计内容该程序是一个小型实用复数计算器,可以完成复数的加减操作2、程序设计要求1)增加运算符重载功能,可以重载+=、-=、*、++、--、>=、<=、!=... 计算器的设计
1、设计内容
该程序是一个小型实用复数计算器,可以完成复数的加减操作
2、程序设计要求
1)增加运算符重载功能,可以重载+=、- =、*、++、- -、> =、<=、!=运算符,其中,> =、<=是针对复数的模运算。
2)完善计算器测试程序,加减法要求在两位数内进行,而且减法结果不能是负数。增加乘法的测试,乘法要求为一位数的运算。
3)完善输入重载函数,要求可以接收从键盘输入的a+i*b形式的负数,在程序中可以识别出实部、虚部并可以正确赋值。
展开
 我来答
神样0086w
推荐于2016-08-02 · 超过76用户采纳过TA的回答
知道答主
回答量:130
采纳率:0%
帮助的人:146万
展开全部
刚刚写完, 先附上截图程序太长, 附上部分程序
// XRabbitDlg.cpp : implementation file
//#include "stdafx.h"
#include "XRabbit.h"
#include "XRabbitDlg.h"
#include "afxdialogex.h"#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CXRabbitDlg dialog
VOID ChangeText(VOID); CXRabbitDlg::CXRabbitDlg(CWnd* pParent /*=NULL*/)
: CDialogEx(CXRabbitDlg::IDD, pParent)
, XEditStr1(_T(""))
, XEditStr2(_T(""))
, XEditStr3(_T(""))
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}void CXRabbitDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EDIT3, XEditStr1);
DDX_Text(pDX, IDC_EDIT4, XEditStr2);
DDX_Text(pDX, IDC_EDIT5, XEditStr3);
}BEGIN_MESSAGE_MAP(CXRabbitDlg, CDialogEx)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_SHOWWINDOW()
ON_BN_CLICKED(IDC_RADIO1, &CXRabbitDlg::OnBnClickedRadio1)
ON_BN_CLICKED(IDC_RADIO2, &CXRabbitDlg::OnBnClickedRadio2)
ON_BN_CLICKED(IDC_RADIO3, &CXRabbitDlg::OnBnClickedRadio3)
ON_BN_CLICKED(IDC_RADIO4, &CXRabbitDlg::OnBnClickedRadio4)
ON_BN_CLICKED(IDC_BUTTON1, &CXRabbitDlg::OnBnClickedButton1)
END_MESSAGE_MAP()
// CXRabbitDlg message handlersBOOL CXRabbitDlg::OnInitDialog()
{
CDialogEx::OnInitDialog(); // Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon // TODO: Add extra initialization here return TRUE; // return TRUE unless you set the focus to a control
}// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.void CXRabbitDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0); // Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialogEx::OnPaint();
}
}// The system calls this function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CXRabbitDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
} void CXRabbitDlg::OnShowWindow(BOOL bShow, UINT nStatus)
{
CDialogEx::OnShowWindow(bShow, nStatus); // TODO: Add your message handler code here
//static_cast<CButton *>(GetDlgItem(IDC_RADIO1))->SetCheck(TRUE);
}
void CXRabbitDlg::OnBnClickedRadio1()
{
// TODO: Add your control notification handler code here
::ChangeText();
}VOID ChangeText(VOID){
CONST UINT uiIDC[4] = {IDC_RADIO1, IDC_RADIO2, IDC_RADIO3, IDC_RADIO4};
CButton *XRadio;
CString XText, XStr;
for (int i = 0; i != 4; ++i){
XRadio = static_cast<CButton *>(CButton::FromHandle(::GetDlgItem(AfxGetApp()->GetMainWnd()->GetSafeHwnd(), uiIDC[i])));
if (XRadio->GetCheck()){
XRadio->GetWindowText(XText);
XStr = XText.GetAt(0) + CString(L"数");
::SetWindowText(::GetDlgItem(AfxGetApp()->GetMainWnd()->GetSafeHwnd(), IDC_STATIC3), XStr);
XStr = CString(L"被") + XText.GetAt(0) + CString(L"数");
::SetWindowText(::GetDlgItem(AfxGetApp()->GetMainWnd()->GetSafeHwnd(), IDC_STATIC2), XStr);
::SetWindowText(::GetDlgItem(AfxGetApp()->GetMainWnd()->GetSafeHwnd(), IDC_STATIC4), CString(XText.GetAt(0)));
break;
}
}
}void CXRabbitDlg::OnBnClickedRadio2()
{
// TODO: Add your control notification handler code here
::ChangeText();
}
void CXRabbitDlg::OnBnClickedRadio3()
{
// TODO: Add your control notification handler code here
::ChangeText();
}
void CXRabbitDlg::OnBnClickedRadio4()
{
// TODO: Add your control notification handler code here
::ChangeText();
}
void CXRabbitDlg::OnBnClickedButton1()
{
// TODO: Add your control notification handler code here
this->UpdateData(TRUE);
CString cstrOperator;
CStatic *XStatic = static_cast<CStatic *>(GetDlgItem(IDC_STATIC4));
XStatic->GetWindowText(cstrOperator);
double lfNum1 = _tcstod(XEditStr1, NULL);
double lfNum2 = _tcstod(XEditStr2, NULL);
double lfRes = 0.0;
if (cstrOperator == CString(L"加"))
lfRes = lfNum1 + lfNum2;
else if (cstrOperator == CString(L"减"))
lfRes = lfNum1 - lfNum2;
else if (cstrOperator == CString(L"乘"))
lfRes = lfNum1 * lfNum2;
else if (cstrOperator == CString(L"除")){
if (lfNum2 == 0)
AfxMessageBox(_T("除数不为零"));
else
lfRes = lfNum1 / lfNum2;
}
else
AfxMessageBox(_T("未知错误"));
INT iRes = static_cast<int>(lfRes * 10);
XEditStr3.Format(_T("%i"), iRes);
XEditStr3.Insert(XEditStr3.GetLength() - 1, _T("."));
this->UpdateData(FALSE);
}
广州中仪测绘
2023-08-25 广告
作为广州中仪测绘科技有限公司的工作人员,我回答如下:使用工程计算器需要遵循一定的步骤和技巧。首先,打开计算器后,根据需要设置计算器的模式,例如科学模式或程序员模式。然后,根据所进行的工程计算需求,输入相应的数值和运算符号。例如,在计算土方量... 点击进入详情页
本回答由广州中仪测绘提供
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式