主题:谁能帮我调试这个程序
刚学了抽象类和虚函数,这个程序过不了,大家帮忙看是什么问题,谢谢!!!!
//process.h
class process
{
public:
virtual void print()=0;
};
//person.h
#include<string.h>
#include"process.h"
class person : public process
{
private:
char *name;
char sex[5];
public:
person(){name=NULL;strcpy(sex,"男");}
person(const person &ob)
{
name=new char[strlen(ob.name)+1];
strcpy(name,ob.name );
strcpy(sex,ob.sex);
}
~person(){delete []name;}
void setp()
{
char na[30];
cout<<"Input name ";cin>>na;
name=new char[strlen(na)+1];
strcpy(name,na);
cout<<"Input sex ";cin>>sex;
}
virtual void print()
{cout<<name<<","<<sex;}
};
//student.h
#include"person.h"
#include<string.h>
class student : public person
{
private:
char *department;
char *major;
int score;
public:
student(){department=NULL;major=NULL;}
student(const student &ob)
{
department=new char[strlen(ob.department )+1];
strcpy(department,ob.department );
major=new char[strlen(ob.major )+1];
strcpy(major,ob.major );
}
~student(){delete []department;delete []major;}
void sets();
void print();
};
void student::sets()
{
char dp[30];
char mj[30];
cout<<"Input department ";cin>>dp;
department=new char [strlen(dp)+1];
strcpy(department,dp);
cout<<"Input major ";cin>>mj;
major=new char[strlen(mj)+1];
strcpy(major,mj);
cout<<"Input score ";cin>>score;
}
void student::print()
{
person::print();
cout<<",study at "<<department<<" department,major at "<<major<<",score is "<<score;
cout<<endl;
}
//xzcexp807.cpp
#include<iostream.h>
#include"student.h"
void main()
{
process *p;
person ps;
student st;
ps.setp();
st.sets();
p=&ps;
p->print();
p=&st;
p->print();
}
//process.h
class process
{
public:
virtual void print()=0;
};
//person.h
#include<string.h>
#include"process.h"
class person : public process
{
private:
char *name;
char sex[5];
public:
person(){name=NULL;strcpy(sex,"男");}
person(const person &ob)
{
name=new char[strlen(ob.name)+1];
strcpy(name,ob.name );
strcpy(sex,ob.sex);
}
~person(){delete []name;}
void setp()
{
char na[30];
cout<<"Input name ";cin>>na;
name=new char[strlen(na)+1];
strcpy(name,na);
cout<<"Input sex ";cin>>sex;
}
virtual void print()
{cout<<name<<","<<sex;}
};
//student.h
#include"person.h"
#include<string.h>
class student : public person
{
private:
char *department;
char *major;
int score;
public:
student(){department=NULL;major=NULL;}
student(const student &ob)
{
department=new char[strlen(ob.department )+1];
strcpy(department,ob.department );
major=new char[strlen(ob.major )+1];
strcpy(major,ob.major );
}
~student(){delete []department;delete []major;}
void sets();
void print();
};
void student::sets()
{
char dp[30];
char mj[30];
cout<<"Input department ";cin>>dp;
department=new char [strlen(dp)+1];
strcpy(department,dp);
cout<<"Input major ";cin>>mj;
major=new char[strlen(mj)+1];
strcpy(major,mj);
cout<<"Input score ";cin>>score;
}
void student::print()
{
person::print();
cout<<",study at "<<department<<" department,major at "<<major<<",score is "<<score;
cout<<endl;
}
//xzcexp807.cpp
#include<iostream.h>
#include"student.h"
void main()
{
process *p;
person ps;
student st;
ps.setp();
st.sets();
p=&ps;
p->print();
p=&st;
p->print();
}