这段程序不能通过编译,我又找不出错在哪里,以及原因,希望大虾能帮忙解释一下错在哪里了,为什么,谢谢,!!!
#include <iostream.h>
#include <stdlib.h>
#include <string.h>
class Name
{
protected:
char *name;
public:
Name(char *n)
{
name=new char[strlen(n)+1];
strcpy(name,n);
};
virtual void disp()=0;
char* getName()
{
return name;
};
virtual ~Name()
{
delete name;
};
};
class Teacher:virtual protected Name
{
private:
int sumscore;
public:
Teacher(char *n,int s):Name(n)
{
sumscore=s;
};
void disp()
{
if(sumscore>5)
cout<<this->getName()<<"\t"<<sumscore<<endl;
};
};
class Student:virtual protected Name
{
private:
int score;
public:
Student(char* n,int s):Name(n)
{
score=s;
};
void disp()
{
if(score>90)
cout<<this->getName()<<"\t"<<score<<endl;
};
};
void main()
{
Name *p[2][3];
int i,j;
for(i=0;i<3;i++)
{
cout<<"第"<<i+1<<"条";
char n[20];
int num;
cout<<"请输入学生姓名:"; cin>>n;
cout<<"请输入学生成绩:"; cin>>num;
p[0][i]=new Student(n,num);
system("cls");
}
for(i=0;i<3;i++)
{
cout<<"第"<<i+1<<"条";
char n[20];
int num;
cout<<"教师姓名:"; cin>>n;
cout<<"请输入教师论文得分:"; cin>>num;
p[1][i]=new Teacher(n,num);
system("cls");
}
system("cls");
for(i=0;i<2;i++)
for(j=0;j<3;j++)
{
p[i][j]->disp();
delete p[i][j];
}
}