This repository has been archived on 2024-01-06. You can view files and clone it, but cannot push or open issues or pull requests.
justhomework/SoftwareDesign/Lab6/2020114490/mainwindow.cpp

37 lines
1 KiB
C++
Raw Normal View History

2022-06-25 04:46:21 +00:00
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include <cmath>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow) {
ui->setupUi(this);
//设置TAB顺序
setTabOrder(ui->equal, ui->x0);
setTabOrder(ui->x0, ui->x1);
setTabOrder(ui->x1, ui->w0);
setTabOrder(ui->w0, ui->w1);
setTabOrder(ui->w1, ui->b);
setTabOrder(ui->b, ui->equal);
}
MainWindow::~MainWindow() { delete ui; }
void MainWindow::on_equal_clicked() {
double num = ui->x0->value() * ui->w0->value() +
ui->x1->value() * ui->w1->value() + ui->b->value();
qDebug() << num;
num = sigmoid(num);
ui->result->setText(QString::number(num, 'f', 16));
ui->list->addItem("f(" + QString::number(ui->x0->value(), 'f', 2) + "," +
QString::number(ui->x1->value(), 'f', 2) +
")=" + QString::number(num, 'f', 2));
}
double MainWindow::sigmoid(double x) { return 1 / (1 + exp(-x)); }
void MainWindow::on_action_triggered() { ui->list->clear(); }