C++初学问题
问题在什么地方
class Point
{
public:
void InitP(float xx=0,float yy=0){X=xx;Y=yy;}
void Move(float xOff,float yOff){X=X+xOff;Y=Y+yOff;}
float GetX(){return X;}
float Gety(){return Y;}
private:
float X,Y;
};
class Rectangle: public Point
{
public:
void InitR(float x,float y,float w,float h){InitP(x,y);W=w;H=h;}
float GetH(){return H;}
float GetW(){return W;}
private:
float W,H;
};
#include<iostream>
#include<math.h>
#include"Rectangle.h"
void main()
{
Rectangle rect;
rect.InitR(2,3,20,10);
rect.Move(3,2);
cout<<"The data of rect(X,Y,W,H):"<<endl;
cout<<GetX()<<",";
cout<<GetY()<<",";
cout<<GetW()<<",";
cout<<GetH()<<endl;
}
系统说E:\Learn\1.cpp(22) : fatal error C1083: Cannot open include file: 'Rectangle.h': No such file or directory
谢谢
参考答案:class Point
{
public:
void InitP(float xx=0,float yy=0){X=xx;Y=yy;}
void Move(float xOff,float yOff){X=X+xOff;Y=Y+yOff;}
float GetX(){return X;}
float Gety(){return Y;}
private:
float X,Y;
};
class Rectangle: public Point
{
public:
void InitR(float x,float y,float w,float h){InitP(x,y);W=w;H=h;}
float GetH(){return H;}
float GetW(){return W;}
private:
float W,H;
};
#include<iostream.h>
#include<math.h>
void main()
{
Rectangle rect;
rect.InitR(2,3,20,10);
rect.Move(3,2);
cout<<"The data of rect(X,Y,W,H):"<<endl;
cout<<rect.GetX()<<","; //成员函数必须要对象调用
cout<<rect.Gety()<<","; //你好想写错了,y是小写,不是大写
cout<<rect.GetW()<<",";
cout<<rect.GetH()<<endl;
}
这样就可以运行了