天空飞鱼84 天空飞鱼84
关注数: 0 粉丝数: 15 发帖数: 3,264 关注贴吧数: 3
麻烦各位高手,输出的为什么和正确答案不一样,谢谢了,在线等! #include <iostream> #include <string.h> using namespace std; class String { public:  String();  String(const char *const);  String(const String &);  ~String();    char & operator[] (unsigned short offset);  char operator[] (unsigned short offset) const;  String operator+ (const String&);  void operator+=(const String&);  String & operator = (const String &);  unsigned short GetLen() const{return itsLen;}  const char * GetString() const{return itsString;} private:  String (unsigned short);  char * itsString;  unsigned short itsLen; }; String::String() {  itsString = new char[1];  itsString[0] = '\0';  itsLen = 0; } String::String (unsigned short len) {  itsString = new char[len + 1];  for (unsigned short i = 0; i <= len ; i++)  itsString[i] ='\0';  itsLen = len; } String::String(const char * const cString) {  itsLen = strlen(cString);  itsString = new char[itsLen + 1];  for(unsigned short i = 0;i < itsLen; i++)  itsString[i] =cString[i];  itsString[itsLen] ='\0'; } String::String(const String & rhs) {  itsLen = rhs.GetLen();  itsString = new char[itsLen + 1];  for(unsigned short i = 0 ; i < itsLen ; i++)   itsString[i] =rhs[i];  itsString[itsLen] ='\0'; } String::~String() {  delete [] itsString;  itsLen = 0; } String& String::operator =(const String & rhs) {  if(this == &rhs)   return *this;  delete[] itsString;  itsLen =rhs.GetLen();  itsString = new char[itsLen + 1];  for(unsigned short i = 0 ; i < itsLen ; i++ )   itsString[itsLen] = '\0';  return *this; } char & String::operator[] (unsigned short offset)  {  if(offset > itsLen)   return itsString[itsLen - 1];  else   return itsString[offset]; } char String::operator[] (unsigned short offset)  const
问一个麻烦点的问题,请大家耐心看看,小弟谢谢了 问一个麻烦点的问题 我把类的声放在一个。HPP的文件里,把类的定义放在一个。CPP的文件里 编译时,对书把能改的错误都改了,可是还是报错, 通不驼编译。是为什么? 作者: 天空飞鱼84 2007-3-7 07:47   回复此发言 -------------------------------------------------------------------------------- 2 回复:问一个麻烦点的问题 附程序,麻烦你看看了 这是类的声明 #include class Point { public: void SetX(int x) {itsX = x; } void SetY(int y) {itsY = y; } int GetX()const (return itsX;} int GetY()const {return itsY;} private: int itsX; int itsY; }; class Rectangle { public: Rectangle (int top , int left , int bottom , int right); ~Rectangle () {} int GetTop() const {return itsTop; } int GetLeft() const {return itsLeft; } int GetBottom() const {return itsBottom; } int GetRight() const {return itsRight; } Point GetUpperLeft() const {return itsUpperLeft; } Point GetLowerLeft() const {return itsLowerLeft; } Point GetUpperRight() const {return itsUpperRight; } Point GetLowerRight() const {return itsLowerRight; } void SetUpperLeft(Point Location) {itsUpperLeft = Location;} void SetLowerLeft(Point Location) {itsLowerLeft = location;} void SetUpperRight(Point Location) {itsUpperRight = location;} void SetLowerRight(Point location) {itsLowerRight = location;} void SetTop(int top) { itsTop = top; } void SetLeft(int left) { itsLeft = left; } void SetBottom(int bottom) { istBottom = bottom;} void SetRight(int right) { itsRight = right; } int GetArea() const; private: Point itsUpperLeft; Point itsUpperRight; Point itslowerLeft; Point itslowerRight; int itsTop; int itsLeft; int itsBottom; int itsRight; }; 作者: 天空飞鱼84 2007-3-7 07:48   回复此发言 -------------------------------------------------------------------------------- 3 回复:问一个麻烦点的问题 类的定义 #include "Rect.hpp" Rectangle::Rectangle(int top, int left,int bottom,int right) { itsTop = top; itsLeft = left; itsBottom = bottom; itsRight = right; itsUpperLeft.SetX(left); itsUpperLeft.SetY(top); itsUpperRight.SetX(right); itsUpperRight.SetY(top); itsLowerLeft.SetX(left); itsLowerLeft.SetY(bottom); itsLowerRight.SetX(right); itsLowerRight.SetY(bottom); } int Recttangle::GetArea() const { int Width = itsRight - itsLeft; int Height = itsTop - itsBottom; return (Width * Height); } int main() { Rectangle MyRectangle (100, 20 ,50 , 80); int Area = MyRectangle.GetArea(); std::cout << "Area: " << Area << "\n"; std::cout << "Upper Left X Coordinate: "; std::cout << MyRectangle.GetUpperLeft().GetX(); return 0; }
人 证 ---- 爆 笑 后 流 泪 [ 强 烈 推 荐 ] ◢ (转) 在火车上,一个很漂亮的女列车员,盯着一个民工模样的中年人,大声说:“查票!”   中年人浑身上下一阵翻找,终于找到了,却摄在手里。 列车员朝他怪怪地笑了笑,说:“这是儿童票。” 中年人憋红了脸,嗫嚅着说:“儿童票不是跟残疾人票价一吗?” 列车员打量了中年人一番,问道:“你是残疾人?”   “我是残疾人!”“那你把残疾证给我看看。”   中年人紧张起来,说:“我没有残疾证,买票的时候,售票员就向我要残疾证,我没办法才买的儿童票。   列车员冷笑了一下:“没有残疾证,怎么能证明你是残疾人啊?”   中年人没有做声,只是轻轻地将鞋子脱下,又将裤腿挽了起来———他只有半个脚掌。     列车员斜眼看了看,说:“我要看的是证件!是残联盖的钢印。” 中年人一副苦瓜脸,解释说:“我没有当地户口,人家不给办理残疾证。而且我是在私人工地干活,出了事之后老板就跑了,我也没钱到医院做评定……”   列车长闻讯赶来,询问情况。 中年人再一次向列车长说明,自己是一个残疾人,买了一张和残疾人票一样价格的票……   列车长也问:“你的残疾证呢?”   中年人说他没有残疾证,接着就让列车长看他的半个脚掌。 列车长连看都没看,他不耐烦地说:“我们只认证不认人!有残疾证就是残疾人,有残疾证才能享受残疾人票的待遇。你赶快补票吧!”   中年人一下就蔫了。
1 下一页