工程由School_Source.h ,School_Source.cpp,Main.cpp构成
请大家在自己的机子上运行以下:
此程序有4个警告;我不能解决,希望大家帮助!
//School_Source.h
{
private:
char* P_name; char* P_city;
char* P_state; char* P_zip;
public:
DateSou();
DateSou(char *name,char* city,char*state,char*zip);
~DateSou();
virtual void print();
protected:
char* strSave(char*s);
};
//////////////////////////////////////////////////////////////////////////////////
class Stu:virtual public DateSou
{
private:
char* P__major;
int __idName;
int __level;
public:
Stu(char*name,char*city,char*state,char*zip,char*major,int idName,int level)
:DateSou(name,city,state,zip)
{ P__major=strSave(major); __idName=idName; __level=level; }
Stu(char*major,int idName,int level)
{ P__major=strSave(major); __idName=idName; __level=level; }
~Stu()
{ delete [] P__major;}
virtual void print();
protected:
void disp();
};
////////////////////////////////////////////////////////////////////////////////////
class Staff:virtual public DateSou
{
private:
char* P__dept;
float __hourlyWage;
public:
Staff(char*name,char*city,char*state,char*zip,char*dept,float hourlyWage)
:DateSou(name,city,state,zip)
{ P__dept=strSave(dept); __hourlyWage=hourlyWage;}
Staff(char*dept,float hourlyWage)
{ P__dept=strSave(dept); __hourlyWage=hourlyWage;}
~Staff()
{ delete []P__dept;}
virtual void print();
protected:
void disp();
};
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
class StuStaff :public Stu ,public Staff
{
public:
StuStaff(char*name,char*city,char*state,char*zip,char*major,
int idName,int level, char*dept,float hourlyWage)
:DateSou(name,city,state,zip),
Stu(major,idName,level), Staff(dept,hourlyWage)
{}
virtual void print();
};
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//School_Source.cpp
#include"School_Source.h"
#include<iostream>
#include<string>
using namespace std;
/////////////////////////////////////////////////////////////////////////////////
DateSou::DateSou()
{
P_name=NULL; P_city=NULL;
P_state=NULL; P_zip=NULL;
}
DateSou::DateSou(char *name, char *city, char *state, char *zip)
{
P_name=strSave(name); P_city=strSave(city);
P_state=strSave(state); P_zip=strSave(zip);
}
DateSou::~DateSou()
{
delete P_name; delete P_city;
delete P_state; delete P_zip;
}
void DateSou::print()
{
cout<<endl<<endl<<P_name<<endl<< P_city<<", ";
cout<<P_state<<" "<<P_zip;
}
char* DateSou::strSave(char*s)
{
char*P; P=new char[strlen(s)+1];
strcpy(P,s);
return P;
}
/////////////////////////////////////////////////////////////////
void Stu::print()
{
DateSou::print();
disp();
}
void Stu::disp()
{
cout<<endl;
cout<<"\major:"<<P__major<<" ";
cout<<"\idName:"<<__idName<<" ";
cout<<"\level:"<<__level;
}
////////////////////////////////////////////////////////////////////////////
void Staff::print()
{
DateSou::print();
disp();
}
void Staff::disp()
{
cout<<"\nDepartment:"<<P__dept;
cout<<"\nhourlyWage:"<<__hourlyWage;
}
///////////////////////////////////////////////////////////////////////////////
void StuStaff::print()
{
DateSou::print();
Stu::disp();
Staff::disp();
cout<<endl;
}
//Main.cpp
#include"School_Source.h"
//using namespace std;
void main()
{
Stu OStu("张三", "北京", "Stu", "1860", "大学语文",17951,4);
Staff OStaff("李四", "上海", "Staff", "10011", "机器人自动化",
StuStaff OStuStaff("王五", "西安", "StuStaff", "12315","历史",11111,3,
"现代哲学",
OStu.print();
OStaff.print();
OStuStaff.print();
}