题目是:设计一个学生表类,类中要求拥有:
学生属性:包括学号(long),姓名(char*),年龄(int),性别(BOOL),家庭住址(char*),朋友列表(struct friend *),家庭成员列表(struct family *),其中struct friend 和struct family自行定义;
方法:输入数据方法、修改数据方法、查询数据方法、输出数据方法(注意:输入、修改、查询、输出的数据包括学生的各种数据,请自行设计方法个数和方式)
提高部分:每个对象如果可以存放多个学生,每个学生都有自己的朋友列表和家庭成员列表的情况如何设计上面的类。
下面是我写的一些,但是不能输出和输入朋友和家人的资料,/**/是我想改进的,但是错误多多
由于刚学C++不久,但是题目比较难,请各位多多指教,谢谢!
#include<iostream.h>
#include<string.h>
/*enum BOOL{
False,True
};*/
struct stu{
long number;
char name[20];
int age;
int sex;
char address[200];
};
struct friends{
char name[20];
char address[100];
long tel_number;
};
struct family{
char name[20];
char description[100];
};
class student{
struct stu data;
struct friends *p_friends;
struct family *p_family;
int m,n;
public:
student(struct stu,int,int);
~student();
void show();
//BOOL M_or_W();//?????
father(char*,char*,char);
mather(char*,char*);
friend1(char*,char*,long);
friend2(char*,char*,long,int);
};
void student::show(){
cout<<"student number:"<<data.number<<endl;
cout<<"student name:"<<data.name<<endl;
cout<<"student age:"<<data.age<<endl;
cout<<"student sex:"<<data.sex<<endl;
cout<<"student address:"<<data.address<<endl;
for (int i=0;i<m;i++)
cout<<"friends name:"<<(p_friends+i)->name<<" "<<"friend address:"<<(p_friends+i)->address<<" "<<"friend tel_number:"<<(p_friends+i)->tel_number<<endl;
for (int j=0;j<n;j++)
cout<<"family name:"<<(p_family+i)->name<<" "<<"family description:"<<(p_family+i)->description<<endl;
}
student::~student(){
delete p_friends;
delete p_family;
}
student::student(struct stu a,int b,int c){
data.number=a.number;
strcpy(data.name,a.name);
data.age=a.age;
data.sex=a.sex;
strcpy(data.address,a.address);
p_friends=new friends[b];
p_family=new family[c];
m=b;
n=c;
}
/*student::father(char *x,char *y,char z){
strcpy(p_family->name,x->name);
strcpy(p_family->description,y->name);
}
student::mather(char *xx,char *yy){
strcpy(p_family->name,xx.name);
strcpy(p_family->description,yy.name);
}
student::friend1(char *h,char *j,long k){
strcpy(p_friends->address,h->address);
strcpy(p_friends->name,h->name);
p_friends->tel_number;
}
student::friend2(char *hh,char *jj,long kk){
strcpy(p_friends->address,hh->address);
strcpy(p_friends->name,jj->name);
p_friends->kk.tel_number;
}
*/
int main(void){
struct stu wy;
/* struct friends *F1;
struct friends *F2;
struct family *F;
struct family *M;*/
wy.number=642135641;
strcpy(wy.name,"wuyu");
wy.age=22;
wy.sex=0;
strcpy(wy.address,"gdsszdxzw");
student kh(wy,2,2);
/*student yyy(wd,father,0);
student pppp(ljq,mather);
student mku(shenzhenzw,xxy,9147);
student tin(maoming,xsl,9348);*/
kh.show();
return 0;
}