本文共 2014 字,大约阅读时间需要 6 分钟。
题目一:
//JNU Orion 233//created by Wang Yuchen @ 2018/03/14//第五次试实验 人员类Staff#include#include #include #include using namespace std;class Date{public: Date(int y = 0, int m = 0, int d = 0); Date(Date &d); void setDate(int y, int m, int d); void showDate(); ~Date(){};private: int year; int month; int day;};class Staff{public: Staff(string newName, int newAge, Date newBirthday); void setStaff(string newName, int newAge, Date newBirthday); void showStaff(); ~Staff(){};private: string name; int age; Date birthday;};Date::Date(int y,int m,int d){ //Date构造函数 year = y; month = m; day = d;}Date::Date(Date &d){ //Date复制构造函数 year = d.year; month = d.month; day = d.day; cout<< "[sys] Calling the Copy Constructor of Staff ..." << endl;}void Date::setDate(int y,int m,int d){ //Date设置日期 year = y; month = m; day = d;}void Date::showDate(){ //Date显示日期 cout<< year << "" << month << "" << day < > name; cout<< "[sys] Input Staff's Age: "; cin>>age; cout<< "[sys] Input Staff's Birthday(xxxx-xx-xx): "; cin>>y>>m>>d; cout<< endl; Date birthday(y,m,d); Staff staff(name,age,birthday); staff.showStaff(); cout<< "[sys] continue ?(Y/N)" ; cin>> choice; if(choice == 'N') break; } return 0;}
题目二:
。。。。
代码如下:
#include#include #include using namespace std;class Complex{public: Complex(float na ,float nb); Complex(float na); //Complex(Complex &c) void addComplex(Complex &c2); void showComplex(); ~Complex(){};private: float a,b;};Complex::Complex(float na,float nb){ a = na; b = nb;}Complex::Complex(float na){ a = na;}/*Complex::Complex(Complex &c2){ a = c2.a; b = c2.b;}*/void Complex::addComplex(Complex &c2){ a += c2.a; b += c2.b;}void Complex::showComplex(){ if(b == 0){ cout<< a <