📄 123.txt
字号:
/***********************个人财政支出管理*************************
程序功能简介
个人财政支出管理程序,完成收入,支出,盈余的记录和管理。
课程设计要求
(1) 增加函数,完成财政账目的管理功能。
(2) 将所有的函数与相应的数据封装到类中,并改写主程序,使程序简化。
(3) 可自行增加程序的功能。
(4) 设计测试主程序,在主程序中完成测试。
课程设计说明
(1) SetGoal()函数账目中有问题,改正。
(2) 可将整修记录装入一个字符串,在两条记录间用特殊符号隔开。
(3) 查找相应记录时,可采用逐个字节比较的方法。
(4) 评定难易级别:B级。
*****************************************************************/
////////// 刘伟南 学号:03303997 班级:03065501 //////////
# define MIN //调试模式时保留
# define DE1 //调试模式时保留
# define DE2 //调试模式时保留
# define WI1 //调试模式时保留
# define WI2 //调试模式时保留
# define SG //调试模式时保留
# define VT //调试模式时保留
# define SZ //调试模式时保留
#include <iostream.h>
#include <fstream.h>
#include <conio.h>
#include <iomanip.h>
#include <stdlib.h>
class Manager //定义类Manager
{
private:
double dAmt; //收入数目
char ans; //存放键盘字符的ASCII码
double num; //存入输入的数据
double wAmt; //支出数目
double setAmt; //制定目标
double gAmt; //取目标金额
double balance; //收支金额
double newbalance; //与目标所差金额
public: //声名我所有的函数
void Deposit(); //收入函数
void Withdraw(); //支出函数
void ViewTotal(); //查看帐目
void SetGoal(); //制定目标
void SetZero(); //记录置零
};
Manager main() //主函数
{
Manager mm; //创建对象
char select;
cprintf("======个人财政支出管理====== ");//显示标题
# ifdef MIN
cout<<"\n\n\n##########################调 试 模 式#########################"<<endl;
#endif
cout<<"\n\n\t<1> 收入模式"<<endl; //选择<1>进入收入模式
cout<<"\n\t<2> 支出模式"<<endl; //选择<2>进入支出模式
cout<<"\n\t<3> 查看帐目"<<endl; //选择<3>进入查看帐目模式
cout<<"\n\t<4> 制定目标"<<endl; //选择<4>进入制定目标模式
cout<<"\n\t<5> 记录置零"<<endl; //选择<5>记录置零
cout<<"\n\t<6> 退出系统"<<endl; //选择<6>退出
cout<<"\n\t<0> 帮 助 "<<endl;
cout<<"\n\n\t请输入你的选择: ";
cin>>select;
if(select == '1'){mm.Deposit();}else{
if(select == '2'){mm.Withdraw();}else{
if(select == '3'){mm.ViewTotal();}else{
if(select == '4'){mm.SetGoal();}else{
if(select == '5'){mm.SetZero();}else{
if(select == '0'){
cout<<"\n\n\n\n程序功能简介:个人财政支出管理程序,完成收入,支出,盈余的记录和管理。主页面下选择数字键进入!"<<'\n'<<'\n';
cout<<" 制做人:刘伟南";
cout<<endl<<endl<<endl;
getch();
main(); //回主函数
}else{
if(select == '6')
{exit(1);} //退出
else main(); //回主函数
}}}}}}
}
void Manager::Deposit(){//在程序中记录收入数目的函数
mm1:dAmt = 0;
num = 0;
double a=0,c=0;
ifstream get("Money.txt"); //打开存贮数据文件
# ifdef DE1
cout<<"\n#########################打开文件money.txt读取数据#########################"<<endl;
#endif
get>>a>>num>>c; //取得存档文件中的三个数据
get.close();
cout<<endl<<endl;
cprintf("**************************收入************************** ");
cout<<"\n\n\t请输入收入金额: $";
cin>>dAmt;
//检查输入的数据是否为错误的数据或是零,然后继续
if(dAmt <= 0){ //如果数据小于等于零
cout<<"\n\n\n\n\n"<<endl;
cprintf(" !!!!!!!!!!错误的数据!!!!!!!!!! ..");
getch();
main();
}else{
cout<<"\n\n\t数据输入 <"<<dAmt<<">."<<endl;
cout<<"\n\t 确认你输入的数据<y/n>: ";
cin>>ans;
if(ans == 'y'){
dAmt = dAmt + num; //把新数据加到原有数据上
ofstream save("Money.txt");
# ifdef DE2
cout<<"\n#########################打开文件money.txt,保存数据#########################"<<endl;
#endif
save<<a<<'\n'<<dAmt<<'\n'<<c;
save.close();
cout<<"\n\n\n\n\n"<<endl;
cprintf(" 你的收入数据成功输入...");
cout<<"\n\t 继续输入收入金额<y/n>: ";
cin>>ans;
if(ans == 'y')goto mm1; //继续输入数据
else
{cout<<endl<<endl<<endl;
main();} //回主函数
getch();
cout<<endl<<endl<<endl;
main(); //回主函数
}
else{ //中止输入数据
main(); //回主函数
}
main(); //回主函数
}
}
void Manager::Withdraw(){ //在程序中记录支出数目的函数
mm2:wAmt = 0;
num = 0;
double a=0,b=0;
ifstream get("Money.txt"); //打开存贮数据文件
# ifdef WI1
cout<<"\n#########################打开文件money.txt,读取数据#########################"<<endl;
#endif
get>>a>>b>>num; //取得存档文件中的三个数据
get.close();
cout<<endl<<endl;
cprintf("**************************支出************************** ");
cout<<"\n\n\t请输入支出金额: $";
cin>>wAmt;
if(wAmt <= 0){ //检查输入的数据是否为错误的数据或是零,然后继续
cout<<"\n\n\n\n\n"<<endl;
cprintf(" !!!!!!!!!!错误的数据!!!!!!!!!! ..");
getch();
main();
}else{
cout<<"\n\n\t数据输入 <"<<wAmt<<">."<<endl;
cout<<"\n\t 确认你输入的数据<y/n>: ";
cin>>ans;
if(ans == 'y'){
wAmt = wAmt + num; //把新数据加到原有数据上
ofstream save("Money.txt");
# ifdef WI2
cout<<"\n#########################打开文件money.txt,保存数据#########################"<<endl;
#endif
save<<a<<'\n'<<b<<'\n'<<wAmt;
save.close();
cout<<"\n\n\n\n\n"<<endl;
cprintf(" 你的支出数据成功输入...");
cout<<"\n\t 继续输入支出金额<y/n>: ";
cin>>ans;
if(ans == 'y')goto mm2; //继续输入数据
else
{cout<<endl<<endl<<endl;
main();} //回主函数
getch();
cout<<endl<<endl<<endl;
main();
}
else{ //中止输入数据
main(); //回主函数
}
main(); //回主函数
}
}
void Manager::SetGoal(){ //在程序中制定目标金额的函数
setAmt = 0;
double b=0,c=0,temp=0;
cout<<endl<<endl;
cprintf("**************************制定目标************************** ");
cout<<"\n\n\t制定目标金额: ";
cin>>setAmt; //保存新数据到文件中
ifstream get("Money.txt"); //打开存贮数据文件
get>>temp>>b>>c; //取得存档文件中的三个数据
get.close();
# ifdef SG
cout<<"\n#########################打开文件money.txt,保存数据#########################"<<endl;
#endif
ofstream save("Money.txt");
save<<setAmt<<'\n'<<b<<'\n'<<c;
save.close();
cout<<"\n\n\n\n\n"<<endl;
cprintf(" 你的目标金额已建立...");
getch();
cout<<endl<<endl<<endl;
main();
}
void Manager::ViewTotal(){ //查看帐目函数
dAmt = 0; //收入数目
wAmt = 0; //支出数目
gAmt = 0; //取目标金额
balance = 0; //收支金额
newbalance = 0;//与目标所差金额
# ifdef VT
cout<<"\n#########################打开文件money.txt,读取数据#########################"<<endl;
#endif
ifstream get("Money.txt"); //打开存贮数据文件
get>>gAmt>>dAmt>>wAmt; //取得存档文件中的三个数据
get.close();
balance = dAmt - wAmt; //收入减去支出取得收支平衡数据
cout<<endl<<endl;
cprintf("**************************查看帐目************************** ");
cout<<"\n\n"<<endl;
cprintf(" 收支总数");
cout<<""<<endl;
cprintf(" =============");
cout<<"\n\n"<<endl;
cprintf(" 收入总金额 支出总金额 收支总金额 ");
cout<<"\n"<<endl;
cout<<setw(15)<<dAmt<<setw(25)<<wAmt<<setw(20)<<balance<<endl;//使每两个数据按一定的间隔输出
newbalance = gAmt - balance;
cout<<"\n\n\n"<<endl;
cprintf(" 收支平衡");
cout<<""<<endl;
cprintf(" =============");
cout<<"\n\n"<<endl;
cprintf(" 目标金额 收支平衡金额 相差金额 ");
cout<<"\n"<<endl;
cout<<setw(15)<<gAmt<<setw(25)<<balance<<setw(23)<<newbalance<<endl;
getch();
cout<<endl<<endl<<endl;
main(); //回到主函数
}
void Manager::SetZero(){ //记录置零函数
cout<<"\n\n\n\n 你确定要将记录置零<y/n>: ";
cin>>ans; //确认是否要将记录置零
if(ans == 'y'){
dAmt = 0; //先初始数据为零
wAmt = 0;
setAmt = 0;
# ifdef SZ
cout<<"\n#########################打开文件money.txt,保存数据#########################"<<endl;
#endif
ofstream save("Money.txt"); //打开存放数据的文件并将收入数据置零
save<<setAmt<<'\n'<<dAmt<<'\n'<<wAmt;
save.close();
cout<<endl<<endl<<endl;
main();} //回主函数
else
{cout<<endl<<endl<<endl;
main();} //回主函数
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -