彻底改版2.0
This commit is contained in:
11
tool/moneytool/main.cpp
Normal file
11
tool/moneytool/main.cpp
Normal file
@@ -0,0 +1,11 @@
|
||||
#include "widget.h"
|
||||
#include <QApplication>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
Widget w;
|
||||
w.show();
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
13
tool/moneytool/moneytool.pro
Normal file
13
tool/moneytool/moneytool.pro
Normal file
@@ -0,0 +1,13 @@
|
||||
QT += core gui
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat
|
||||
|
||||
TARGET = moneytool
|
||||
TEMPLATE = app
|
||||
DESTDIR = $$PWD/../bin
|
||||
CONFIG += warn_off
|
||||
|
||||
SOURCES += main.cpp
|
||||
SOURCES += widget.cpp
|
||||
HEADERS += widget.h
|
||||
FORMS += widget.ui
|
||||
50
tool/moneytool/widget.cpp
Normal file
50
tool/moneytool/widget.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
#pragma execution_character_set("utf-8")
|
||||
#include "widget.h"
|
||||
#include "ui_widget.h"
|
||||
#include "qmessagebox.h"
|
||||
#include "qdebug.h"
|
||||
|
||||
Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
}
|
||||
|
||||
Widget::~Widget()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void Widget::on_btnOk_clicked()
|
||||
{
|
||||
//当前多少钱
|
||||
int moneyCurrent = ui->txtMoneyCurrent->text().toInt();
|
||||
//利息
|
||||
float rate = ui->txtRate->text().toFloat();
|
||||
//定期期限
|
||||
int year = ui->cboxYear->currentText().left(1).toInt();
|
||||
//总年份 必须是定期期限的倍数
|
||||
int years = ui->txtYears->text().toInt();
|
||||
//最终多少钱
|
||||
int moneyAll = 0;
|
||||
|
||||
if (years % year != 0) {
|
||||
ui->txtYears->setFocus();
|
||||
QMessageBox::critical(this, "错误", "总年份必须是期限的整数倍数!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (ui->cboxType->currentIndex() == 0) {
|
||||
//傻瓜场景 直接计算
|
||||
moneyAll = moneyCurrent + (moneyCurrent * rate * years);
|
||||
} else {
|
||||
//真实场景 复利计算
|
||||
int count = years / year;
|
||||
for (int i = 0; i < count; ++i) {
|
||||
moneyCurrent = moneyCurrent + (moneyCurrent * rate * year);
|
||||
}
|
||||
moneyAll = moneyCurrent;
|
||||
}
|
||||
|
||||
//计算下来3年期定期存款30年总金额翻2番到最初本金3倍 100W本金3年期自动续期30年=321W
|
||||
ui->txtMoneyAll->setText(QString::number(moneyAll));
|
||||
}
|
||||
25
tool/moneytool/widget.h
Normal file
25
tool/moneytool/widget.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef WIDGET_H
|
||||
#define WIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
namespace Ui {
|
||||
class Widget;
|
||||
}
|
||||
|
||||
class Widget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit Widget(QWidget *parent = 0);
|
||||
~Widget();
|
||||
|
||||
private slots:
|
||||
void on_btnOk_clicked();
|
||||
|
||||
private:
|
||||
Ui::Widget *ui;
|
||||
};
|
||||
|
||||
#endif // WIDGET_H
|
||||
150
tool/moneytool/widget.ui
Normal file
150
tool/moneytool/widget.ui
Normal file
@@ -0,0 +1,150 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Widget</class>
|
||||
<widget class="QWidget" name="Widget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>存款计算器</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>10</y>
|
||||
<width>381</width>
|
||||
<height>86</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="2">
|
||||
<widget class="QLabel" name="labYears">
|
||||
<property name="text">
|
||||
<string>年限</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="labMoneyCurrent">
|
||||
<property name="text">
|
||||
<string>本金</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<widget class="QLineEdit" name="txtRate">
|
||||
<property name="text">
|
||||
<string>0.04125</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="txtMoneyCurrent">
|
||||
<property name="text">
|
||||
<string>1000000</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QLabel" name="labRate">
|
||||
<property name="text">
|
||||
<string>利率</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="labYear">
|
||||
<property name="text">
|
||||
<string>期限</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="labType">
|
||||
<property name="text">
|
||||
<string>方式</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QComboBox" name="cboxType">
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>单利</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>复利</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="cboxYear">
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>1年</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>3年</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>5年</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="3">
|
||||
<widget class="QLineEdit" name="txtYears">
|
||||
<property name="text">
|
||||
<string>30</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="3">
|
||||
<widget class="QLineEdit" name="txtMoneyAll"/>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="QLabel" name="labMoneyAll">
|
||||
<property name="text">
|
||||
<string>总计</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="4" rowspan="3">
|
||||
<widget class="QPushButton" name="btnOk">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>计算</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user