当前位置: 首页 > news >正文

《QT实用小工具·二十》存款/贷款计算器

1、概述
源码放在文章末尾

该项目实现了用于存款和贷款的计算器的功能,如下图所示:
在这里插入图片描述

项目部分代码如下:

#ifndef WIDGET_H
#define WIDGET_H#include <QWidget>namespace Ui {
class Widget;
}class Widget : public QWidget
{Q_OBJECTpublic:explicit Widget(QWidget *parent = 0);~Widget();private:Ui::Widget *ui;private slots:void initForm();void on_btnCalc_clicked();void on_btnCalc2_clicked();
};#endif // WIDGET_H
#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);this->initForm();
}Widget::~Widget()
{delete ui;
}void Widget::initForm()
{QDateTime now = QDateTime::currentDateTime();ui->dateStart->setDate(now.date());ui->dateEnd->setDate(now.date().addYears(1));
}void Widget::on_btnCalc_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年=321WQString value = QString::number(moneyAll);ui->txtMoneyAll->setText(value);//拷贝到其他地方if (ui->rbtn1->isChecked()) {ui->txtValue1->setText(value);} else {ui->txtValue2->setText(value);}//计算两种存款方式的差额 比如1年期存3年和3年期存3年QString value1 = ui->txtValue1->text().trimmed();QString value2 = ui->txtValue2->text().trimmed();if (!value1.isEmpty() && !value2.isEmpty()) {int value = qAbs(value1.toInt() - value2.toInt());ui->txtValue->setText(QString::number(value));}
}void Widget::on_btnCalc2_clicked()
{//计算天数QDateTime dateStart = ui->dateStart->dateTime();QDateTime dateEnd = ui->dateEnd->dateTime();int day = dateStart.daysTo(dateEnd);int money = ui->txtMoney2->text().toInt();float rate = ui->txtRate2->text().toFloat();int result = money * rate * day;ui->txtResult2->setText(QString::number(result));qDebug() << day;
}

源码下载

http://www.lryc.cn/news/336827.html

相关文章:

  • hbase基础shell用法
  • ElasticSearch 的 BoolQueryBuilder 使用
  • [C++/Linux] 网络I/O处理
  • HarmonyOS4 页面路由
  • ShardingSphere再回首
  • 第七篇:3.6 其他评估考虑/4.审计指南/5. 通用报告规范/6.披露指南、参考标准及其他 - IAB/MRC及《增强现实广告效果测量指南1.0》
  • 函数、指针和数组的相互运用(C语言)
  • .Net Core/.Net 6/.Net 8,一个简易的消息队列
  • OpenHarmony4.0分布式任务调度浅析
  • element-ui backtop 组件源码分享
  • MongoDB快照(LVM)业务场景应用实战
  • 3D开发工具HOOPS:推动汽车行业CAD可视化发展
  • Centos安装MySQL提示公钥尚未安装
  • FebHost:英国.UK域名简介
  • SQL Serve---查询
  • RabbitMQ3.13.x之十一_RabbitMQ中修改用户密码及角色tags
  • Taro打包生成不同目录
  • 2024-04-08 NO.5 Quest3 手势追踪进行 UI 交互
  • PaddleDetection 项目使用说明
  • leetcode解题思路分析(一百五十五)1352 - 1358 题
  • 如何将普通maven项目转为maven-web项目
  • LeetCode 226. 翻转二叉树
  • 【ArcGIS Pro二次开发】(85):Aspose.Cells中的Excel操作
  • 基于java+springboot+vue实现的兴顺物流管理系统(文末源码+Lw)23-287
  • pytorch view、expand、transpose、permute、reshape、repeat、repeat_interleave
  • uni-app实现下拉刷新
  • vue ts 应用梳理
  • CUDA12.4文档-全文翻译
  • 【C 数据结构】循环链表
  • Python列表