• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

开始尝试面向对象的编程

发布: 2007-6-08 22:43 | 作者: seanhe | 来源: | 查看: 19次 | 进入软件测试论坛讨论

领测软件测试网 学c++也很久了,不过一直都是些皮毛。现在打算深入下去,所以准备写些有意思的代码,训练自己的思维。

c++的精髓一般很难把握,而且由于它兼容C代码,搞得很多人都用c的思维方式来写c++的代码。

我决定改变这一点。当然要从自身做起。从今天起,我要陆陆续续贴些代码上来,争取用面向对象的方式来完成这个项目。

//filename: cell.h

#ifndef _MAC_CELL
#define _MAC_CELL
#include <iostream>
#include <string>
#include <locale>
namespace std {} using namespace std;

const int CELL1=0xa9b0; //┌
const int CELL2=0xa9a4; //─
const int CELL3=0xa9d0; //┬
const int CELL4=0xa9b4; //┐
const int CELL5=0xa9a6; //│
const int CELL6=0xa9c0; //├
const int CELL7=0xa9c8; //┤
const int CELL8=0xa9e0; //┼
const int CELL9=0xa9b8; //└
const int CELL10=0xa9d8;//┴
const int CELL11=0xa9bc;//┘

class pos
{
 private:
  int x;
  int y;
 public:
  pos();
  pos(int lx, int ly);
  pos(pos & s);
      void operator=(pos s);     
  int getX();
  int getY();
};

class cell
{
 private:
  pos start;
  int width;
  int height;
  wstring content;
 public:
  cell();
  cell(int x, int y,int w,int h);
  cell(pos s,int w,int h);
  ~cell();
  int getWidth();
  int getHeight();
  wstring getContent();
  void setWidth(int w);
  void setHeight(int h);
  void setContent(wstring s);
};

#endif /* _MAC_CELL */

--------------cut here -----------------------

//filename:cell.cpp

#include <cell.h>
pos::pos():
x(0),y(0)
{
}

pos::pos(int lx,int ly):
x(lx),y(ly)
{
}
pos::pos(pos & s)
{
 x=s.getX();
 y=s.getY();
}
void pos::operator=(pos s)
{
 x=s.getX();
 y=s.getY();
}

int pos::getX()
{
 return x; 
}

int pos::getY()
{
 return y;
 }
 
cell::cell():
start(0,0),width(0),height(0),content()
{
}

cell::cell(int x,int y,int w,int h):
start(x,y),width(w),height(h),content()
{
}

cell::cell(pos s,int w,int h):
start(s),width(w),height(h),content()
{
 
}

int cell::getWidth()
{
 return width;
}

int cell::getHeight()
{
 return height;
 }

wstring cell::getContent()
{
 return content;
 }

void cell::setWidth(int w)
{
 width=w;
 }

void cell::setHeight(int h)
{
 height=h;
 }

void cell::setContent(wstring s)
{
 content=s;
 }

cell::~cell()
{
}


--------------------cut here--------------------------------

//filename:test.cpp

#include <cell.h>
int main()
{
 cell a(0,0,10,10);
 a.setContent(L"this is just a test");
 cout << a.getHeight() <<endl;
 return 0;
}

---------------cut here-----------------------------------------

//compile command:

aCC -AA +DD64 -I/opt/aCC/include_std -I. -lstd_v2 -lCsup_v2 test.cpp cell.cpp -o test

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网