10.29总结

news/2025/10/30 0:03:16/文章来源:https://www.cnblogs.com/zhao-hang/p/19175631

include

include

include

include

include

include

using namespace std;

// 账户类型枚举
enum AccountType {
SAVING, // 活期
FIXED_1Y, // 定期一年
FIXED_3Y, // 定期三年
FIXED_5Y // 定期五年
};

// 账户类
class Account {
private:
string accountId; // 账户ID
AccountType type; // 账户类型
double balance; // 余额
time_t openTime; // 开户时间
double interestRate; // 利率
double interest; // 利息

public:
Account(string id, AccountType t, double rate)
: accountId(id), type(t), balance(0), interestRate(rate), interest(0) {
openTime = time(nullptr);
}

string getAccountId() const { return accountId; }
AccountType getType() const { return type; }
double getBalance() const { return balance; }
double getInterest() const { return interest; }
time_t getOpenTime() const { return openTime; }
double getInterestRate() const { return interestRate; }void setInterestRate(double rate) { interestRate = rate; }// 存款
void deposit(double amount) {balance += amount;
}// 取款,返回是否成功
bool withdraw(double amount) {if (amount <= balance) {balance -= amount;return true;}return false;
}// 计算利息(移除const修饰符,因为需要修改interest)
void calculateInterest() {time_t now = time(nullptr);double days = difftime(now, openTime) / (60 * 60 * 24);interest = balance * interestRate * days / 365;
}// 显示账户信息
void display() const {cout << "账户ID: " << accountId << endl;cout << "账户类型: ";switch (type) {case SAVING: cout << "活期"; break;case FIXED_1Y: cout << "定期一年"; break;case FIXED_3Y: cout << "定期三年"; break;case FIXED_5Y: cout << "定期五年"; break;}cout << endl;cout << "余额: " << fixed << setprecision(2) << balance << endl;cout << "开户时间: " << ctime(&openTime);cout << "利率: " << interestRate * 100 << "%" << endl;cout << "利息: " << fixed << setprecision(2) << interest << endl;
}

};

// 账户管理系统类
class AccountManager {
private:
vector accounts;
double savingRate; // 活期利率
double fixed1YRate; // 一年定期利率
double fixed3YRate; // 三年定期利率
double fixed5YRate; // 五年定期利率

public:
AccountManager()
: savingRate(0.003), fixed1YRate(0.015), fixed3YRate(0.0275), fixed5YRate(0.03) {}

// 开户
bool openAccount(string id, AccountType type) {// 检查账户是否已存在for (const auto& acc : accounts) {if (acc.getAccountId() == id) {cout << "账户已存在!" << endl;return false;}}double rate;switch (type) {case SAVING: rate = savingRate; break;case FIXED_1Y: rate = fixed1YRate; break;case FIXED_3Y: rate = fixed3YRate; break;case FIXED_5Y: rate = fixed5YRate; break;default: rate = 0;}accounts.push_back(Account(id, type, rate));cout << "开户成功!" << endl;return true;
}// 销户
bool closeAccount(string id) {for (auto it = accounts.begin(); it != accounts.end(); ++it) {if (it->getAccountId() == id) {it->calculateInterest();cout << "销户信息:" << endl;it->display();accounts.erase(it);cout << "销户成功!" << endl;return true;}}cout << "账户不存在!" << endl;return false;
}// 汇总
void summary() const {double totalBalance = 0;double totalInterest = 0;cout << "账户汇总信息:" << endl;// 这里需要通过非const引用来调用calculateInterest,因此使用mutable迭代for (auto& acc : const_cast<vector<Account>&>(accounts)) {acc.calculateInterest();acc.display();cout << "------------------------" << endl;totalBalance += acc.getBalance();totalInterest += acc.getInterest();}cout << "总余额: " << fixed << setprecision(2) << totalBalance << endl;cout << "总利息: " << fixed << setprecision(2) << totalInterest << endl;
}// 查询
void query(string id) const {for (auto& acc : const_cast<vector<Account>&>(accounts)) {if (acc.getAccountId() == id) {acc.calculateInterest();acc.display();return;}}cout << "账户不存在!" << endl;
}// 存款
bool deposit(string id, double amount) {for (auto& acc : accounts) {if (acc.getAccountId() == id) {acc.deposit(amount);cout << "存款成功!当前余额:" << fixed << setprecision(2) << acc.getBalance() << endl;return true;}}cout << "账户不存在!" << endl;return false;
}// 取款
bool withdraw(string id, double amount) {for (auto& acc : accounts) {if (acc.getAccountId() == id) {if (acc.withdraw(amount)) {cout << "取款成功!当前余额:" << fixed << setprecision(2) << acc.getBalance() << endl;return true;} else {cout << "余额不足!" << endl;return false;}}}cout << "账户不存在!" << endl;return false;
}// 结息
void calculateInterest() {for (auto& acc : accounts) {acc.calculateInterest();}cout << "结息完成!" << endl;
}// 文件导入
bool importFromFile(const string& filename) {ifstream file(filename);if (!file.is_open()) {cout << "无法打开文件!" << endl;return false;}accounts.clear();int count;file >> count;for (int i = 0; i < count; ++i) {string id;int type;double balance, rate;time_t openTime;file >> id >> type >> balance >> openTime >> rate;Account acc(id, static_cast<AccountType>(type), rate);// 导入时需要设置余额(原代码未处理)for (int j = 0; j < balance; ++j) { // 临时模拟存款(实际应添加setBalance接口)acc.deposit(1);}accounts.push_back(acc);}file.close();cout << "导入成功!" << endl;return true;
}// 文件导出
bool exportToFile(const string& filename) const {ofstream file(filename);if (!file.is_open()) {cout << "无法打开文件!" << endl;return false;}file << accounts.size() << endl;for (const auto& acc : accounts) {file << acc.getAccountId() << " "<< acc.getType() << " "<< acc.getBalance() << " "<< acc.getOpenTime() << " "<< acc.getInterestRate() << endl;}file.close();cout << "导出成功!" << endl;return true;
}// 修改利率
void changeInterestRate() {cout << "当前利率:" << endl;cout << "活期:" << savingRate * 100 << "%" << endl;cout << "一年定期:" << fixed1YRate * 100 << "%" << endl;cout << "三年定期:" << fixed3YRate * 100 << "%" << endl;cout << "五年定期:" << fixed5YRate * 100 << "%" << endl;cout << "选择要修改的利率类型:" << endl;cout << "1. 活期" << endl;cout << "2. 一年定期" << endl;cout << "3. 三年定期" << endl;cout << "4. 五年定期" << endl;int choice;cin >> choice;double newRate;cout << "输入新的利率(例如 0.01 表示 1%):";cin >> newRate;switch (choice) {case 1:savingRate = newRate;for (auto& acc : accounts) {if (acc.getType() == SAVING) {acc.setInterestRate(newRate);}}break;case 2:fixed1YRate = newRate;for (auto& acc : accounts) {if (acc.getType() == FIXED_1Y) {acc.setInterestRate(newRate);}}break;case 3:fixed3YRate = newRate;for (auto& acc : accounts) {if (acc.getType() == FIXED_3Y) {acc.setInterestRate(newRate);}}break;case 4:fixed5YRate = newRate;for (auto& acc : accounts) {if (acc.getType() == FIXED_5Y) {acc.setInterestRate(newRate);}}break;default:cout << "选择无效!" << endl;return;}cout << "利率修改成功!" << endl;
}

};

int main() {
AccountManager manager;
int choice;
string id;
double amount;
string filename;

while (true) {cout << "\n个人银行账户管理系统:" << endl;cout << "1 开户" << endl;cout << "2 销户" << endl;cout << "3 汇总" << endl;cout << "4 查询" << endl;cout << "5 存款" << endl;cout << "6 取款" << endl;cout << "7 结息" << endl;cout << "8 修改利率" << endl;cout << "9 文件导入" << endl;cout << "10 文件导出" << endl;cout << "11 退出" << endl;cout << "请选择:";cin >> choice;switch (choice) {case 1: {cout << "输入账户ID:";cin >> id;cout << "选择账户类型(1:活期,2:一年定期,3:三年定期,4:五年定期):";int typeChoice;cin >> typeChoice;AccountType type;switch (typeChoice) {case 1: type = SAVING; break;case 2: type = FIXED_1Y; break;case 3: type = FIXED_3Y; break;case 4: type = FIXED_5Y; break;default: type = SAVING;}manager.openAccount(id, type);break;}case 2:cout << "输入要销户的账户ID:";cin >> id;manager.closeAccount(id);break;case 3:manager.summary();break;case 4:cout << "输入要查询的账户ID:";cin >> id;manager.query(id);break;case 5:cout << "输入账户ID:";cin >> id;cout << "输入存款金额:";cin >> amount;manager.deposit(id, amount);break;case 6:cout << "输入账户ID:";cin >> id;cout << "输入取款金额:";cin >> amount;manager.withdraw(id, amount);break;case 7:manager.calculateInterest();break;case 8:manager.changeInterestRate();break;case 9:cout << "输入导入文件名:";cin >> filename;manager.importFromFile(filename);break;case 10:cout << "输入导出文件名:";cin >> filename;manager.exportToFile(filename);break;case 11:cout << "谢谢使用,再见!" << endl;return 0;default:cout << "选择无效,请重新选择!" << endl;}
}return 0;

}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/950343.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

10.28总结

import java.util.Scanner; /**班级:[请填写班级]学号:[请填写学号]姓名:[请填写姓名]功能:在线投稿系统的管理类,实现核心业务逻辑 */ public class Main { // 用数组存储稿件,最多存储100条记录(可扩展) pri…

不等式3

Problem 已知数列 $ { a_n } $ 的前 $ n $ 项和为 $ S_n $,满足 $ S_{n+1} = 2a_n^ { \hspace{0.2cm} 2} - 1 + S_n (n\in N^{*})$ 。 (1)略。 (2)当 $ a_1 \in [ \frac{ \sqrt{2} } {2} ,1 ]$ 时,求 $ 4a_1-a_3 …

退役划水十二 用进废退

我完蛋了用进废退 四月桃红,五黄六月,七月流火,八月金桂,摆烂甚久,思前想后,还是决定写些文字,作为自己存活过的凭证。其实直接原因是:和:我应该没有红温,只是一分悲戚两分无语三分凉薄四分叹息。悲戚于自己…

新学期每日总结(第16天)

今日 相较昨日 下载数据库

Gin笔记二之gin.Engine和路由设置

本文首发于公众号:Hunter后端 原文链接:Gin笔记二之gin.Engine和路由设置这一篇笔记主要介绍 gin.Engine,设置路由等操作,以下是本篇笔记目录:gin.Default() 和 gin.New() HTTP 方法 路由分组与中间件1、gin.Defa…

阅读笔记一:以“刻意练习”筑牢成长根基 - 20243867孙堃2405

《程序员的修炼之路:从小工到专家》并非一本罗列技术知识点的工具书,而是一部指引开发者突破职业瓶颈的思维指南。书中最触动我的,是对“成长本质”的深刻剖析——从“小工”到“专家”,从来不是资历的自然累积,而…

flv 转化成 mp4 文件

ffmpeg -i "原视频.flv" -c copy "新视频.mp4"因为你用了 -c copy,意思是:不重新压缩/重编码(既不压音频也不压视频) 只是直接把原始音视频流复制进一个新的容器格式(从 .flv 换到 .mp4) 所…

牛客刷题-Day18

模拟、枚举与贪心 https://ac.nowcoder.com/acm/contest/20960?from=acdiscuss牛客刷题-Day18 今日刷题:\(1001-1010\) 1001 模拟 例1-字符串展开解题思路 模拟,注意细节就可以。 C++ 代码 #include <bits/stdc…

网络连接的核心——TCP/IP体系结构

网络连接的核心——TCP/IP体系结构一、网络连接的核心 前言:局域网作为互联网的核心,但是不同的局域网之间采用的是不同的技术(传输介质、介质控制方法、程真方法等)通过利用IP协议将这些网络从用户层面看起来是一…

C++练习-函数

double dist( double x1, double y1, double x2, double y2 ){double Dx,Dy;Dx=fabs(x1-x2);Dy=fabs(y1-y2);double dis;dis=sqrt(pow(Dx,2)+pow(Dy,2));return dis; }int sign( int x ){int res;if(x>0){res=1;}el…

使用 Java 解析验证码:结合 Tesseract OCR 进行文本识别

更多内容访问ttocr.com或联系1436423940环境准备 1.1 安装 Java如果尚未安装 Java,可前往 Oracle 官方网站 或 Adoptium 下载最新版本的 JDK。安装完成后,运行以下命令检查版本: java -version 1.2 安装 Tesseract …

代码大全2阅读笔记(2)

一、开篇:别让 “基础模块” 拖垮整体质量 读《代码大全 2》到编码实践章节时,最深刻的感受是:高质量代码不是靠 “高深技巧” 堆出来的,而是把 “变量、函数、控制结构” 这些基础模块做到极致。很多时候我们写的…

使用 Swift 进行验证码识别:集成 Tesseract OCR

环境准备 1.1 安装 Tesseract OCR 更多内容访问ttocr.com或联系1436423940 在 macOS 上可以使用 Homebrew 进行安装:brew install tesseract 安装完成后,检查 Tesseract 是否安装成功: tesseract --version 1.2 创建…

使用 Rust 进行验证码识别:结合 Tesseract OCR 进行文本解析

环境准备 1.1 安装 Rust如果尚未安装 Rust,可使用 Rust 官方安装工具 :更多内容访问ttocr.com或联系1436423940 curl --proto =https --tlsv1.2 -sSf https://sh.rustup.rs | sh 安装完成后,检查 Rust 版本: rustc…

软件技术基本第二次作业

这个作业属于哪个课程 https://edu.cnblogs.com/campus/zjlg/25rjjc这个作业的目标 实现文本计数统计姓名-学号 冯艳-2023329301103码云仓库地址:https://gitee.com/f2196470648/word-counter.git

Day7CSS的引入方式与选择器

<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0">…

ZR-J 2025-10-29 比赛总结

比赛链接 分数:\(100 + 100 + 0 + 0 = 200\) 永康喵喵又没有翻车! 有了前几次翻车的教训,我形成了先写注释(对于难题)\(\rightarrow\) 仔细写题 \(\rightarrow\) 静态检查 \(\rightarrow\) 动态检查 \(\rightarro…

newDay17

1.背了背单词,把u校园作业弄了,其他的没啥 2.明天看看Java那个期中考试怎么弄 3.最近有点摆

AI元人文架构:从价值计算到智能主体的演进路径

AI元人文架构:从价值计算到智能主体的演进路径 摘要: 本文系统阐述了基于Free Transformer潜变量Z的AI元人文架构,通过构建三值纠缠模型与语境主权机制,建立多层次价值博弈体系。研究提出价值递归架构和情感维度建…

三元组 - MKT

三元组 [62] B. Jiang, Y. Zhu, and M. Liu, “A triangle feature based map-tomap matching and loop closure for 2d graph slam,” in Proc. of the International Conference on Robotics and Biomimetics (ROBIO…