请帮我用c++写一个简单的财务报表系统
当然可以!下面是一个简单的财务报表系统的C++代码示例:
#include <iostream>
#include <vector>
using namespace std;
struct FinancialStatement {
string companyName;
int year;
double revenue;
double expenses;
double profit;
};
void addStatement(vector<FinancialStatement>& statements) {
FinancialStatement statement;
cout << "公司名称: ";
cin >> statement.companyName;
cout << "年份: ";
cin >> statement.year;
cout << "收入: ";
cin >> statement.revenue;
cout << "支出: ";
cin >> statement.expenses;
statement.profit = statement.revenue - statement.expenses;
statements.push_back(statement);
cout << "财务报表已添加!" << endl;
}
void printStatement(const FinancialStatement& statement) {
cout << "公司名称: " << statement.companyName << endl;
cout << "年份: " << statement.year << endl;
cout << "收入: " << statement.revenue << endl;
cout << "支出: " << statement.expenses << endl;
cout << "利润: " << statement.profit << endl;
}
void printAllStatements(const vector<FinancialStatement>& statements) {
if (statements.empty()) {
cout << "没有财务报表可打印!" << endl;
} else {
for (const FinancialStatement& statement : statements) {
printStatement(statement);
cout << endl;
}
}
}
int main() {
vector<FinancialStatement> statements;
int choice;
do {
cout << "1. 添加财务报表" << endl;
cout << "2. 打印所有财务报表" << endl;
cout << "3. 退出" << endl;
cout << "请选择操作: ";
cin >> choice;
switch (choice) {
case 1:
addStatement(statements);
break;
case 2:
printAllStatements(statements);
break;
case 3:
cout << "退出财务报表系统!" << endl;
break;
default:
cout << "无效的选择!" << endl;
break;
}
cout << endl;
} while (choice != 3);
return 0;
}
这个简单的财务报表系统包括以下功能:
- 添加财务报表:用户可以输入公司名称、年份、收入和支出信息,并计算利润。
- 打印所有财务报表:将所有财务报表的信息打印出来。
- 退出:退出财务报表系统。
你可以根据实际需求进行修改和扩展。希望对你有帮助
原文地址: https://www.cveoy.top/t/topic/h5SF 著作权归作者所有。请勿转载和采集!