满意答案
egmwhy
2013.12.31
采纳率:54% 等级:12
已帮助:8300人
很简单 的
给个差不多的你看看就知道了
#include
#include
#include
using namespace std;
class Student
{ int ID;
string name;
double score;
Date birth;
public:
void Set(int ID1,string name1,double score1);
int GetID()const { return ID; }
string GetName()const { return name; }
double GetScore()const { return score; }
Date GetBirth()const { return birth; }
void SetID(int ID1) { ID=ID1; }
void SetName(string name1) { name=name1; }
void SetScore(double score1){ score=score1; }
void SetBirth(Date birth1) { birth=birth1; }
void Output()const;
void Output(ofstream &fout)const;
void Input(istream &i);
};
void Date::Set(int y,int m,int d)
{ year=y; month=m; day=d; }
void Date::Set(const string &s)
{ year=atoi(s.substr(0,4).c_str() ); // 转换得到C串
month=atoi(s.substr(5,2).c_str());
day=atoi(s.substr(8,2).c_str());
}
void Date::Output()const
{ cout <
void Date::Input(istream &i)
{ i>>year>>month>>day; }
void Date::Output(ofstream &fout)const
{ fout <
bool Date::IsLeapYear()
{ return (year%4==0 && year%100!=0) || (year%400==0); }
void Date::Add(int days)
{ year=year+days /365;
month=(month + (days %365)%30)%12;
day=(day+ days%30) % 30;
}
int Date::Sub(Date &d)
{
return (year-d.year)*365+(month-d.month)*30+day-d.day;
}
Date Date::Sub(int days)
{ Date d;
d.Set(year,month,day-days);
return d;
}
void main()
{ Student sts[2]; // Student *sts=new Student[2];
Date d;
ofstream fout; fout.open("1.txt");
sts[0].Set(1,"aaa",99); d.Set(2007,1,1); sts[0].SetBirth(d);
sts[0].Output(fout);
sts[1].Set(2,"BBB",89); d.Set(2007,1,3); sts[1].SetBirth(d);
sts[1].Output(fout);
fout.close();
// delete []sts;
}
00分享举报