// Picture.cpp: implementation of the Picture class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Picture.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
ostream operator<<(ostream& o,Picture& p)
{
p.Display(o);
return o;
}
Picture operator+(Picture& p1,Picture& p2)
{
Picture p(p1);
p.RightAdd(p2);
return p;
}
//////////////////////////////////////////////////////////////////////////
Picture::Picture():m_width(0),m_height(0),m_pdata(NULL)//默认构造函数
{
}
Picture::Picture(const char*const*const arr ,int len)
{
int maxlen=0;
for (int i=0;i<len;i++)
{
maxlen = Picture::max(maxlen,strlen(arr[i]));
}
m_width = maxlen;//字符串长度,不包括 '\0'
m_height = len;
m_pdata = new char[m_width*m_height];
memset(m_pdata,0,m_width*m_height);
for (i=0;i<m_height;i++)
{
for (int j=0;arr[i][j]!='\0';j++)
{
m_pdata[i*m_width+j]=arr[i][j];
}
}
}
Picture::~Picture()
{
delete m_pdata;
}
Picture::Picture(const Picture& p)
{
m_width = p.m_width;
m_height= p.m_height;
m_pdata = new char[m_width*m_height];
memcpy(m_pdata,p.m_pdata,m_width*m_height);
}
Picture& Picture::operator =(const Picture& p)
{
if (this==&p)//自我赋值
{return *this;
}
delete m_pdata;
this->Picture::Picture(p);//把复制构造函数当普通函数使用
return *this;
}
//////////////////////////////////////////////////////////////////////////
void Picture::Display(ostream& o)
{
for (int i=0;i<m_height;i++)
{
for (int j=0;j<m_width;j++)
{
o<<position(i,j);
}
o<<endl;
}
}
//////////////////////////////////////////////////////////////////////////
Picture& Picture::ShowFrame(char jiao/* = */,char topbottom/* = */,char leftright/* = */)
{
m_jiao = jiao;
m_topbottom = topbottom;
m_leftright = leftright;
return frame();
}
Picture& Picture::frame()
{
int w = m_width + 2;
int h = m_height + 2;
char* pdata=new char[w*h];
memset(pdata,0,w*h);
for (int i=0;i<m_height;i++)
{
for (int j=0;j<m_width;j++)
{
pdata[(i+1)*w+j+1]=position(i,j);
}
}
delete m_pdata;
m_pdata = pdata;
m_width = w;
m_height = h;
kuang(0,0,w,h);
return *this;
}
Picture& Picture::LeftAdd(const Picture& p)
{
int w = m_width + p.m_width;
int h = Picture::max(m_height,p.m_height);
char* pdata = new char[w*h];
memset(pdata,0,w*h);
for (int i=0;i<m_height;i++)
{
for (int j=0;j<m_width;j++)
{
pdata[i*w+j+p.m_width] = position(i,j);
}
}
for (i=0;i<p.m_height;i++)
{
for (int j=0;j<p.m_width;j++)
{
pdata[i*w+j]=p.position(i,j);
}
}
m_width = w;
m_height =h;
delete m_pdata;
m_pdata = pdata;
return *this;
}
Picture& Picture::RightAdd(const Picture& p)
{
int w = m_width + p.m_width;
int h = Picture::max(m_height,p.m_height);
char* pdata = new char[w*h];
memset(pdata,0,w*h);
for (int i=0;i<m_height;i++)
{
for (int j=0;j<m_width;j++)
{
pdata[i*w+j] = position(i,j);
}
}
for (i=0;i<p.m_height;i++)
{
for (int j=0;j<p.m_width;j++)
{
pdata[i*w+j+m_width]=p.position(i,j);
}
}
m_width = w;
m_height =h;
delete m_pdata;
m_pdata = pdata;
return *this;
}
Picture& Picture::TopAdd(const Picture& p)
{
int w = Picture::max(m_width,p.m_width);
int h = m_height + p.m_height;
char* pdata = new char[w*h];
memset(pdata,0,w*h);
for (int i=0;i<m_height;i++)
{
for (int j=0;j<m_width;j++)
{
pdata[(i+p.m_height)*w+j] = position(i,j);
}
}
for (i=0;i<p.m_height;i++)
{
for (int j=0;j<p.m_width;j++)
{
pdata[i*w+j] = p.position(i,j);
}
}
m_height = h;
m_width = w;
delete m_pdata;
m_pdata = pdata;
return *this;
}
Picture& Picture::BottomAdd(const Picture& p)
{
int w = Picture::max(m_width,p.m_width);
int h = m_height + p.m_height;
char* pdata = new char[w*h];
memset(pdata,0,w*h);
for (int i=0;i<m_height;i++)
{
for (int j=0;j<m_width;j++)
{
pdata[i*w+j] = position(i,j);
}
}
for (i=0;i<p.m_height;i++)
{
for (int j=0;j<p.m_width;j++)
{
pdata[(i+m_height)*w+j] = p.position(i,j);
}
}
m_height = h;
m_width = w;
delete m_pdata;
m_pdata = pdata;
return *this;
}
iuan19
- 粉丝: 2
- 资源: 4
最新资源
- zblog站群:zblog seo站群高收录排名全地域霸屏
- 【安卓毕业设计】数独联网对战APP源码(完整前后端+mysql+说明文档).zip
- 【安卓毕业设计】Android天气小作业源码(完整前后端+mysql+说明文档).zip
- 【安卓毕业设计】群养猪生长状态远程监测源码(完整前后端+mysql+说明文档).zip
- 【安卓毕业设计】奶牛管理新加功能源码(完整前后端+mysql+说明文档).zip
- C#.NET公墓陵园管理系统源码数据库 SQL2008源码类型 WebForm
- 作业这是作业文件这是作业
- 【物理化学实验报告】挥发性双液系气-液平衡相图的测绘.pdf
- 4353_135543959.html
- C#物联订单仓储综合管理系统源码 物联综合管理系统源码数据库 SQL2008源码类型 WebForm
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈