コード例 #1
0
ファイル: calculator.cpp プロジェクト: jxwufan/Calculator
Calculator::Calculator(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Calculator)
{
    ui->setupUi(this);

    pastNumber = 0;
    currentNumber = ui->lcd->value();
    state = '\0';
    point = false;
    in = false;
    count = 0;

    connect(ui->button0, SIGNAL(clicked()),
            this, SLOT(push0()));
    connect(ui->button1, SIGNAL(clicked()),
            this, SLOT(push1()));
    connect(ui->button2, SIGNAL(clicked()),
            this, SLOT(push2()));
    connect(ui->button3, SIGNAL(clicked()),
            this, SLOT(push3()));
    connect(ui->button4, SIGNAL(clicked()),
            this, SLOT(push4()));
    connect(ui->button5, SIGNAL(clicked()),
            this, SLOT(push5()));
    connect(ui->button6, SIGNAL(clicked()),
            this, SLOT(push6()));
    connect(ui->button7, SIGNAL(clicked()),
            this, SLOT(push7()));
    connect(ui->button8, SIGNAL(clicked()),
            this, SLOT(push8()));
    connect(ui->button9, SIGNAL(clicked()),
            this, SLOT(push9()));
    connect(ui->buttonDot, SIGNAL(clicked()),
            this, SLOT(pushpoint()));
    connect(ui->buttonCE, SIGNAL(clicked()),
            this, SLOT(ce()));
    connect(ui->buttonC, SIGNAL(clicked()),
            this, SLOT(c()));
    connect(ui->buttonPlus, SIGNAL(clicked()),
            this, SLOT(pushPlus()));
    connect(ui->buttonSub, SIGNAL(clicked()),
            this, SLOT(pushSub()));
    connect(ui->buttonTimes, SIGNAL(clicked()),
            this, SLOT(pushTimes()));
    connect(ui->buttonDiv, SIGNAL(clicked()),
            this, SLOT(pushDiv()));
    connect(ui->buttonEqual, SIGNAL(clicked()),
            this, SLOT(pushEqual()));

    QFont font = ui->button0->font();
    font.setPointSize(40);
    ui->button0->setFont(font);
    ui->button1->setFont(font);
    ui->button2->setFont(font);
    ui->button3->setFont(font);
    ui->button4->setFont(font);
    ui->button5->setFont(font);
    ui->button6->setFont(font);
    ui->button7->setFont(font);
    ui->button8->setFont(font);
    ui->button9->setFont(font);
    ui->buttonC->setFont(font);
    ui->buttonCE->setFont(font);
    ui->buttonEqual->setFont(font);
    ui->buttonDiv->setFont(font);
    ui->buttonTimes->setFont(font);
    ui->buttonPlus->setFont(font);
    ui->buttonSub->setFont(font);
    ui->buttonDot->setFont(font);
}
コード例 #2
0
ファイル: arith01.c プロジェクト: nilqed/ReduceAlgebra
static Lisp_Object plusrr(Lisp_Object a, Lisp_Object b)
/*
 * Adding two ratios involves some effort to keep the result in
 * lowest terms.
 */
{
    Lisp_Object nil = C_nil;
    Lisp_Object na = numerator(a), nb = numerator(b);
    Lisp_Object da = denominator(a), db = denominator(b);
    Lisp_Object w = nil;
    push5(na, nb, da, db, nil);
#define g   stack[0]
#define db  stack[-1]
#define da  stack[-2]
#define nb  stack[-3]
#define na  stack[-4]
    g = gcd(da, db);
    nil = C_nil;
    if (exception_pending()) goto fail;
/*
 * all the calls to quot2() in this procedure are expected - nay required -
 * to give exact integer quotients.
 */
    db = quot2(db, g);
    nil = C_nil;
    if (exception_pending()) goto fail;
    g = quot2(da, g);
    nil = C_nil;
    if (exception_pending()) goto fail;
    na = times2(na, db);
    nil = C_nil;
    if (exception_pending()) goto fail;
    nb = times2(nb, g);
    nil = C_nil;
    if (exception_pending()) goto fail;
    na = plus2(na, nb);
    nil = C_nil;
    if (exception_pending()) goto fail;
    da = times2(da, db);
    nil = C_nil;
    if (exception_pending()) goto fail;
    g = gcd(na, da);
    nil = C_nil;
    if (exception_pending()) goto fail;
    na = quot2(na, g);
    nil = C_nil;
    if (exception_pending()) goto fail;
    da = quot2(da, g);
    nil = C_nil;
    if (exception_pending()) goto fail;
    w = make_ratio(na, da);
/*
 * All the goto statements and the label seem a fair way of expressing
 * the common action that has to be taken if an error or interrupt is
 * detected during any of the intermediate steps here.  Anyone who
 * objects can change it if they really want...
 */
fail:
    popv(5);
    return w;
#undef na
#undef nb
#undef da
#undef db
#undef g
}