//Cube.h
class Cube{
public:
Cube(double aside=1.0);
double getSide();
void setSide(double aside);
private:
double side;
};
//Cube.cpp
#include "Cube.h"
Cube::Cube(double aside):side(aside){
if(side<=0.0)
side=1.0;
}
double Cube::getSide(){
return side;
}
void Cube::setSide(double aside){
if(aside<=0.0)
aside=1.0;
side=aside;
}
//main.cpp
#include <iostream>
#include "Cube.h"
using namespace std;
int main(int argc,char *argv[]){
Cube box(5.0);
cout<<box.getSide();
//box.side=6.0 //不可以修改
box.setSide(6.0);
cout<<box.getSide();
system("PAUSE");
return EXIT_SUCCESS;
}