第十一周阅读程序(补)

/*
 * Copyright 
 (c) 2016,烟台大学计算机与控制工程学院
 * All rights reserved.
 * 文件名称:main.cpp
 * 作    者:胡庆龙
 * 完成日期:2016年6月20日
 * 版 本 号:v1.0
 *第十一周阅读程序
 */
#include <iostream>
using namespace std;
class Data
{
public:
    Data(int i):x(i){cout<<"A";}
    ~Data(){ cout<<"B";}
private:
    int x;
};
class Base
{
public:
    Base(int i):b1(i){cout<<"C";}
    ~Base(){ cout<<"D";}
private:
    int b1;
};
class Derived:public Base
{
public:
    Derived (int i,int j):Base(i),d1(j){
        cout<<"E";
    }
    ~Derived(){cout<<"F";}
private:
    Data d1;
};
int main()
{
    Derived obj(1,2);
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
非常抱歉,我在之前给出的回答中漏掉了第十步和第十一步的具体程序。以下是充的代码: ```cpp public slots: void equalClicked() { QString expression = resultLineEdit->text(); QRegExp regex("([-+*/])"); QStringList numbers = expression.split(regex, QString::SkipEmptyParts); QStringList operators = expression.split(QRegExp("\\d+"), QString::SkipEmptyParts); double result = numbers.at(0).toDouble(); for (int i = 1; i < numbers.size(); i++) { if (operators.at(i - 1) == "+") { result += numbers.at(i).toDouble(); } else if (operators.at(i - 1) == "-") { result -= numbers.at(i).toDouble(); } else if (operators.at(i - 1) == "*") { result *= numbers.at(i).toDouble(); } else if (operators.at(i - 1) == "/") { result /= numbers.at(i).toDouble(); } } resultLineEdit->setText(QString::number(result)); } ``` 在上述代码中,我们定义了一个名为equalClicked()的槽函数,用于处理等号按钮的点击事件。该函数首先获取结果文本框中的表达式,然后使用正则表达式将数字和操作符分隔开。接下来,使用循环遍历数字列表和操作符列表,并根据操作符进行相应的计算操作。最后,将计算结果显示在结果文本框中。 您需要将这个槽函数连接到等号按钮的clicked()信号,以便在等号按钮被点击时执行计算操作。在之前的代码中,您可以在创建等号按钮的部分添加以下代码: ```cpp equalButton = new QPushButton("=", this); layout->addWidget(equalButton, 4, 2); connect(equalButton, &QPushButton::clicked, this, &Calculator::equalClicked); ``` 这样,当等号按钮被点击时,就会触发equalClicked()槽函数进行计算操作。 非常抱歉给您带来的困惑,并感谢您的理解!如果还有其他问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值