学生信息之类交互调用

class graduate;
class teacher
{
	int tno;
	char tname[10];
	char prof[8];
	int num;
	graduate *sp[6];
	public:
		teacher(){}
		teacher(int n,char na[],char pr[]){tno=n;strcpy(tname,na);strcpy(prof,pr);num=0;}
		void addg(graduate *gp){sp[num]=gp;num++;}
		void tdis(){cout<<"tname:"<<tname<<" tno"<<tno<<" prof"<<prof<<endl;}
		void tdisall()
		{
			int i;cout<<"tname tno prif"<<endl;
			for(i=0;i<num;i++)
			sp[i]->gdis();
		}
};
class graduate
{
	int sno;
	char sname[10];
	teacher t;
	public:
	graduate(int n,char na[])
	{
		sno=n;strcpy(sname,na);
	}	
	void setteacher(teacher &t1)
	{
		t1.addg(this);t=t1;
	}
	void gdis()
	{
		cout<<"sno:"<<sno<<"name:"<<sname<<endl;
	}
	void gdisall()
	{
		cout<<"sno:"<<sno<<"name:"<<sname<<endl;
		t.tdis();
	}
	
};
int main()
{
	int i;
	teacher t[3]={teacher(101,"wz1","T"),teacher(102,"wz2","T"),teacher(103,"wz3","T")};
    graduate g[3]={graduate(20130101,"s1"),graduate(20130102,"s2"),graduate(20130103,"s3")};
    g[0].setteacher(t[0]);
    g[1].setteacher(t[0]);
    g[2].setteacher(t[2]);
    for(i=0;i<3;i++)
       g[i].gdisall();
       
    for(i=0;i<3;i++)
       t[i].tdisall();
return 0;
}


你可能感兴趣的:(小代码)