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

全部博文(816)

文章存档

2011年(1)

2008年(815)

分类:

2008-12-17 18:04:04

题目要求:
描述一个学校的情况,描述对象包括教师和学生。声明一个类People,其中包含成员变量name(姓名)、age(年龄)、add(地址)作为教师类和学生类的基类。在学生类中增加成员变量所在分院、年级,在教师类中增加
以下是我的程序代码:
#include
#include
class People
{
protected:
char *name;
int age;
char *addr;
public:
People(char *xname,char *xaddr,int xage)
{
name=xname;
addr=xaddr;
age=xage;
}
};
class Student:public People
{
private:
char *faculty;
char *grade;
public:
Student(char *xname,char *xaddr,int xage,char *xfaculty,char *xgrade);
void show();
~Student()
{cout<<"执行析构函数~Student()"<};
Student::Student(char *xname,char *xaddr,int xage,char *xfaculty,char *xgrade):People(*xname,*xaddr,xage)
{
faculty=xfaculty;
grade=xgrade;
}
void Student::show()
{
 cout<<"姓名:"< cout<<"年龄:"< cout<<"地址:"< cout<<"学院:"< cout<<"年级:"<}
class Teacher:public People
{
private:
char *major;
double salary;
public:
Teacher(char *xname,char *xaddr,int xage,char *xmajor,double xsalary);
void disp();
~Teacher()
{
cout<<"执行析构函数~Teacher()"< }
};
Teacher::Teacher(char *xname,char *xaddr,int xage,char *xmajor,double xsalary):People(*xname,*xaddr,xage)
{salary=xsalary;
major=xmajor;
}
void Teacher::disp()
{
cout<<"姓名:"< cout<<"年龄:"< cout<<"地址:"< cout<<"专业:"< cout<<"工资:"<}
void main()
{
Student obj1("Shirley","SLG",20,"信息学院","二年级");
Teacher obj2("LDP","沈阳师范大学",27,"中文系",1500);
}
编译的时候总是出现这么两个错误提示:
--------------------Configuration: fengrui - Win32 Debug--------------------
Compiling...
source.cpp
E:\软件\开发\VC\MSDev98\MyProjects\fengrui\source.cpp(29) : error C2664: '__thiscall People::People(char *,char *,int)' : cannot convert parameter 1 from 'char' to 'char *'
        Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
E:\软件\开发\VC\MSDev98\MyProjects\fengrui\source.cpp(55) : error C2664: '__thiscall People::People(char *,char *,int)' : cannot convert parameter 1 from 'char' to 'char *'
        Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
执行 cl.exe 时出错.
调了很久都没调出来,还请各位大侠指出我错哪里了啊.

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

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