我的代码是这样的:
//日期类和人员类:设计日期类 date,包含 3 个成员变量:int year、int month 和 int day 分
//别表示年、月、日;然后设计人员类 person,包含 4 个成员变量:姓名 name(字符指
//针),性别 gender(字符),生日 birthday(date 类对象)、现金 cashFlow(整数),还包含
//一个静态成员函数 int getCount() 返回总人数。为这两个类设计成员函数,保证满足以下
#include <iostream>
#include <string>
using namespace std;
class date
{
public:
date(){}
date(int m_year, int m_month, int m_day)
{
year = m_year;
month = m_month;
day = m_day;
}
int year = 0;
int month = 0;
int day = 0;
};
class person
{
public:
person(){}
person(string m_name, char m_gender, int m_year, int m_month, int m_day, int m_cashFlow) :birthday(m_year, m_month, m_day), cashFlow(m_cashFlow)
{
name = m_name;
gender = m_gender;
}
void print()
{
cout << "姓名:" << name << "; 性别:";
if (gender == 'f') {
cout << "女" << endl;
}
else cout << "男" << endl;
cout << "生日:" << birthday.year << "-" << birthday.month << "-" << birthday.day << ";\n";
}
int getCashFlow()
{
if (cashFlow = NULL)
return 0;
else return cashFlow;
}
private:
string name = "zhang";
char gender = 'a';
date birthday;
int cashFlow = 0;
};
int main() {
person p1, p2("zhang", 'f', date(1991, 1, 1)), p3(p2);
//person p1, p2("zhang", 'f', date(1991, 1, 1)), p3(p2);
//p3.print(); // 输出: 姓名:zhang; 性别:女; 生日:1991−1−1;
//cout << "收支为:" << p3.getCashFlow() << "元" << endl; // 输出:0元
//person *p = new person("li", 'm', date(1990, 2, 2), 800);
//p−>print(); // 输出: 姓名: li ; 性别:男; 生日:1990−2−2;
//cout << "收支为:" << p−>getCashFlow() << "元" << endl; // 输出:800元
//cout << "总人数:" << p1.getCount() << endl; // 输出:4
//delete p;
//cout << "总人数:" << p1.getCount() << endl; // 输出:3
return 0;
}
然后他就一直显示这个:
为啥咧?