haihongyuan.com
海量文库 文档专家
全站搜索:
您现在的位置:首页 > 幼儿教育 > 幼儿读物幼儿读物

源程序

发布时间:2014-01-02 12:00:43  

#include <stdio.h>

#include <iostream>

#include<string>

using namespace std;

class People

{

public:

string name; //姓名 string sex; //性别 int age; //年龄 public:

void display()

{

cout<<"姓名:"<<name<<endl; cout<<"性别:"<<sex<<endl; cout<<"年龄:"<<age<<endl; }

};

class Old : public People //老人类 {

public:

string Retired;

public:

void show()

{

display();

cout<<"退休单位:"<<Retired<<endl; }

};

class Major : public People //成人类 {

public:

string Unit;

string post;

long num;

float money;

public:

void show()

{

display();

cout<<"工号:"<<num<<endl; cout<<"工资:"<<money<<endl;

cout<<"职务:"<<post<<endl;

cout<<"工作单位:"<<Unit<<endl; }

};

class Child : public People //儿童类 {

public:

int phone;

public:

void show()

{

display();

cout<<"监护人联系电话:"<<phone<<endl; }

};

class Lchild : public Child //学龄期儿童 {

public:

string school;

int num;

public:

void show2()

{

show();

cout<<"学号:"<<num<<endl;

cout<<"学校:"<<school<<endl; }

};

class Mchild:public Child //学龄前儿童 {

public:

string kd;

public:

void show2()

{

show();

cout<<"幼儿园:"<<kd<<endl;

}

};

void main()

{

int Pn,On,Mn,Cn,Lcn,Mcn;

Pn=0,On=0,Mn=0,Cn=0,Lcn=0,Mcn=0;

People p;

Pn++;

p.name="张华";p.sex="女";p.age=40;

Old op;

Pn++;On++;

op.name="王成光";op.sex="男";op.age=70;op.Retired="河南省安阳市文峰区房产分局"; Old op1;

Pn++;On++;

op1.name="张方玉";op1.sex="男";op1.age=67;op1.Retired="河南省安阳市眼科医院";

Major mp;

Mn++;Pn++;

mp.name="王一一";mp.sex="女";mp.age=40;mp.num=100861102;mp.money=3000;mp.post="职员";mp.Unit="中国移动";

Child cp;

Cn++;Pn++;

cp.name="张云";cp.sex="女";cp.age=7;cp.phone=2971726;

Lchild lcp;

Lcn++;Cn++;Pn++;

lcp.name="张明宇";lcp.sex="男";lcp.age=9;lcp.phone=3939025;lcp.num=103110122;lcp.school="安阳一中";

Mchild mcp;

Mcn++;Cn++;Pn++;

mcp.name="张浩鑫";mcp.sex="男";mcp.age=3;mcp.phone=2971060;mcp.kd="幼儿园";

cout<<"所创建的信息如下所示:"<<endl<<endl;

p.display();

cout<<endl<<endl;

op.show();

cout<<endl<<endl;

op1.show();

cout<<endl<<endl;

mp.show();

cout<<endl<<endl;

cp.show();

cout<<endl<<endl;

mcp.show2();

cout<<endl<<endl;

} lcp.show2(); cout<<"该实验过程中共创造了"<<Pn<<"个People对象"<<endl; cout<<"该实验过程中共创造了"<<On<<"个Old对象"<<endl; cout<<"该实验过程中共创造了"<<Mn<<"个Major对象"<<endl; cout<<"该实验过程中共创造了"<<Cn<<"个Child对象"<<endl; cout<<"该实验过程中共创造了"<<Lcn<<"个Lchild对象"<<endl; cout<<"该实验过程中共创造了"<<Mcn<<"个Mchild对象"<<endl;

网站首页网站地图 站长统计
All rights reserved Powered by 海文库
copyright ©right 2010-2011。
文档资料库内容来自网络,如有侵犯请联系客服。zhit326@126.com