编程处理教师的基本情况。

要求:

1、定义一个“person”类。用来存储及处理人的姓名、性别、年龄,成员函数自定;

2、定义“teacher”类,公有继承“person”类用来存储教师所在学院、所学专业、学历、学位、职称、教龄等,成员函数自定。

3、处理程序,主要包含:

⑴显示姓名、性别、年龄函数:既能显示person对象的姓名、性别、年龄,又能显示teacher对象的姓名、性别、年龄(用person引用对象为形參);

⑵显示教师所在学院、所学专业、学历、学位、职称、教龄的函数;

⑶ main()函数:分别定义persor对象及teacher对象,并输入不同对象相关值。调用成员函数设置对象的值,调用显示函数显示对应值。

#ifndef __person__person__
#define __person__person__
#include<iostream>
using namespace std;
#include<string.h>
class person
{
protected:
char *name;
char *sex;
int age;
public:
person(char *na,char *se,int ag);
void set_person(char *na,char *se,int ag);
char* get_name()
{return name;}
char* get_sex()
{return sex;}
int get_age()
{return age;}
void print();
~person()
{delete []name;delete []sex;} }; person::person(char *na,char *se,int ag)
{ name=new char[strlen(na)+1];
strcpy(name,na);
sex=new char[strlen(se)+1];
strcpy(sex,se);
age = 0;
} void person:: set_person(char *na,char *se,int ag)
{
name=new char[strlen(na)+1];
strcpy(name,na);
sex=new char[strlen(se)+1];
strcpy(sex,se);
age=ag;
} void person:: print()
{
for(int i = 0;i<=strlen(name);i++)
{
cout<<name[i];
}
cout<<endl;
for(int i = 0;i<=strlen(sex);i++)
{
cout<<sex[i];
}
cout<<endl;
cout<<"age:"<<age<<endl;
cout<<endl; } #endif /* defined(__person__person__) */
#ifndef person_teacher_h
#define person_teacher_h #include"person.h"
class teacher:public person
{
protected:
char *college;//学院
char *speciality;//专业
char *school;//学历
char *degree;//学位
char *title;//职称
int teacherage;//教龄
public:
teacher(char *na,char* se,int ag,char *co,char *sp,char* sc,char* de,char* ti,int te);
void set_t(char *na,char* se,int ag,char *co,char *sp,char* sc,char* de,char* ti,int te);
char* get_college()
{return college;}
char* get_speciality()
{return speciality;}
char* get_school()
{return school;}
char* get_degree()
{return degree;}
char* get_title()
{return title;}
int get_teacher_age()
{return teacherage;}
~teacher();
void print_t(person&p);
}; teacher::teacher(char *na,char* se,int ag,char *co,char *sp,char* sc,char* de,char* ti,int te):person(na,se,ag)
{
//person::set_person(na, se, ag);
college=new char[strlen(co)+1];
strcpy(college,co);
speciality=new char[strlen(sp)+1];
strcpy(speciality,sp);
school=new char[strlen(sc)+1];
strcpy(school,sc);
degree=new char[strlen(de)+1];
strcpy(degree,de);
title=new char[strlen(ti)+1];
strcpy(title,ti);
teacherage =0;
} void teacher:: set_t(char *na,char* se,int ag,char *co,char *sp,char* sc,char* de,char* ti,int te)
{
name=new char[strlen(na)+1];
strcpy(name,na);
sex=new char[strlen(se)+1];
strcpy(sex,se);
age=ag; college=new char[strlen(co)+1];
strcpy(college,co);
speciality=new char[strlen(sp)+1];
strcpy(speciality,sp);
school=new char[strlen(sc)+1];
strcpy(school,sc);
degree=new char[strlen(de)+1];
strcpy(degree,de);
title=new char[strlen(ti)+1];
strcpy(title,ti);
teacherage =te; }
teacher::~teacher()
{ delete []college;
delete []speciality;
delete []school;
delete []degree;
delete [] title;
} void teacher:: print_t(person &p)
{
p.print();
cout<<"-------------------"<<endl;
for(int i = 0;i<=strlen(college);i++)
{
cout<<college[i];
}
cout<<endl;
for(int i = 0;i<=strlen(speciality);i++)
{
cout<<speciality[i];
}
cout<<endl;
for(int i = 0;i<=strlen(school);i++)
{
cout<<school[i];
}
cout<<endl;
for(int i = 0;i<=strlen(degree);i++)
{
cout<<degree[i];
}
cout<<endl;
for(int i = 0;i<=strlen(title);i++)
{
cout<<title[i];
}
cout<<endl; cout<<teacherage<<endl;
cout<<endl;
}
void fun(person &p)
{
p.print();
cout<<endl;
} #endif
#include "teacher.h"
//#include"person.h"
int main()
{
person p("s","nv",22);
teacher T("张老师","女",44,"计科","网络","本科","博士","教授",20);
T.print_t(p);
T.set_t("张老师","女",44,"计科","网络","本科","博士","教授",20);
T.print_t(p);
cout<<T.get_name()<<endl;
cout<<T.get_sex()<<endl;
cout<<T.get_age()<<endl;
cout<<T.get_college()<<endl;
cout<<T.get_degree()<<endl;
cout<<T.get_school()<<endl;
cout<<T.get_speciality()<<endl;
cout<<T.get_title()<<endl;
cout<<T.get_teacher_age()<<endl;
cout<<"--------------------"<<endl;
fun(p);
return 0;
} //int main()
//{
// person p("s","nv",22);
// p.print();
// p.set_person("w","female",44);
// p.print();
// return 0;
//}

[c++]基类对象作为函数參数(赋值兼容规则)的更多相关文章

  1. Effective JavaScript Item 55 接受配置对象作为函数參数

    接受配置对象作为函数參数 尽管保持函数接受的參数的顺序非常重要,可是当函数可以接受的參数达到一定数量时.也会让用户非常头疼: var alert = new Alert(100, 75, 300, 2 ...

  2. C++容器类对象函数參数问题

    总之中的一个句话:容器类对象作为函数參数,与整数类型作为函数參数的传递特性同样. 验证程序 #include "stdafx.h" #include <iostream> ...

  3. 各种python 函数參数定义和解析

    python 中的函数參数是赋值式的传递的,函数的使用中要注意两个方面:1.函数參数的定义过程,2.函数參数在调用过程中是怎样解析的. 首先说一下在python 中的函数调用过程是分四种方式的.这里且 ...

  4. C++ - 虚基类、虚函数与纯虚函数

    虚基类       在说明其作用前先看一段代码 class A{public:    int iValue;}; class B:public A{public:    void bPrintf(){ ...

  5. C++中基类对象的引用

    代码: #include <iostream> #include <cstdio> using namespace std; class A{ public: void pri ...

  6. C++派生类中如何初始化基类对象(五段代码)

    今天收到盛大的面试,问我一个问题,关于派生类中如何初始化基类对象,我在想派生类对于构造函数不都是先构造基类对象,然后在构造子类对象,但是如果我们在成员初始化列表先初始化派生类的私有成员,在函数内去调用 ...

  7. JavaScript的最大函数參数长度和最大栈深度检測

    一般代码也许不会涉及最大參数长度和最大栈深度,但某些特殊场合,检測这两个參数还是有必要的.比如:用递归计算斐波那契数列的第n个值,不了解最大栈深度,难免显得肤浅.又比如:将一串charCode转成St ...

  8. 关于MFC中重载函数是否调用基类相对应函数的问题

    在重载CDialog的OnInitDialog()函数的时候,在首行会添加一句:CDialongEx::OnInitDialog();语句,这是为什么呢?什么时候添加,什么时候不添加? 实际上,我们在 ...

  9. 业务基类对象BaseBLL

    using System; using System.Collections; using System.Data; using System.Text; using System.Collectio ...

随机推荐

  1. git的学习笔记整理

    Git学习较好的网址:http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/001373 ...

  2. [湖南师大集训2018 7 26] hunger 解题报告 (SPFA)

    饿 (hungry.pas/c/cpp) [背景描述] 给出

  3. MyBatis、JDBC、Hibernate区别

    从层次上看,JDBC是较底层的持久层操作方式,而Hibernate和MyBatis都是在JDBC的基础上进行了封装使其更加方便程序员对持久层的操作. 从功能上看, JDBC就是简单的建立数据库连接,然 ...

  4. Ionic2中的Navigation.md

    1. 概述 为了能够得到同原生应用类似的导航效果,Ionic创建了几个navagation组件来实现pages之间的导航操作,这种导航跟原生Angular2中的route机制是不一样的,我们可以借助于 ...

  5. [BJOI2014]大融合 LCT维护子树信息

    Code: #include <cstdio> #include <algorithm> #include <cstring> #include <strin ...

  6. vue的webpack打包

    一个完整的项目离不开 开发环境 生产环境 测试环境 这三个环境 首先解释一下这三个环境的含义 开发环境:开发环境是程序猿们专门用于开发的服务器,配置可以比较随意,为了开发调试方便,一般打开全部错误报告 ...

  7. 理解JavaScript Call()函数原理。

    最近在做面试题的过程中偶然碰到关于call函数的问题.然后再百度上查了查.偶然看到一篇文章:JavaScript中的call.apply.bind深入理解 抛开其对call函数基本概念的介绍还有其他原 ...

  8. TCP服务器如何区分不同的用户

    CS架构:使用SOCKET(一般是一个整数),当服务器侦听到连接请求的时候,accept会返回一个SOCKET(用于识别不同的连接,可以理解成,SOCKET是区分不同连接的ID).当服务器listen ...

  9. [Bug]Python3.x SyntaxError: 'ascii' codec can't decode byte 0xe4 in position

    安装arch后就没再用python了 昨天管服务器的大佬在跑贝叶斯分类器的时候发现正确率有问题 我赶紧去做优化,然后就有这样的报错 Python 3.6.4 (default, Jan 5 2018, ...

  10. iotop---监控磁盘I/O 使用状况

    iotop命令是一个用来监视磁盘I/O使用状况的top类工具.iotop具有与top相似的UI,其中包括PID.用户.I/O.进程等相关信息.Linux下的IO统计工具如iostat,nmon等大多数 ...