求。c++编写家庭财务管理系统。。
- 提问者网友:傲气稳全场
- 2021-02-01 14:23
亲,用类实现奥。。我实在是没有财富值。谢谢了。。急求。。
- 二级知识专家网友:走,耍流氓去
- 2021-02-01 15:20
|一| 可代做 +Q
- 1楼网友:茫然不知崩溃
- 2021-02-01 16:16
#include <iostream> #include <iomanip> #include <fstream> #include <cstring> #include "hsk2007.h" void main() { int a,b,c; //时间项 float in,out,all; //收入、支出、共计 char x,y,z; //功能选择字符 struct record r; //日记录单元 do { cout<<"\n\n\t____________________________________________________\n\n\n\t 家庭财务管理2007\n\n\t____________________________________________________\n\n\t <b>新建记录 <l>查询记录 <q>退出\n\n\t请选择(输入选项前对应的字母):"; cin>>x; strupr(&x); if(x=='b') { cout<<"\n\t新建记录->\n\t请输入:\n\t新记录的日期(年 月 日):"; //新建记录 cin>>a>>b>>c; if(a>=1980&&a<=2100&&b>=1&&b<=12&&c>=1&&c<=31) { cout<<"\t新记录当日的收入:"; cin>>in; cout<<"\t新记录当日的支出:"; cin>>out; w(a,b,c,in,out); cout<<"\t新记录已建立!\n"; } else cout<<"\t输入有误,请重新输入!"; } if(x=='l') do { cout<<"\n\n\t查询记录->\n\t查询方式: <y>年 <s>季度 <m>月 <d>日 <q>退出\n\t请选择(输入选项前对应的字母):"; //查询记录 cin>>y; strupr(&y); if(y=='y') { cout<<"\n\t查询记录->按年查询->\n\t请输入所查询的年份:"; //按年查询 cin>>a; if(a>=1980&&a<=2100) { do { cout<<"\t是否查询日记录(y/n):"; cin>>z; strupr(&z); if(z=='y'||z=='n') year(a,z); else cout<<"\t输入有误,请重新选择!\n"; } while(z!='y'&&z!='n'); } else cout<<"\t输入有误,请重新输入!"; } if(y=='s') { cout<<"\n\t查询记录->按季度查询->\n\t请输入所查询的年份、季度:"; //按季度查询 cin>>a>>b; if(a>=1980&&a<=2100&&b>=1&&b<=4) { do { cout<<"\t是否查询日记录(y/n):"; cin>>z; strupr(&z); if(z=='y'||z=='n') season(a,b,z); else cout<<"\t输入有误,请重新选择!\n"; } while(z!='y'&&z!='n'); } else cout<<"\t输入有误,请重新输入!"; } if(y=='m') { cout<<"\n\t查询记录->按月查询->\n\t请输入所查询的年份、月份:"; //按月查询 cin>>a>>b; if(a>=1980&&a<=2100&&b>=1&&b<=12) { do { cout<<"\t是否查询日记录(y/n):"; cin>>z; strupr(&z); if(z=='y'||z=='n') month(a,b,z,&in,&out); else cout<<"\t输入有误,请重新选择!\n"; } while(z!='y'&&z!='n'); } else cout<<"\t输入有误,请重新输入!"; } if(y=='d') { cout<<"\n\t查询记录->按日查询->\n\t请输入所查询的日期:"; //按日查询 cin>>a>>b>>c; if(a>=1980&&a<=2100&&b>=1&&b<=12) { day(a,b,c,&r); all=r.w[0]-r.w[1]; cout<<"\t "<<r.t[0]<<"年"<<r.t[1]<<"月"<<r.t[2]<<"日 收入:"<<r.w[0]<<" 支出:"<<r.w[1]<<" 共计:"<<all<<endl; } else cout<<"\t输入有误,请重新输入!"; } if(y!='y'&&y!='s'&&y!='m'&&y!='d'&&y!='q') cout<<"\t输入有误,请重新选择!"; } while(y!='q'); if(x!='b'&&x!='l'&&x!='q') cout<<"\t输入有误,请重新选择!"; } while(x!='q'); }
using namespace std; //命名空间 struct record //记录 { int t[3]; //年、月、日 float w[2]; }; //收入、支出
void w(int year,int month,int day,float in=0.0,float out=0.0) //写日记录 { struct record r; ofstream file; r.t[0]=year; r.t[1]=month; r.t[2]=day; r.w[0]=in; r.w[1]=out; file.open("家庭收支记录.txt",ios_base::app); file.write((char *)&r,sizeof(struct record)); file.close(); }
void day(int y,int m,int d,struct record *p) //读日记录 { ifstream file; file.open("家庭收支记录.txt",ios_base::in); file.seekg(0,ios::beg); do file.read((char *)p,sizeof(struct record)); while(!file.eof()&&(p->t[0]<y||p->t[0]==y&&p->t[1]<m||p->t[0]==y&&p->t[1]==m&&p->t[2]<d)); if(p->t[0]!=y||p->t[1]!=m||p->t[2]!=d) { p->t[0]=y; p->t[1]=m; p->t[2]=d; p->w[0]=0.0; p->w[1]=0.0; } file.close(); }
void month(int y,int m,char z,float *in,float *out) //读月记录 { int d; float min=0.0,mout=0.0,mall; struct record r; for(d=1;d<=31;d++) { day(y,m,d,&r); if(r.w[0]!=0.0||r.w[1]!=0.0) { min=min+r.w[0]; mout=mout+r.w[1]; if(z=='y') cout<<"\t "<<r.t[0]<<"-"<<r.t[1]<<"-"<<r.t[2]<<" 收入:"<<r.w[0]<<" 支出:"<<r.w[1]<<endl; } } mall=min-mout; *in=min; *out=mout; cout<<"\t "<<y<<"年"<<setw(2)<<m<<"月 收入:"<<min<<" 支出:"<<mout<<" 共计:"<<mall<<endl; }
void season(int y,int s,char z) //读季度记录 { int m; float sin=0.0,sout=0.0,sall,in,out; for(m=3*s-2;m<=3*s;m++) { month(y,m,z,&in,&out); sin=sin+in; sout=sout+out; } sall=sin-sout; cout<<"\t "<<y<<"年"<<s<<"季度 收入:"<<sin<<" 支出:"<<sout<<" 共计:"<<sall<<endl; }
void year(int y,char z) //读年记录 { int m; float yin=0.0,yout=0.0,yall,in,out; for(m=1;m<=12;m++) { month(y,m,z,&in,&out); yin=yin+in; yout=yout+out; } yall=yin-yout; cout<<"\t "<<y<<"年 收入:"<<yin<<" 支出:"<<yout<<" 共计:"<<yall<<endl; }