//st.h文件
class TDate{
public:
void SetDate(int y,int m,int d);
void ShowDate();
private:
int year;
int month;
int day;
};
class Tstudent{
public:
void SetStudent(char *sn,char *name,TDate bd,int n);
void ShowStudent();
private:
char sno[5];
char sname[10];
TDate birthday;
int cno;
};
//st.cpp
#include<string.h>
#include<iomanip.h>
#include"st.h"
void TDate::SetDate(int y,int m,int d)
{
year=y;
month=m;
day=d;
};
void TDate::ShowDate()
{
cout<<year<<"."<<month<<"."<<day;
}
void Tstudent::SetStudent(char *sn,char *name,TDate bd,int cn)
{
strcpy(sno,sn);
strcpy(sname,name);
birthday=bd;
birthday.SetDate(2006,12,16);
cno=cn;
}
void Tstudent::ShowStudent()
{
cout<<setw(6)<<sno<<setw(12)<<sname<<setw(8);
birthday.ShowDate();
cout<<setw(5)<<cno<<endl;
}
//e_77.cpp
#include <iostream.h>
#include <st.h>
void main()
{
TDate b;
Tstudent s1;
cout<<"访问的类成员:\n";
cout<<setw(6)<<"sno<<setw(12)<<"sname"<<setw(14)<<"birthday"<<setw(6)<<"cno\n";
s1.SetStudent("001","aaa",b,2);
s1.ShowStudent();
}