Calculator::Calculator(QWidget *parent) : QDialog(parent), myCurResult(0) { QVBoxLayout* mainLayout = new QVBoxLayout(); setLayout(mainLayout); numberLineEdit = new QLineEdit("0"); numberLineEdit->setValidator(new QIntValidator()); mainLayout->addWidget(numberLineEdit); plusButton = new QPushButton("+"); minusButton = new QPushButton("-"); asterixButton = new QPushButton("*"); slashButton = new QPushButton("/"); QHBoxLayout* btnsLayout = new QHBoxLayout(); btnsLayout->addWidget(plusButton); btnsLayout->addWidget(minusButton); btnsLayout->addWidget(asterixButton); btnsLayout->addWidget(slashButton); mainLayout->addLayout(btnsLayout); connect(plusButton, SIGNAL(clicked()), this, SLOT(sumUp())); connect(minusButton, SIGNAL(clicked()), this, SLOT(subtract())); connect(asterixButton, SIGNAL(clicked()), this, SLOT(multiply())); connect(slashButton, SIGNAL(clicked()), this, SLOT(divide())); }
bool isHappy(int n) { set<int> duplicate; while(n != 1) { if(duplicate.count(n) == 1) return false; else { duplicate.insert(n); n = sumUp(n); } } return true; }
WPMixer::WPMixer(QObject *parent) : QThread(parent), channel(0), chcnt(0), output(0) { timer.setSingleShot(true); connect(&timer, SIGNAL(timeout()), this, SLOT(sumUp())); sdata = 0; tdata = 0; setReadLength(1); /*//debug filein = 0; fileout = 0; fileout2 = 0;*/ }
int main(void) { int limit; printf("Enter how far the sum should be: (<=0 to quit)"); scanf("%d", &limit); while (limit > 0) { printf("sum = %d\n", sumUp(limit)); // function statement printf("Enter how far the sum should be: (<=0 to quit)"); scanf("%d", &limit); } printf("Exiting...\n"); return 0; // return statement }