个人财务管理系统C++代码
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
#include
#include
#include
#include
#include
#include
#include
using namespace std;
class Time //时间类
{
int month;
int day;
int year;
public:
void GetTime(int n,int m,int d){year=n,month=m;day=d;}
void CheckTime();
}Time1;
void Time::CheckTime() //时间错误检查
{
if(month>12 ||month<1)
{
MessageBox(NULL,"月份输入错误","错误!",MB_OK);
exit(0);
}
else
{
if(month==1||month==3 ||month==5||month==7||month==8||month==10||month==12)
{
if(day>31 || day<1)
{
MessageBox(NULL,"日期输入错误","错误!",MB_OK);
exit(0);
}
}
else
{
if(month==4||month==6 ||month==9||month==11)
if(day<1||day>30)
{
MessageBox(NULL,"日期输入错误","错误!",MB_OK);
exit(0);
}
}
}
if(month==2)
if(day>29||day<1)
{
MessageBox(NULL,"日期输入错误","错误!",MB_OK);
exit(0);
}
}
typedef class CFinance:public Time
{
public:
int year,month,day;
double Income,Output;
CFinance *next;
}Infor;
void SearchIncomeInfor(Infor *head);
void SearchOutputInfor(Infor *head);
int menu_select();
void SearchDateInfor(Infor *head);
Infor *Inforinitlist() //创建信息空链表
{
Infor *head;
head=(Infor*)malloc(sizeof(Infor));
head->next =NULL;
return head;
}
int menu_select()
{
char *m[6]={"1.录入财务信息","2.浏览财务信息","3.查询财务信息","4.统计财务信息",
"5.保存财务信息","6.退出财务系统"};
char *c;
c=new char[50];
do
{
system("cls");
cout<<"\t\t----------财务管理系统总菜单----------------"<
cout<<"\t\t\t"<
}
while(c[0]<'1'||c[0]>'6'||c[1]);
return(c[0]-'0');
}
void SaveToFile(Infor *head)
{
fstream FInfor("FInfor.dat",ios::out | ios::binary);
if(!FInfor)
{
cout<<"文件打开失败!";
//exit(0);
}
Infor *p;
p=head->next;
while(p!=NULL)
{
FInfor<<"\t年份:"<
p=p->next;
}
// 通常notepad 都会放在C盘下面的Windows 目录下,
FInfor.close();
system("C:/WINDOWS/NOTEPAD FInfor.dat");
}
void InputFinanceInfor(Infor *head)
{
system("cls");
cout<<"\t\t------------------输入财务信息---------------------"<
p3=head;
if(NULL!=p3->next)
{
p3=p3->next;
}
p2=p3;
char input,*in;
in=&input;
do
{
p1=(Infor*)malloc(sizeof(Infor));
cout<<"\t\t\t年份[int]: ";
cin>>p1-
>year;
cout<
cout<
cout<
cout<
p2->next=p1;
p2=p1;
cout<
system("pause");
}while(toupper(input)!='N');
p2->next=NULL;
}
void ListFinanceInfor(Infor *head)
{
Infor *p;
p=head->next;
if(p!=NULL)
{
system("cls");
cout<
{
cout<<"\t\t-------------------------------------------"<
}
}
}
//查询总菜单
void SearchMenu(Infor *head)
{
Infor *p;
p=head->next;
int Ch;
system("cls");
cout<
cin>>Ch;
switch (Ch)
{
case 1:
SearchOutputInfor(p);
system("pause");
break;
case 2:
SearchIncomeInfor(p);
system("pause");
break;
case 3:
SearchDateInfor(p);
system("pause");
break;
case 4:
system("cls");
return;
default:
break;
}
}
void SearchOutputInfor(Infor *head)
{
Infor *p;
p=head;
system("cls");
cout<
{
if(0!=p->Output)
{
cout<
p=p->next;
}
}
void SearchIncomeInfor(Infor *head)
{
Infor *p;
p=head;
system("cls");
cout<
{
if(0!=p->Output)
{
cout<
p=p->next;
}
}
void SearchDateInfor(Infor *head)
{
int x,y,z;
Infor *p;
p=head;
cout<<"请输入日期。"<
Time1.GetTime(x,y,z);
Time1.CheckTime();
cout<
"<
{
if(p->next ==NULL)
{
cout<<"未找到记录!"<
}
p=p->next;
}
system("cls");
cout<
void CalculateMonthInfor(Infor *head)
{
int x,y;
Infor *p;
p=head;
system("cls");
cout<
while(p!=NULL)
{
if(x==p->year&&y==p->month)
{
cout<
p=p->next;
}
}
void CalculateYearInfor (Infor *head)
{
int x;
Infor *p;
p=head;
system("cls");
cout<
while(p!=NULL)
{
if(x==p->year)
{
cout<
p=p->next;
}
}
void CalculateDayInfor (Infor *head)
{
int x,y,z;
Infor *p;
p=head;
system("cls");
cout<
while(p!=NULL)
{
if(x==p->year&&y==p->month&&z==p->day)
{
cout<
p=p->next;
}
}
void CalculateInfor(Infor *head)
{
Infor *p;
p=head->next;
int Ch;
system("cls");
cout<
cin>>Ch;
switch (Ch)
{
case 1:
CalculateYearInfor(p);
system("pause");
break;
case 2:
CalculateMonthInfor(p);
system(
"pause");
break;
case 3:
CalculateDayInfor(p);
system("pause");
break;
case 4:
system("cls");
return;
default:
break;
}
}
void main()
{
system("color 3D");
Infor *st,*head=NULL;
st=Inforinitlist();
int choice=0;
while(choice!=6)
{
choice=menu_select();
switch(choice)
{
case 1:
InputFinanceInfor(st);system("pause");
break;
case 2:
ListFinanceInfor(st);system("pause");
case 3:
SearchMenu(st);system("pause");
break;
case 4:
CalculateInfor(st);system("pause");
break;
case 5:
system("cls");SaveToFile(st);
break;
case 6:
exit(0);
break;
default:;
}
}
}