#include<iostream>
#include<string>
#include<iomanip>
#include<fstream>
#include"List.h"
using namespace std;
class CListSuper:public CList //定义链表类
{
public:
void InsertNode(CNode*); //排序插入一个结点
};
void CListSuper::InsertNode(CNode*pnode)
{
CNode*p1,*p2;
if(pHead==0)
{
pHead=pnode;
pnode->pNext=0;
}
else
{
p1=p2=pHead;
while((p1->pData->Compare(*(pnode->pData))<0)&&p1->pNext)
{
p2=p1;
p1=p1->pNext;
}
if(p1==pHead)
{
pHead=pnode;
pnode->pNext=p1;
}
else if(p1->pNext!=0)
{
p2->pNext=pnode;
pnode->pNext=p1;
}
else
{
p1->pNext=pnode;
pnode->pNext=0;
}
}
return;
}
class CFinance:public CData
{
private:
int nYear,nMonth,nDay;
double dlIncome,dlOutput;
double dlBalance; //结余
char szPurpose[20]; //用途 目的
public:
CFinance(){dlIncome=dlOutput=dlBalance=0.0;}
int Compare(CData &);
void Show();
void SetFinance(int,int,int,double,double,char*);
};
void CFinance::SetFinance(int year,int month,int day,double income,double output,char *szsource)
{
nYear=year;
nMonth=month;
nDay=day;
dlIncome=income;
dlOutput=output;
strcpy_s(szPurpose,szsource);
}
int CFinance::Compare(CData&data)
{
CFinance&temp=(CFinance&)data;
if(nYear>temp.nYear)
return 1;
else if(nYear<temp.nYear)
return -1;
if(nMonth>temp.nMonth)
return 1;
if(nMonth<temp.nMonth)
return -1;
if(nDay>temp.nDay)
return 1;
if(nDay<temp.nDay)
return -1;
else
return 0;
}
void CFinance::Show(void)
{
cout<<setw(4)<<nYear<<setw(3)<<nMonth<<setw(3)<<nDay;
if(dlOutput<0.01)
cout<<setw(10)<<dlIncome<<setw(20)<<dlBalance<<setw(20)<<szPurpose<<endl;
else if(dlIncome<0.01)
cout<<setw(20)<<dlOutput<<setw(10)<<dlBalance<<setw(20)<<szPurpose<<endl;
}
void ShowAll(CListSuper&FinList){FinList.ShowList();}
void Output(CListSuper&FinList) //将支出记录添加到链表中
{
CNode*pNode;
CFinance*pFin;
int nYear,nMonth,nDay;
double dlOutput;
char szCourse[20];
cout<<"输入年 月 日(输入0结束): ";
cin>>nYear;
while(nYear)
{
cin>>nMonth>>nDay;
cout<<"输入支出金额: ";
cin>>dlOutput;
cout<<"输入支出理由:";
cin.ignore();
cin.getline(szCourse,20);
pFin=new CFinance; //生成新的数据对象
pFin->SetFinance(nYear,nMonth,nDay,0.0,dlOutput,szCourse);
pNode=new CNode; //生成新的结点
pNode->InputData(pFin); //结点赋值
FinList.InsertNode(pNode); //结点加入链表
cout<<"输入年 月 日(输入0结束): ";
cin>>nYear;
}
cout<<endl<<endl;
}
void Income(CListSuper&FinList) //将收入记录添加到链表中
{
CNode*pNode;
CFinance*pFin;
int nYear,nMonth,nDay;
double dlIncome;
char szCourse[20];
cout<<"输入年 月 日(输入0结束): ";
cin>>nYear;
while(nYear)
{
cin>>nMonth>>nDay;
cout<<"输入收入金额: ";
cin>>dlIncome;
cout<<"输入收入来源: ";
cin.ignore();
cin.getline(szCourse,20);
pFin=new CFinance; //生成新的数据类对象
pFin->SetFinance(nYear,nMonth,nDay,dlIncome,0.0,szCourse);
pNode=new CNode; //生成新的结点
pNode->InputData(pFin); //结点赋值
FinList.InsertNode(pNode); //结点加入链表
cout<<"输入年 月 日(输入0结束): ";
cin>>nYear;
}
cout<<endl<<endl;
}
void Operate(string &strChoice,CListSuper &FinList) //根据主菜单选项进行操作
{
if(strChoice=="1")
Income(FinList);
else if(strChoice=="2")
Output(FinList);
else if(strChoice=="3")
ShowAll(FinList);
else if(strChoice=="0")
return;
else
cout<<"输入错误,请重新输入您的选择:";
}
int main()
{
CListSuper FinList; //定义链表的对象
system("cls");
cout<<"\t欢迎进入个人财务管理数据\n\n";
string strChoice; //接受主菜单选项
do
{
cout<<"\t1.输入收入记录\n";
cout<<"\t2.输入支出记录\n";
cout<<"\t3.查看财务账目\n";
cout<<"\t0.退出系统\n\n\n";
cout<<"请输入您的选择:";
cin>>strChoice;
cin.ignore( );
Operate(strChoice,FinList);
}
while(strChoice, FinList);
cout<<"\n\n\t欢迎再次使用个人财务管理系统\n\n";
return 0;
}
也许对你有帮助:https://blog.csdn.net/it_xiangqiang/category_10581430.html
CNode结构体在哪里定义的,没有看到定义的代码。最好把详细错误提示贴出来。
提示错误为 没有可用于执行该转换的用户定义的转换运算符,或者无法调用该运算符
实在是能力有限无法修改希望大神帮忙
您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~
如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~
ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632
非常感谢您使用有问必答服务,为了后续更快速的帮您解决问题,现诚邀您参与有问必答体验反馈。您的建议将会运用到我们的产品优化中,希望能得到您的支持与协助!
速戳参与调研>>>https://t.csdnimg.cn/Kf0y