carysu@126.com

carysu@126.com
posts - 11, comments - 0, trackbacks - 0, articles - 0

 


/*
多态的实现。
*/

#include 
<iostream>
#include 
<string>

using namespace std;


class cbuilding
{

    
string name;
    
//char * name;
public:
    
void set(string strName);
    
void display()
    
{
        cout
<<"建筑是"<< name<<endl;
    }

}
;

void cbuilding::set(string str)
{
    name 
= str;
}


class bridge:public cbuilding
{

    
float bridgeLength;
public:
    
void setlength(float length)
    
{
    bridgeLength 
= length;
    }

    
void display()
    
{
        cbuilding::display();
        cout
<<"桥的长度是"<<bridgeLength<<endl;
    }

}
;
void main()
{
    bridge b;
    
//string s1="zhongguo";
    b.set("杭州钱塘江三桥");
    b.setlength(
200.003);
    b.display();
    
return;
}


/*
多态的实现。
*/
#include <iostream>
#include <string>

using namespace std;


class cbuilding
{

 string name;
 //char * name;
public:
 void set(string strName);
 void display()
 {
  cout<<"建筑是"<< name<<endl;
 }
};

void cbuilding::set(string str)
{
 name = str;
}

class bridge:public cbuilding
{

 float bridgeLength;
public:
 void setlength(float length)
 {
 bridgeLength = length;
 }
 void display()
 {
  cbuilding::display();
  cout<<"桥的长度是"<<bridgeLength<<endl;
 }
};
void main()
{
 bridge b;
 //string s1="zhongguo";
 b.set("杭州钱塘江三桥");
 b.setlength(200.003);
 b.display();
 return;
}

posted @ 2011-07-16 16:11 susu 阅读(103) | 评论 (0)编辑 收藏

仅列出标题
共2页: 1 2