#include
#include
#include
#include
#include
using namespace std;
struct Date
{
int Year;
int Month;
int Day;
};
struct Bill
{
void input() //收入
{
char t;
cout << " *****收入基本信息*****" << endl;
fstream outfile("bb.txt", ios::out | ios::app); //以写方式打开文件
if (!outfile)
cout << " 打开文件失败!" << endl;
else
{
cout << " 顺序号:";
cin >> id;
outfile << id << " ";
cout << " 日期:" << endl;
cout << " 年份:"; cin >> time.Year; outfile << time.Year << " "; cout << endl;
cout << " 月份:"; cin >> time.Month; outfile << time.Month << " "; cout << endl;
cout << " 日期:"; cin >> time.Day; outfile << time.Day << " "; cout << endl;
cout << " 摘要:";
cin >> id;
outfile << id << " ";
cout << " 金额:";
cin >> price;
outfile << price << " ";
cout << " 余额:";
cin >> price;
outfile << price << " ";
cout << " 币种<1,4>: 1.人民币" << endl;
cout << " 2.美元" << endl;
cout << " 3.欧元" << endl;
cout << " 4.日元" << endl;
cout << " 5.英镑:";
cin >> category;
switch (category)
{
case 1: outfile << " 人民币" << " " << '1' << " " << endl; break;
case 2: outfile << " 美元" << " " << '1' << " " << endl; break;
case 3: outfile << " 欧元" << " " << "1" << " " << endl; break;
case 4: outfile << " 日元" << " " << "1" << " " << endl; break;
case 5: outfile << " 英镑" << " " << "1" << " " << endl; break;
default:
{
cout << " 输入的数字有误哦";
cout << " 请重新输入:"; cin >> category;
switch (category)
{
case 1: outfile << " 人民币" << " " << '1' << " " << endl; break;
case 2: outfile << " 美元" << " " << '1' << " " << endl; break;
case 3: outfile << " 欧元" << " " << "1" << " " << endl; break;
case 4: outfile << " 日元" << " " << "1" << " " << endl; break;
case 5: outfile << " 英镑" << " " << "1" << " " << endl; break;
default:outfile << " 人民币" << " " << '1' << " " << endl; break;
}
}
}
outfile.close();
}
cout << " 是否继续添加收入信息(Y/N):";
cin >> t;
if (t == 'y' || t == 'Y')
input();
else
return;
}
void input1() //支出
{
char t;
cout << " *****支出基本信息*****" << endl;
fstream outfile("bb.txt", ios::out | ios::app); //以写方式打开文件
if (!outfile)
cout << " 打开文件失败!" << endl;
else
{
cout << " 顺序号:";
cin >> id;
outfile << id << " ";
cout << " 日期:" << endl;
cout << " 年份:"; cin >> time.Year; outfile << time.Year << " "; cout << endl;
cout << " 月份:"; cin >> time.Month; outfile << time.Month << " "; cout << endl;
cout << " 日期:"; cin >> time.Day; outfile << time.Day << " "; cout << endl;
cout << " 摘要:";
cin >> id;
outfile << id << " ";
cout << " 金额:";
cin >> price;
outfile << price << " ";
cout << " 余额:";
cin >> price;
outfile << price << " ";
cout << " 币种<1,4>: 1.人民币" << endl;
cout << " 2.美元" << endl;
cout << " 3.欧元" << endl;
cout << " 4.日元" << endl;
cout << " 5.英镑:";
cin >> category;
switch (category)
{
case 1: outfile << " 人民币" << " " << "-1" << " " << endl; break;
case 2: outfile << " 美元" << " " << "-1" << " " << endl; break;
case 3: outfile << " 欧元" << " " << "-1" << " " << endl; break;
case 4: outfile << " 日元" << " " << "-1" << " " << endl; break;
case 5: outfile << " 英镑" << " " << "-1" << " " << endl; break;
default:
{
cout << " 输入的数字有误哦";
cout << " 请重新输入:"; cin >> category;
switch (category)
{
case 1: outfile << " 人民币" << " " << "-1" << " " << endl; break;
case 2: outfile << " 美元" << " " << "-1" << " " << endl; break;
case 3: outfile << " 欧元" << " " << "-1" << " " << endl; break;
case 4: outfile << " 日元" << " " << "-1" << " " << endl; break;
case 5: outfile << " 英镑" << " " << "-1" << " " << endl; break;
default:outfile << " 人民币" << " " << "-1" << " " << endl; break;
}
}
}
outfile.close();
}
cout << " 是否继续添加收入信息(Y/N):";
cin >> t;
if (t == 'y' || t == 'Y')
input();
else
return;
}
void mingxi()
{
char t;
fstream infile2("bb.txt", ios::in); //以读方式打开文件
if (!infile2)
{
cout << " 打开文件失败!" << endl;
return;
}
int line = 0;
int a[100], b[100], c[100], d[100], e[100];
char arr[100][100][100]; //定义一个string类型的二维数组,用来保存从文本内读取的信息
memset(arr, 0, sizeof(arr)); //将数组清空
while (!infile2.eof()) //文件不为空的条件设置
{
infile2 >> arr[line][0] >> a[line] >> b[line] >> c[line] >> arr[line][1] >> arr[line][2] >> arr[line][3] >> arr[line][4] >> e[line];
line++;
}
for (int i = 0; i < line; i++)
{
d[i] = a[i] * 10000 + b[i] * 100 + c[i];
}
int year, month, day;
int start = 0, finish = 0;
cout << " 请输入要查询的起始日期:";
cout << endl << " 年:"; cin >> year;
if (year <= 0)
{
cout << "输入的日期不太对,请重新输入。" << endl;
cout << " 年:"; cin >> year; cout << endl;
}
cout << endl << " 月:"; cin >> month;
if (month <= 0)
{
cout << "输入的日期不太对,请重新输入。" << endl;
cout << " 月:"; cin >> month; cout << endl;
}
cout << endl << " 日:"; cin >> day;
if (day <= 0)
{
cout << "输入的日期不太对,请重新输入。" << endl;
cout << endl << " 日:"; cin >> day;
}
start = year * 10000 + month * 100 + day;
cout << " 请输入要查询的截止日期:";
cout << endl << " 年:"; cin >> year;
if (year <= 0)
{
cout << "输入的日期不太对,请重新输入。" << endl;
cout << " 年:"; cin >> year; cout << endl;
}
cout << endl << " 月:"; cin >> month;
if (month <= 0)
{
cout << "输入的日期不太对,请重新输入。" << endl;
cout << " 月:"; cin >> month; cout << endl;
}
cout << endl << " 日:"; cin >> day;
if (day <= 0)
{
cout << "输入的日期不太对,请重新输入。" << endl;
cout << endl << " 日:"; cin >> day;
}
finish = year * 10000 + month * 100 + day;
for (int i = 0; i < line; i++)
{
if (d[i] >= start && d[i] <= finish)
{
cout << " 顺序号:" << arr[i][0] << " " << "年:" << a[i] << " " << "月:"
<< b[i] << " " << "日:" << c[i] << " " << "摘要:" << arr[i][1] << " " << "金额:"
<< arr[i][2] << " " << "余额" << arr[i][3] << " " << "币种:" << arr[i][4];
if (e[i] == 1) cout << "收入" << endl;
else cout << "支出" << endl;
}
}
cout << " 是否继续查询(Y/N):";
cin >> t;
if (t == 'y' || t == 'Y')
mingxi();
else
return;
}
void check1()
{
char t;
fstream infile2("bb.txt", ios::in); //以读方式打开文件
if (!infile2)
{
cout << " 打开文件失败!" << endl;
return;
}
float result = 0, a[100], b[100], c[100], d[100], e[100];
int line = 0;
char arr[100][100][100]; //定义一个string类型的二维数组,用来保存从文本内读取的信息
memset(arr, 0, sizeof(arr)); //将数组清空
while (!infile2.eof()) //文件不为空的条件设置
{
infile2 >> arr[line][0] >> a[line] >> b[line] >> c[line] >> arr[line][1] >> d[line] >> arr[line][2] >> arr[line][3] >> e[line];
line++;
}
int num1 = 0;
int year, month;
cout << " 请输入要核算的月份:" << endl;
cout << endl << " 年:"; cin >> year;
if (year <= 0)
{
cout << "输入的日期不太对,请重新输入。" << endl;
cout << " 年:"; cin >> year; cout << endl;
}
cout << endl << " 月:"; cin >> month;
if (month <= 0)
{
cout << "输入的日期不太对,请重新输入。" << endl;
cout << " 月:"; cin >> month; cout << endl;
}
for (int i = 0; i < line; i++)
{
if (a[i] == year && b[i] == month)
{
cout << " 顺序号:" << arr[i][0] << " " << "年:" << a[i] << " " << "月:"
<< b[i] << " " << "日:" << c[i] << " " << "摘要:" << arr[i][1] << " " << "金额:"
<< d[i] << " " << "余额" << arr[i][2] << " " << "币种:" << arr[i][3];
if (e[i] == 1)
{
cout << "收入" << endl;
result += d[i];
}
else
{
cout << "支出" << endl;
result -= d[i];
}
}
}
cout << " 该月账单总额为::" << result << "元" << endl;
cout << " 是否继续核算(Y/N):";
cin >> t;
if (t == 'y' || t == 'Y')
check1();
else
return;
}
void check2()
{
char t;
fstream infile2("bb.txt", ios::in); //以读方式打开文件
if (!infile2)
{
cout << " 打开文件失败!" << endl;
return;
}
float result = 0, a[100], b[100], c[100], d[100], e[100];
int line = 0;
char arr[100][100]; //定义一个string类型的二维数组,用来保存从文本内读取的信息
memset(arr, 0, sizeof(arr)); //将数组清空
while (!infile2.eof()) //文件不为空的条件设置
{
infile2 >> arr[line][0] >> a[line] >> b[line] >> c[line] >> arr[line][1] >> d[line] >> arr[line][2] >> arr[line][3] >> e[line];
line++;
}
int year;
cout << endl << " 请输入要核算的年份:"; cin >> year;
if (year <= 0)
{
cout << "输入的日期不太对,请重新输入。" << endl;
cout << " 年:"; cin >> year; cout << endl;
}
for (int i = 0; i < line; i++)
{
if (a[i] == year)
{
cout << " 顺序号:" << arr[i][0] << " " << "年:" << a[i] << " " << "月:"
<< b[i] << " " << "日:" << c[i] << " " << "摘要:" << arr[i][1] << " " << "金额:"
<< d[i] << " " << "余额" << arr[i][2] << " " << "币种:" << arr[i][3];
if (e[i] == 1)
{
cout << "收入" << endl;
result += d[i];
}
else
{
cout << "支出" << endl;
result -= d[i];
}
}
}
cout << " 该年账单总额为::" << result << "元" << endl;
cout << " 是否继续核算(Y/N):";
cin >> t;
if (t == 'y' || t == 'Y')
check2();
else
return;
}
void check3()
{
char t;
fstream infile2("bb.txt", ios::in); //以读方式打开文件
if (!infile2)
{
cout << " 打开文件失败!" << endl;
return;
}
float result = 0, a[100], b[100], c[100], d[100], e[100];
int line = 0;
char arr[100][100][100]; //定义一个string类型的二维数组,用来保存从文本内读取的信息
memset(arr, 0, sizeof(arr)); //将数组清空
while (!infile2.eof()) //文件不为空的条件设置
{
infile2 >> arr[line][0] >> a[line] >> b[line] >> c[line] >> arr[line][1] >> d[line] >> arr[line][2] >> arr[line][3] >> e[line];
line++;
}
for (int i = 0; i < line-1; i++)
{
cout << " 顺序号:" << arr[i][0] << " " << "年:" << a[i] << " " << "月:"
<< b[i] << " " << "日:" << c[i] << " " << "摘要:" << arr[i][1] << " " << "金额:"
<< d[i] << " " << "余额" << arr[i][2] << " " << "币种:" << arr[i][3];
if (e[i] == 1)
{
cout << "收入" << endl;
}
else
{
cout << "支出" << endl;
}
}
return;
}
//顺序号,金额,时间
string id;
float price;
Date time;
int category;
};
int main()
{
char choose;
Bill w;
int quit = 1;
while (quit)
{
cout << " 收支管理系统 " << endl;
cout << " " << endl;
cout << " 1.收入 " << endl;
cout << " 2.支出 " << endl;
cout << " 3.明细表 " << endl;
cout << " 4.按月查询 " << endl;
cout << " 5.按年查询 " << endl;
cout << " 6.写入文件 " << endl;
cout << " 7.读取文件 " << endl;
cout << " 0.退出 " << endl;
cout << " " << endl;
cout << " 请输入您选择的数字<0-7>:";
cin >> choose;
switch (choose)
{
case '1': w.input(); break;
case '2': w.input1(); break;
case '3': w.mingxi(); break;
case '4': w.check1(); break;
case '5': w.check2(); break;
case '6': cout << " 文件已写入"<<endl; break;
case '7': w.check3(); break;
case '0':
{
cout << " 欢迎下次使用,拜拜\n";
quit = 0;
break;
}
default:cout << " 输入的数字不太对...."; break;
}
}
return 0;
}
日期闰年合法性的检验 Bill w 含义 统计的实现还有三维数组的使用 望有人能解释我的疑惑