64,682
社区成员
发帖
与我相关
我的任务
分享
缺头文件string.h
#include <iostream>
#include <string> //字符
#include <fstream> //对文件操作
#include <iomanip> //setw
#include <cstdlib>
#include<string.h> //strcmp位于此头文件
using namespace std; //命名空间
class account
{
private:
string dates; //日期
float money; // 交易金额
string xfib; //消费类别
string coslx; //消费类型
string beizhu; //备注
public:
account(); //构造函数
char register1(); //登陆口
char service(); //业务入口
void in_item(); //存入
void out_item(); //支出
void check_item();//查询
void count(); //统计
void save_new();
};
int main()
{
char choose;
account acc;//添加对象
char q[20];
char p[20];
choose = acc.register1();
if (choose == '1') {
cout << "账号:" << setw(20) << endl;
cin >> q;
cout << "密码:" << setw(20) << endl;
cin >> p;
}
else {
cout << "退出,谢谢使用" << endl;
exit(0);
}
while (choose == acc.service())
{
switch (choose)
{
case '1':
acc.in_item();//账目收入
break;
case '2':
acc.out_item();//账目支出
break;
case '3':
acc.count();//账目统计
break;
case 4:
acc.check_item();//账目查询
break;
case '5':
cout << "退出,谢谢使用";
exit(0);
break;
default:
break;
}
}
return 0;
}
account::account()//初始化构造函数
{
dates = "";
money = 0.0;
xfib = "";
coslx = "";
}
char account::register1()
{
cout << "=================================================== "
<< endl
<< " 个人记账本 "
<< endl
<< " 1. 登录 "
<< endl
<< " 2. 退出 "
<< endl
<< "==================================================="
<< endl;
char choose;
cin >> choose;
return choose;
}
char account::service()
{
system("cls");//清除屏幕
cout << endl;
cout << "===================================="
<< " 1.账目收入 "
<< " 2.账目支出 "
<< " 3.账目统计 "
<< " 4.账目查询 "
<< " 5.退出 "
<< "===================================="
<< endl;
char choose;
cin >> choose;
return choose;
}
void account::in_item() //账目收入
{
cout << "根据提示输入信息" << endl << "日期" << endl;
cin >> dates;
cout << "金额";
cin >> money;
cout << "备注";
cin >> beizhu;
save_new(); //保存信息函数
cout << "信息已保存" << endl;
}
void account::out_item() //账目支出
{
cout << "根据提示输入信息" << endl << "日期";
cin >> dates;
cout << "金额";
cin >> money;
cout << "消费类别 衣(a)食(b)住(c)行(d)其他(e)";
cin >> xfib;
cout << "备注";
cin >> beizhu;
save_new(); //保存信息
cout << "信息已保存" << endl;
}
void account::count() //账目统计
{
fstream inDate("C:\1.txt", ios::in | ios::out);
int b = 0;
float sum;
sum = 0;
char in_item = 'A', out_item = 'B';
if (!inDate)
{
cout << endl << "对不起找不到文件" << endl;
return;
}
string sign1;
string sign2;
cout << endl << "输入交易开始日期:";
cin >> sign1;
cout << endl << "输入交易终止日期";
cin >> sign2;
bool flag = true;
bool flag1 = true;
int a = 0;
float num1 = 0, num2 = 0, num3 = 0, num4 = 0, num5 = 0, num6 = 0, num7 = 0;
string str[100];
while (inDate >> dates >> money >> xfib)
{
getline(inDate, str[a]);
if (strcmp(dates.c_str(), sign1.c_str()) >= 0 && strcmp(dates.c_str(), sign2.c_str()) <= 0)
//比较日期的大小
{
if (flag)
{
cout << endl << "该时间段交易信息有:" << endl;
cout << setiosflags(ios::left);
cout << setw(16) << "交易日期"
<< setw(10) << "交易金额"
<< setw(17) << "交易类别"
<< setw(17) << "交易类型"
<< setw(20) << "备注" << endl;
}
cout << dates << ""
<< money << ""
<< xfib << ""
<< str[a] << endl;
if (coslx == "A")
num1 += money;
if (coslx == "B")
num2 += money;
if (xfib == "a")
num3 += money;
if (xfib == "b")
num4 += money;
if (xfib == "c")
num5 += money;
if (xfib == "d")
num6 += money;
if (xfib == "e")
num7 += money;
flag = false;
}
if (b != 0)
{
if (flag1)
{
cout << "请输入消费类别:(A或B)" << endl;
cin >> sign1;
}
flag1 = false;
}
a++;
}
cout << "此段时间的总支出为:" << num1 << endl
<< "此段时间的总收入为:" << num2 << endl;
cout << "此段时间总购衣为:" << num3 << endl
<< " 食物费为:" << num4 << endl
<< " 住房费为" << num5 << endl
<< " 交通费为" << num6 << endl
<< " 其他为" << num7 << endl;
if (a > 100)
{
cout << "交易金额:" << "money" << endl;
sum += money;
}
cout << sum << endl;
}
void account::check_item() //查询
{
fstream indate("C:\1.txt", ios::in | ios::out);
int a = 1, b = 0, c;
string sign;
cout << "输入你想要查询的日期:" << endl;
bool flag = true;
string str[200];
string str1, str2;
while (indate >> dates)
{
getline(indate, str[a]);
if (sign == dates)
{
if (flag)
{
cout << "你想查询的交易:" << endl;
cout << setiosflags(ios::left)
<< setw(16) << "交易日期"
<< setw(10) << "交易金额"
<< setw(16) << "交易类型"
<< setw(17) << "交易类别"
<< setw(20) << "备注" << endl;
}
cout << "序号" << a << endl;
cout << dates << str[a] << endl;
a++;
}
}
}
void account::save_new()
{}