資源簡介
C++實戰源碼-適配器模式的簡單應用(入門級實例225).zip
代碼片段和文件信息
//?adapter.cpp?:?Defines?the?entry?point?for?the?console?application.
//
#include?“stdafx.h“
#include?“ioStream.h“
#include?“string.h“
typedef?char?String[30];
struct?Point
{
int?xy;
};
class?Car?{
private:
String?name; //表示名稱
????double?speed; //表示速度
public:
double?getSpeed(){
return?speed;
}
void?setSpeed(double?sp)
{
speed?=?sp;
}
char?*getName()
{
return?name;
}
void?setName(String?Name)
{
strcpy(nameName);
}
public:
virtual?void?toString()?{
????????cout?<“車名:“?<????????<“速度:“?<????}
};
class?GPS?{
????virtual?Point?getLocation()?=?0;//提供定位功能
};
class?GPSCar?:public?Car??GPS?{
public:
Point?getLocation()?{//利用汽車的速度來確定汽車的位置
????????Point?point;
point.x?=?getSpeed();
point.y?=?getSpeed();
????????return?point;
????}
????void?toString()?{
Car::toString();
????????cout?<“坐標:(“?<????}
};
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????1428??2010-10-14?19:37??adapter\adapter.cpp
?????文件????????4548??2010-10-14?19:14??adapter\adapter.dsp
?????文件?????????539??2010-10-14?19:14??adapter\adapter.dsw
?????文件?????????294??2010-10-14?19:14??adapter\StdAfx.cpp
?????文件?????????769??2010-10-14?19:14??adapter\StdAfx.h
- 上一篇:C++實戰源碼-遍歷磁盤目錄
- 下一篇:C++實戰源碼-在指定目錄下查找文件
評論
共有 條評論