基本操作 原题
#include
#include
using namespace std;
class Point{
double x,y;
public:
// ERROR **********found**********
Point(double m=0.0, double n=0.0):m(x), n(y){}
friend double distanceBetween(const Point& p1, const Point& p2);
};
// ERROR **********found**********
double Point::distanceBetween(const Point& p1, const Point& p2){//返回两点之间的距离
double dx=p1.x-p2.x;
double dy=p1.y-p2.y;
return sqrt(dx*dx+dy*dy);
}
int main(){
Point f1(0,0), f2(1,1);
// ERROR **********found**********
cout<
基本操作 答案
#include
#include
using namespace std;
class Point{
double x,y;
public:
// ERROR **********found**********
Point(double m=0.0, double n=0.0):x(m), y(n){}
friend double distanceBetween(const Point& p1, const Point& p2);
};
// ERROR **********found**********
double distanceBetween(const Point& p1, const Point& p2){//返回两点之间的距离
double dx=p1.x-p2.x;
double dy=p1.y-p2.y;
return sqrt(dx*dx+dy*dy);
}
int main(){
Point f1(0,0), f2(1,1);
// ERROR **********found**********
cout<
简单应用 原题
#include
using namespace std;
class Switchable{ //具有开、关两种状态的设备
bool is_on; //为 ture 表示“开”,为 false 表示“关”
public:
Switchable(): is_on(false){}
void switchOn(){ is_on=true; } //置为“开”状态
//**********found**********
void switchOff(){_________________________________}//置为“关”状态
bool isOn(){ return is_on; } //返回设备状态
//**********found**********
virtual const char *getDeviceName()__________; //返回设备名称的纯虚函数
};
class Lamp: public Switchable{
public:
//返回设备名称,用于覆盖基类中的纯虚函数
const char *getDeviceName(){ return "Lamp"; }
};
class Button{ //按钮
Switchable *device; //按钮控制的设备
public:
//**********found**********
Button(Switchable &dev): _______________{} //用参数变量的地址初始化device
bool isOn(){ return device->isOn(); } //按钮状态
void push(){ //按一下按钮改变状态
if(isOn()) device->switchOff();
//**********found**********
else ___________________________
}
};
int main(){
Lamp lamp;
Button button(lamp);
cout<<"灯的状态:"<<(lamp.isOn()? "开" : "关")<
简单操作 答案
#include
using namespace std;
class Switchable{ //具有开、关两种状态的设备
bool is_on; //为 ture 表示“开”,为 false 表示“关”
public:
Switchable(): is_on(false){}
void switchOn(){ is_on=true; } //置为“开”状态
//**********found**********
void switchOff(){is_on=false;}//置为“关”状态
bool isOn(){ return is_on; } //返回设备状态
//**********found**********
virtual const char *getDeviceName()=0; //返回设备名称的纯虚函数
};
class Lamp: public Switchable{
public:
//返回设备名称,用于覆盖基类中的纯虚函数
const char *getDeviceName(){ return "Lamp"; }
};
class Button{ //按钮
Switchable *device; //按钮控制的设备
public:
//**********found**********
Button(Switchable &dev): device(&dev){} //用参数变量的地址初始化device
bool isOn(){ return device->isOn(); } //按钮状态
void push(){ //按一下按钮改变状态
if(isOn()) device->switchOff();
//**********found**********
else device->switchOn();
}
};
int main(){
Lamp lamp;
Button button(lamp);
cout<<"灯的状态:"<<(lamp.isOn()? "开" : "关")<
综合应用 原题
//main.cpp
#include "MiniString.h"
#pragma warning (disable:4996)
ostream& operator<<(ostream& o,MiniString& s)
{
int len=strlen(s.str);
for(int i=0;i