/*头文件*/
# include <iostream>
using namespace std;
/*定义数据的结构*/
typedef struct day
{
int in;
int out;
}day;
typedef struct month
{
day d[31];
}month;
typedef struct year
{
month m[12];
}year;
typedef struct record
{
year y[10];
}record;
/*函数声明*/
void menu();
void record_init(record &R);
void income_sustain(record &R);
void income(record R);
void inquriy_year(record R);
void inquriy_mouth(record R);
void inquriy_day(record R);
void statistic(record R);
void statistic_day(record R);
void statistic_mouth(record R);
void statistic_year(record R);
/*主函数*/
void main()
{
char choice,choice_0;
record rec;
record_init(rec);
do
{
menu();
cin>>choice;
switch(choice)
{
case '1':income_sustain(rec);break;
case '2':income(rec);break;
case '3':statistic(rec);break;
case '4':break;
}
cout<<"确认是否继续个人理财管理系统[y/n] ";
cin>>choice_0;
if(choice_0=='n')
break;
}while(choice_0=='y');
}
/*数据初始化函数*/
void record_init(record &R)
{
int i,j,k;
for(i=0;i<10;i=i+1)
for(j=0;j<12;j=j+1)
for(k=0;k<31;k=k+1)
{
R.y[i].m[j].d[k].in=0;
R.y[i].m[j].d[k].out=0;
}
}
/*输出菜单函数*/
void menu()
{
cout<<" 个人理财管理系统 "<<endl;
cout<<" **********************请选择操作**********************"<<endl;
cout<<" 1资金信息维护"<<endl;
cout<<" 2资金信息查询"<<endl;
cout<<" 1按日期查询 2按月份查询 3按年份查询"<<endl;
cout<<" 3资金信息统计"<<endl;
cout<<" 1按日期统计 2按月份统计 3按年份统计"<<endl;
cout<<" 4退出系统"<<endl;
cout<<" ******************************************************"<<endl;
cout<<"请输入您的选择[1~4] ";
}
/*资金信息维护函数*/
void income_sustain(record &R)
{
int a,b,c,n,j;
cout<<"\n\t新建记录->\n\t请输入:\n\t新记录的数目:";
cin>>j;
cout<<"所新建的日期(年[2000~2010]月[1~12]日[1~31]):"<<endl;
cout<<"\t新输入当日的收入情况:"<<endl;
for(n=1;n<=j;n=n+1)
{
cout<<" 年";
cout<<" 月";
cout<<" 日: ";
cin>>a>>b>>c;
cout<<"\t收入:";
cin>>R.y[a-2000].m[b-1].d[c-1].in;
}
cout<<"\t新输入当日的支出情况:"<<endl;
for(n=1;n<=j;n=n+1)
{
cout<<" 年";
cout<<" 月";
cout<<" 日: ";
cin>>a>>b>>c;
cout<<"\t支出:";
cin>>R.y[a-2000].m[b-1].d[c-1].out;
}
}
/*资金信息查询函数*/
void income(record R)
{
char choice,choice_0;
do
{
cout<<" 1按日期查询 2按月份查询 3按年份查询"<<endl;
cout<<"请输入您的选择[1~3] ";
cin>>choice;
switch(choice)
{
case '1':inquriy_day(R);break;
case '2':inquriy_mouth(R);break;
case '3':inquriy_year(R);break;
}
cout<<"确认是否继续资金信息查询[y/n] ";
cin>>choice_0;
if(choice_0=='n')
break;
}while(choice_0=='y');
}
/*按日期查询*/
void inquriy_day(record R)
{
int a,b,c;
cout<<"\n\t查询记录->按日查询->\n\t请输入所查询的日期(年[2000~2010]月[1~12]日[1~31]):";
cin>>a>>b>>c;
if(a>=2000&&a<=2010&&b>=1&&b<=12&&c>=1&&c<=31)
{
cout<<"\t "<<a<<"年"<<b<<"月"<<c<<"日 收入:"<<R.y[a-2000].m[b-1].d[c-1].in<<" 支出:"<<R.y[a-2000].m[b-1].d[c-1].out<<endl;
}
else cout<<"\t输入有误,请重新输入!";
}
/*按月份查询*/
void inquriy_mouth(record R)
{
int a,b,c;
cout<<"\n\t查询记录->按月查询->\n\t请输入所查询的年份、月份(年[2000~2010]月[1~12]):";
cin>>a>>b;
if(a>=2000&&a<=2010&&b>=1&&b<=12)
{
for(c=1;c<=31;c=c+1)
{
cout<<c<<"日 收入:"<<R.y[a-2000].m[b-1].d[c-1].in<<" 支出:"<<R.y[a-2000].m[b-1].d[c-1].out<<"\n";
}
cout<<endl;
}
else cout<<"\t输入有误,请重新输入!";
}
/*按年份查询*/
void inquriy_year(record R)
{
int a,b,c,mouth_in,mouth_out;
cout<<"\n\t查询记录->按年查询->\n\t请输入所查询的年份(年[2000~2010]):"<<endl;
cin>>a;
cout<<"年"<<endl;
if(a>=2000&&a<=2010)
{
for(b=1;b<=12;b=b+1)
{
for(c=1;c<=31;c=c+1)
{
mouth_in=0;
mouth_out=0;
mouth_in=mouth_in+R.y[a-2000].m[b-1].d[c-1].in;
mouth_out=mouth_out+R.y[a-2000].m[b-1].d[c-1].out;
}
cout<<b<<"月 收入:"<<mouth_in<<" 支出:"<<mouth_out<<endl;
}
}
else cout<<"\t输入有误,请重新输入!";
}
/*资金信息统计函数*/
void statistic(record R)
{
char choice,choice_0;
do
{
cout<<" 1按日期统计 2按月份统计 3按年份统计"<<endl;
cout<<"请输入您的选择[1~3] ";
cin>>choice;
switch(choice)
{
case '1':statistic_day(R);break;
case '2':statistic_mouth(R);break;
case '3':statistic_year(R);break;
}
cout<<"确认是否继续资金信息统计[y/n] ";
cin>>choice_0;
if(choice_0=='n')
break;
}while(choice_0=='y');
}
/*按日期统计函数*/
void statistic_day(record R)
{
int a,b,c;
int in_out;
cout<<"\n\t统计记录->按日统计->\n\t请输入所统计的日期(年[2000~2010]月[1~12]日[1~31]):";
cin>>a>>b>>c;
if(a>=2000&&a<=2010&&b>=1&&b<=12&&c>=1&&c<=31)
{
in_out=R.y[a-2000].m[b-1].d[c-1].in-R.y[a-2000].m[b-1].d[c-1].out;
cout<<"\t "<<a<<"年"<<b<<"月"<<c<<"日 收入:"<<R.y[a-2000].m[b-1].d[c-1].in<<" 支出:"<<R.y[a-2000].m[b-1].d[c-1].out<<" 总计: "<<in_out<<endl;
}
else cout<<"\t输入有误,请重新输入!";
}
/*按月份统计函数*/
void statistic_mouth(record R)
{
int a,b,c,in,out,in_out;
in=0;
out=0;
cout<<"\n\t统计记录->按月统计->\n\t请输入所统计的月份(年[2000~2010]月[1~12]):";
cin>>a>>b;
if(a>=2000&&a<=2010&&b>=1&&b<=12)
{
for(c=1;c<=31;c=c+1)
{
in=in+R.y[a-2000].m[b-1].d[c-1].in;
out=out+R.y[a-2000].m[b-1].d[c-1].out;
}
in_out=in-out;
cout<<a<<"月 收入:"<<in<<" 支出:"<<out<<" 总计: "<<in_out<<endl;
}
else cout<<"\t输入有误,请重新输入!";
}
/*按年份统计函数*/
void statistic_year(record R)
{
int a,b,c,year_in,year_out,in_out;
year_in=0;
year_out=0;
cout<<"\n\t统计记录->按年统计->\n\t请输入所统计的年份(年[2000~2010]):"<<endl;
cin>>a;
if(a>=2000&&a<=2010)
{
cout<<"\t "<<a<<"年"<<endl;
for(b=1;b<=12;b=b+1)
for(c=1;c<=31;c=c+1)
{
year_in=year_in+R.y[a-2000].m[b-1].d[c-1].in;
year_out=year_out+R.y[a-2000].m[b-1].d[c-1].out;
}
in_out=year_in-year_out;
cout<<a<<"年 收入:"<<year_in<<" 支出:"<<year_out<<" 总计: "<<in_out<<endl;
}
else cout<<"\t输入有误,请重新输入!";
}