Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2342151
  • 博文数量: 816
  • 博客积分: 10000
  • 博客等级: 上将
  • 技术积分: 5010
  • 用 户 组: 普通用户
  • 注册时间: 2008-12-17 17:57
文章分类

全部博文(816)

文章存档

2011年(1)

2008年(815)

分类:

2008-12-17 18:02:00

unix.h代码:
// unix.h




#include "iostream"
#include "string.h"
using namespace std;
 char* strsave(char *s)
{
char *p;
p=new char[strlen(s)+1];
strcpy(p,s);
return p;
}

class data_total
{
private:
char *last_name;
char *first_name;
char *street_address;
char *street;
char *city;
char *zip;
public:
data_total()
{
last_name=NULL;
first_name=NULL;
street_address=NULL;
city=NULL;
street=NULL;
zip=NULL;
}
data_total(char *ln,char *fn,char *st,char *cty,char *str,char *zp)
{
last_name=strsave(ln);
first_name=strsave(fn);
street_address=strsave(st);
city=strsave(cty);
street=strsave(str);
zip=strsave(zp);
}
~data_total()
{
delete last_name;
delete first_name;
delete street_address;
delete city;
delete street;
delete zip;
}
void print()
{
cout<<"\n"< }
};

class student:virtual public data_total
{
private:
char *major;
int id_name;
int level;
public:
student(char *ln,char *fn,char *st,char *cty,char *str,char* zp,char *ma,int id,int le)
:data_total(ln,fn,st,cty,str,zp)
{
major=strsave(ma);
id_name=id;
level=le;
}
~student()
{
    delete major;
}
void print();
};

void student::print()
{
data_total::print();
cout<<"the student's major is "< cout<<"his id_name is "<}

class employee:virtual public data_total
{
private:
char *dept;
float wage;
public:
employee(char *ln,char *fn,char *st,char *cty,char *str,char *zp,char *dp,float wa)
:data_total(ln,fn,st,cty,str,zp)
{
dept=strsave(dp);
wage=wa;
}
~employee()
{
delete dept;
}
void print();
};
void employee::print()
{
data_total::print();
cout<<"the department is "<}

class professor:virtual public employee
{
private:
float salary;
public:
professor(char *ln,char *fn,char *st,char *cty,char *str,char *zp,char *dp,float sal):
employee(ln,fn,st,cty,str,zp,dp,sal)
{};
void print();
};

void professor::print()
{
data_total::print();
employee::print();
cout<<"the salary is"<}

class student_part:public student,public employee
{
public:
student_part(char *ln,char *fn,char *st,char *cty,char *str,char *zp,char *ma,int id, int le,char *dep,float wa)    /*wa 是float型!*/
:student(ln,fn,st,cty,str,zp,ma,id,le),employee(ln,fn,st,cty,str,zp,dep,wa)
{}
void print();
};

void student_part::print()
{
student::print();
employee::print();
}


pc176.cpp代码:
// pc176.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include "unix.h"

int _tmain(int argc, _TCHAR* argv[])
{
student my_student("George","Smith","1234 Park Lane","Colorado springs","Co.","80907","Computer Science",1234,4);
employee my_employee("Sears","Stella","1234 Silver Lane","Manitou springs","Co","12345","Electrical Engineer",720);
professor my_professor("Jones","Robert","12345678 ABC Lane","Colorado springs","Co.","80907","Computer Scinece",222.2);
student_part my_part("Robinmsion","Steer","7654321 DEF Lane","Colorado springs","Co.","80907","Computer Science",1234,4,"Electrical Engineer",5.80);
my_student.print();
my_employee.print();
my_professor.print();
my_part.print();

return 0;
}

1>c:\users\nopassword\documents\visual studio 2005\projects\pc176\pc176\pc176.cpp(11) : warning C4305: “参数”: 从“double”到“float”截断
1>c:\users\nopassword\documents\visual studio 2005\projects\pc176\pc176\pc176.cpp(12) : warning C4305: “参数”: 从“double”到“float”截断

--------------------next---------------------

阅读(1184) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~