duibi a.cpp

来自「C语言相关程序」· C++ 代码 · 共 133 行

CPP
133
字号
#include"iostream.h"
#include"string.h"
class person
{
	protected:
	    char *name;
		int  id;
	public:
	  person(char *a,int d)
		{
			name = new char[strlen(a)+1];
			strcpy(name,a);
			id = d;
		}
	 ~person()
		{
			delete []name;
		}
	  void show()
		{
			cout<<"姓名是:"<<name<<endl;
			cout<<"id好号是:"<<id<<endl;
		}

};

class teacher:public person
{
	private:
		char *Degree;
		char *dep;
	public:
		teacher(char *a,int d,char *De,char *dp):person(a,d)
		{
			Degree = new char[strlen(De)+1];
			 strcpy(Degree,De);
			dep = new char[strlen(dp)+1];
			strcpy(dep,dp);
		}
		~teacher ()
		{
			delete []Degree;
			delete []dep;
		}
		void show()
		{
			person::show();
			cout<<"Degree是:"<<Degree<<endl;
			cout<<"dep是:"<<dep<<endl;
		}
};

class student:public person
{
	protected:
	   int old;
	   char *sno;
	public:
		//test by ls
		student(char *a,int d,int o,char *s):/*public*/ person(a,d)
		{
			sno = new char[strlen(s)+1];
			strcpy(sno,s);
			old = o;
		}
		~student()
		{
			delete []sno;
		}
		void show()
		{
		 person::show();
		 cout<<"年龄是:"<<old<<endl;
		 cout<<"sno:是:"<<sno<<endl;
		}

};

class stud
{
	protected:
         char *addr;
         int  tel;
	public:
	    stud(char *ad,int te)
		{
			 //by ls
			 //addr = new [strlen(ad)+1];
			 addr = new char[strlen(ad)+1];
			 tel = te;
		}
		~stud()
		{
			delete []addr;
		}
		void show()
		{
			cout<<"地址是:"<<addr<<endl;
			cout<<"电话是:"<<tel<<endl;
		}

};
//by ls
class /*score()*/score:public student, public stud
{
	private:
		double math;
		double eng;
	public:
		//by ls
		score(double m,double e,char *a,int d,int o,char *s,char *ad,int te):student(a,d,o,s),stud(ad,te)//student(a,b,c),stud(d,e)
		{
			math = m;
			eng = e;
		}
		void show()
		{
			student::show();
			stud::show();
			cout<<"数学成绩是:"<<math<<endl;
			cout<<"eng 是:"<<eng<<endl;
		}
};

void main()
{
   //by ls
  //score(23,26,"wangdingguo",65,23,"dsgecid","adfadfgaet",1335679);
  //score.show();
	score kk(23,26,"wangdingguo",65,23,"dsgecid","adfadfgaet",1335679);
	kk.show();
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?