写一个理财软件,首先我想到的抽象出一个 个人财产 类;
class DATA{
public:
unsigned int year;
unsigned char month;
unsigned char day;
public:
DATA(unsigned int Year,unsigned char Month,unsigned char Day){
year = Year;
month = Month;
day = Day;
}
DATA(){}
~DATA(){}
bool isEmpty(){
if(year == month == day ==0) return true;
else return false;
}
};
class CProperty{
typedef struct DETAIL{
DETAIL(){};
unsigned long currentProperty; //现在有的钱
unsigned long money; //收入或支出的钱
DATA data; //支出或收入的时间
char * pszReason; //支出或收入的原因
};
public:
DETAIL detail;
CProperty(unsigned long money=0){
if(ReadcurrentProperty() == false)
detail.currentProperty = money;
}
~CProperty(){}
bool ReadcurrentProperty()
{
// 从文件中读取现在有的钱,赋值给detail.currentProperty,成功返回TRUE
//return true;
//失败返回FALSE
return false;
}
void get(unsigned long money){ detail.currentProperty += money; }
void out(unsigned long money){ detail.currentProperty -= money; }
void saveToFile(){
//把 类数据成员 detail 写到文件去
}
void searchAndShow(DATA from,DATA to){
if(from.isEmpty()==true && to.isEmpty()==true){
//显示全部储存的信息
}
if(from.isEmpty()==false && to.isEmpty()==true){
//显示从from到最后一条信息
}
if(from.isEmpty()==true && to.isEmpty()==false){
//显示第一条到to的信息
}
}
};
void main()
{
CProperty myProperty(10000000); //初始财产1000万
myProperty.get(5000000);
DATA d(0,0,0);
myProperty.detail.data=d;
char * psz = "工资";
myProperty.detail.pszReason=psz;
myProperty.saveToFile();
}