// 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
最新资源
- springboot199疫情打卡健康评测系统_zip.zip
- 演示文档文档要演示11
- springboot200个人博客系统的设计与实现_rar.zip
- 网络安全入门视频教程.zip
- springboot202善筹网(众筹)前后台实现设计_rar.zip
- springboot201基于SpringBoot的论坛系统设计与实现_rar.zip
- springboot205大学生智能消费记账系统的设计与实现_rar.zip
- Android 项目MVP框架,开箱即用.zip(毕设&课设&实训&大作业&竞赛&项目)
- 饮品店接单网页管理系统(毕设&课设&实训&大作业&竞赛&项目)
- springboot204在线考试系统_rar.zip
- STM32F407ZET6最小系统板
- springboot203医疗挂号管理系统_rar.zip
- ip归属地工具java模型包的压缩文件,下载后注意要解压后才可以引入java代码
- springboot206基于SpringBoot的农商对接系统的设计与实现_rar.zip
- springboot208基于springboot物流管理系统_rar.zip
- springboot207基于springboot的实习管理系统_zip.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈


