#include<iostream>
#include<string.h>
#include<stdlib.h>
using namespace std;
const int capacity=10;
class Student
{
public:
Student()
{
age=weight=height=0;
name=new char [capacity];
sex=new char [capacity];
subject=new char [capacity];
}
~Student()
{
delete [] name;
delete [] sex;
delete [] subject;
}
void push(int a,int b,int c,char *s1,char *s2,char *s3)
{
age=a;weight=b;height=c;
strcpy(name,s1);
strcpy(sex,s2);
strcpy(subject,s3);
}
void pop()
{
cout<<"姓名:"<<name<<endl;
cout<<"性别:"<<sex<<endl;
cout<<"身高:"<<height<<endl;
cout<<"体重:"<<weight<<endl;
cout<<"年龄:"<<age<<endl;
cout<<"专业:"<<subject<<endl;
}
protected:
int age;
char *name;
char *sex;
int weight;
int height;
char *subject;
private:
};
class Graduate:public Student
{
public:
Graduate()
{
time=0;
type=new char [capacity];
direction=new char [capacity];
}
~Graduate()
{
delete [] type;
delete [] direction;
}
void push1(int a1,char *str1,char *str2)
{
time=a1;
strcpy(type,str1);
strcpy(direction,str2);
}
void pop1()
{
cout<<"研究类型:"<<type<<endl;
cout<<"研究方向:"<<direction<<endl;
cout<<"参加会议的次数:"<<time<<endl;
}
private:
int time;
char *type;
char *direction;
};
int main()
{
Graduate p[3];int i;
p[0].push(22,48,164,"Li Hua","Female","Physics");
p[0]. push1(3,"Atom","Physics");
p[1].push(23,67,173,"Xiaoming","Male","Biology");
p[1].push1(4,"Protein", "Biology");
p[2].push(22,80,183,"Li Qiang","Male","Chemistry");
p[2].push1(3,"Gene","Chemistry");
cout<< "Please enter the student ID of the student you want to view:"<<endl;cin>>i;
p[i-1].pop();
p[i-1].pop1();
return 0;
}
#include<string.h>
#include<stdlib.h>
using namespace std;
const int capacity=10;
class Student
{
public:
Student()
{
age=weight=height=0;
name=new char [capacity];
sex=new char [capacity];
subject=new char [capacity];
}
~Student()
{
delete [] name;
delete [] sex;
delete [] subject;
}
void push(int a,int b,int c,char *s1,char *s2,char *s3)
{
age=a;weight=b;height=c;
strcpy(name,s1);
strcpy(sex,s2);
strcpy(subject,s3);
}
void pop()
{
cout<<"姓名:"<<name<<endl;
cout<<"性别:"<<sex<<endl;
cout<<"身高:"<<height<<endl;
cout<<"体重:"<<weight<<endl;
cout<<"年龄:"<<age<<endl;
cout<<"专业:"<<subject<<endl;
}
protected:
int age;
char *name;
char *sex;
int weight;
int height;
char *subject;
private:
};
class Graduate:public Student
{
public:
Graduate()
{
time=0;
type=new char [capacity];
direction=new char [capacity];
}
~Graduate()
{
delete [] type;
delete [] direction;
}
void push1(int a1,char *str1,char *str2)
{
time=a1;
strcpy(type,str1);
strcpy(direction,str2);
}
void pop1()
{
cout<<"研究类型:"<<type<<endl;
cout<<"研究方向:"<<direction<<endl;
cout<<"参加会议的次数:"<<time<<endl;
}
private:
int time;
char *type;
char *direction;
};
int main()
{
Graduate p[3];int i;
p[0].push(22,48,164,"Li Hua","Female","Physics");
p[0]. push1(3,"Atom","Physics");
p[1].push(23,67,173,"Xiaoming","Male","Biology");
p[1].push1(4,"Protein", "Biology");
p[2].push(22,80,183,"Li Qiang","Male","Chemistry");
p[2].push1(3,"Gene","Chemistry");
cout<< "Please enter the student ID of the student you want to view:"<<endl;cin>>i;
p[i-1].pop();
p[i-1].pop1();
return 0;
}