概述
#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,"李华","女","物理");
p[0].push1(3,"原子","物理");
p[1].push(23,67,173,"小明","男","生物");
p[1].push1(4,"蛋白质","生物");
p[2].push(22,80,183,"李强","男","化学");
p[2].push1(3,"基因","化学");
cout<<"请输入您要查看学生的学号:"<<endl;cin>>i;
p[i-1].pop();
p[i-1].pop1();
return 0;
}
最后
以上就是老迟到香氛为你收集整理的研究生类的全部内容,希望文章能够帮你解决研究生类所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复