青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

隨筆 - 41, 文章 - 8, 評論 - 8, 引用 - 0
數據加載中……

[導入][C++]c++沉思錄第10章例子“字符圖像”

雖然還不是很懂啊,但卻很有意思。

下面把辛辛苦苦打的代碼貼出來,大家一起學習。

下面是 Picture.h

#include<iostream>
using namespace std;
class P_Node{
 friend class Picture;

protected:
 P_Node();
 virtual ~P_Node();
 virtual int height() const=0;
 virtual int width() const=0;
 virtual void display
  (ostream&,int,int)const=0;
 //int max(int,int);
private:
 int use;
};

class Picture{
 friend ostream& operator<<(ostream&,const Picture&);
 friend Picture frame(const Picture&);
 friend Picture operator&(const Picture&,const Picture&);
 friend Picture operator|(const Picture&,const Picture&);
 friend class String_Pic;
 friend class Frame_Pic;
 friend class Hcat_Pic;
 friend class VCat_Pic;

public:
 Picture();
 Picture(const char* const*,int);
 Picture(const Picture&);
 ~Picture();
 
 Picture& operator=(const Picture&);
private:
 Picture(P_Node*);
 int height() const;
 int width() const;
 void display(ostream&,int,int) const;
 P_Node* p;
};


class String_Pic:public P_Node{
 friend class Picture;
 String_Pic(const char* const*,int);
 ~String_Pic();
 int height() const;
 int width() const;
 void display(ostream&,int,int) const;
 char** data;
 int size;
};

class Frame_Pic:public P_Node{
 friend Picture frame(const Picture&);
 Frame_Pic(const Picture&);
 int height() const;
 int width() const;
 void display(ostream&,int,int) const;
 Picture p;
};

class VCat_Pic:public P_Node{
 friend Picture operator&
  (const Picture&,const Picture&);
 VCat_Pic(const Picture&,const Picture&);
 int height() const;
 int width() const;
 void display(ostream&,int,int) const;
 Picture top,bottom;
};

class Hcat_Pic:public P_Node{
 friend Picture operator|
  (const Picture&,const Picture&);
 Hcat_Pic(const Picture&,const Picture&);
 int height() const;
 int width() const;
 void display(ostream&,int,int) const;
 Picture left,right;
};

下面是 Picture.cpp

#include"Picture.h"
#include<iostream>
#include<cstring>
using namespace std;

P_Node::~P_Node(){}
P_Node::P_Node():use(1){}

static void pad(ostream& os,int x,int y)
{
 for(int i=x;i<y;i++)
  os<<" ";
}
int max(int x,int y)
{
 return x>y?x:y;
}

Picture::Picture(const char* const* str,int n):
 p(new String_Pic(str,n)){}

Picture::Picture(const Picture& orig):p(orig.p)
{
 orig.p->use++;
};

Picture::Picture(P_Node* p_node):p(p_node){}

Picture::~Picture()
{
 if(--p->use==0)
  delete p;
}

Picture& Picture::operator=(const Picture& orig)
{
 orig.p->use++;
 if(--p->use==0)
  delete p;
 p=orig.p;
 return *this;
}

int Picture::height() const
{
 return p->height();
}

int Picture::width() const
{
 return p->width();
}

void Picture::display(ostream& o,int x,int y)const
{
 p->display(o,x,y);
}

ostream& operator<<(ostream& os,const Picture& picture)
{
 int ht=picture.height();
 for(int i=0;i<ht;i++){
  picture.display(os,i,0);
  os<<endl;
 }
 return os;
}

String_Pic::String_Pic(const char* const* p,int n):
 data(new char* [n]),size(n)
{
 for(int i=0;i<n;i++){
  data[i]=new char[strlen(p[i])+1];
  strcpy(data[i],p[i]);
 }
}

int String_Pic::height() const
{
 return size;
}

int String_Pic::width() const
{
 int n=0;
 for(int i=0;i<size;i++){
  n=max(n,strlen(data[i]));
 }
 return n;
}

void String_Pic::display(ostream& os,int row,int width)const
{
 int start=0;
 if(row>=0&&row<height()){
  os<<data[row];
  start=strlen(data[row]);
 }
 pad(os,start,width);
}

String_Pic::~String_Pic()
{
 for(int i=0;i<size;i++)
  delete[] data[i];
 delete[] data;
}

Frame_Pic::Frame_Pic(const Picture& pic):p(pic){}
int Frame_Pic::height()const
{
 return p.height()+2;
}
int Frame_Pic::width()const
{
 return p.width()+2;
}

void Frame_Pic::display(ostream& os,int row,int wd)const
{
 if(row<0||row>=height()){
  pad(os,0,wd);
 }else{
  if(row==0||row==height()-1){
   os<<"+";
   int i=p.width();
   while(--i>=0)
    os<<"-";
   os<<"+";
  }else{
   os<<"|";
   p.display(os,row-1,p.width());
   os<<"|";
  }
  pad(os,width(),wd);
 }
}

Picture frame(const Picture& pic)
{
 return new Frame_Pic(pic);
}

VCat_Pic::VCat_Pic(const Picture& t,const Picture& b):
 top(t),bottom(b){}

int VCat_Pic::height()const
{
 return top.height()+bottom.height();
}
int VCat_Pic::width()const
{
 return max(top.width(),bottom.width());
}
void VCat_Pic::display(ostream& os,int row,int wd)const
{
 if(row>=0 && row< top.height())
  top.display(os,row,wd);
 else if(row <top.height()+bottom.height())
  bottom.display(os,row-top.height(),wd);
 else
  pad(os,0,wd);
}
Picture operator&(const Picture& t,const Picture& b)
{
 return new VCat_Pic(t,b);
}

Hcat_Pic::Hcat_Pic(const Picture& l,const Picture& r):
 left(l),right(r){}

int Hcat_Pic::height()const
{
 return max(left.height(),right.height());
}
int Hcat_Pic::width()const
{
 return left.width()+right.width();
}
void Hcat_Pic::display(ostream& os,int row,int wd)const
{
 left.display(os,row,left.width());
 right.display(os,row,right.width());
 pad(os,width(),wd);
}

Picture operator|(const Picture& l,const Picture& r)
{
 return new Hcat_Pic(l,r);
}

 

下面是 test.cpp

#include<iostream>
#include<cstring>
#include"Picture.h"

using namespace std;

char *init[]={"Paris","in the","Spring"};
int main()
{
 Picture p(init,3);
 cout<<p<<endl;

 Picture q=frame(p);
 cout<<q<<endl;

 cout<<(q&(p|q))<<endl;

 cout<<frame(p|p)<<endl;

 cout<<frame(q|q)<<endl;

 cout<<(p&p)<<endl;

 cout<<(q&q)<<endl;

 cout<<frame(p&p)<<endl;
 cout<<frame(frame(q&q)|frame(p&p))<<endl;
 return 0;
}

閱讀全文
類別:c++ 查看評論
文章來源:http://hi.baidu.com/mirguest/blog/item/d91abdcd42caeb2ef8dc612e.html

posted on 2011-02-02 12:01 mirguest 閱讀(314) 評論(0)  編輯 收藏 引用 所屬分類: C++

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            午夜国产精品视频| 欧美一区二区三区另类| 麻豆精品传媒视频| 最新亚洲电影| 亚洲激情av| 欧美人与性禽动交情品 | 欧美日韩亚洲另类| 亚洲视频高清| 午夜一区不卡| 亚洲电影av| 99精品热6080yy久久| 国产麻豆精品久久一二三| 欧美中文字幕视频在线观看| 久久久精彩视频| a4yy欧美一区二区三区| 亚洲小说欧美另类婷婷| 在线不卡中文字幕播放| 亚洲人成网站色ww在线| 欧美系列亚洲系列| 麻豆av一区二区三区久久| 欧美黑人在线观看| 欧美中日韩免费视频| 久久亚洲免费| 午夜精品免费在线| 久久综合色婷婷| 羞羞答答国产精品www一本| 久久久www成人免费毛片麻豆| 99国产精品久久久久久久成人热| 亚洲永久免费观看| 亚洲精品久久久久| 欧美一区二视频在线免费观看| 亚洲欧洲另类国产综合| 午夜一级久久| 一区二区三区国产| 久久一区二区三区四区| 欧美在线观看www| 欧美久久视频| 欧美α欧美αv大片| 国产伦精品一区二区三区高清版 | 亚洲一级特黄| 亚洲伦伦在线| 久久久久国产一区二区三区| 亚洲欧美三级伦理| 欧美精品一区二区三区久久久竹菊 | 欧美午夜免费| 亚洲精品视频在线观看免费| 在线日韩中文| 久久精品国产在热久久| 欧美一二三视频| 欧美性猛交一区二区三区精品| 欧美激情精品久久久久久变态| 国产一区二区三区丝袜| 亚洲影视中文字幕| 亚洲特级片在线| 欧美日韩爆操| 亚洲人午夜精品免费| 在线观看国产精品淫| 久久国产夜色精品鲁鲁99| 欧美一区二区三区在线观看| 国产精品v欧美精品v日韩| 日韩网站在线观看| 亚洲视频在线观看网站| 欧美精品 国产精品| 亚洲国产精品热久久| 亚洲精品国产精品国产自| 麻豆9191精品国产| 欧美福利电影在线观看| 亚洲激情视频在线播放| 欧美成人一区二区三区| 亚洲高清视频在线| 日韩亚洲精品在线| 欧美日韩少妇| 亚洲午夜精品网| 久久av一区二区三区亚洲| 国产亚洲精品高潮| 久久久久久久综合色一本| 欧美**人妖| 日韩视频精品| 国产精品美女久久久久av超清 | 欧美xxxx在线观看| 亚洲精品一区二区在线观看| 欧美精品久久久久久久免费观看| 亚洲乱码视频| 欧美有码在线观看视频| 韩国亚洲精品| 欧美精品18+| 亚洲欧美国产精品专区久久| 久久国产欧美精品| 亚洲国产欧美不卡在线观看| 欧美裸体一区二区三区| 日韩网站在线观看| 久久精品一区二区三区不卡| 亚洲激情社区| 国产精品蜜臀在线观看| 久久成年人视频| 亚洲日本va午夜在线电影| 亚洲综合电影| 亚洲国产网站| 国产精品青草久久| 另类图片综合电影| 亚洲一区999| 欧美激情在线观看| 午夜宅男欧美| 亚洲免费观看高清在线观看| 国产乱码精品一区二区三区av | 亚洲一区自拍| 欧美国产综合| 久久国产精品久久w女人spa| 亚洲久久视频| 狠色狠色综合久久| 欧美亚洲第一页| 免费观看成人网| 欧美1区2区3区| 欧美高清在线观看| 国产亚洲亚洲| 欧美视频三区在线播放| 久久噜噜噜精品国产亚洲综合| 亚洲毛片av| 亚洲大胆人体视频| 久久激情一区| 亚洲在线一区| 一本久久综合| 最新国产成人在线观看| 极品av少妇一区二区| 国产精品视频观看| 欧美少妇一区| 欧美精品一区三区| 免费中文日韩| 久久亚洲影音av资源网| 久久国产天堂福利天堂| 亚洲自拍都市欧美小说| 野花国产精品入口| 最新亚洲一区| 亚洲国产免费看| 亚洲成人在线免费| 欧美高清一区| 欧美成人午夜激情视频| 老司机精品视频网站| 欧美制服第一页| 午夜精品久久一牛影视| 亚洲在线观看视频| 亚洲一区视频| 欧美一区二区黄色| 欧美在线视频免费观看| 欧美一级片久久久久久久| 午夜欧美大尺度福利影院在线看| 亚洲一区二区三区成人在线视频精品| 日韩视频免费观看高清在线视频 | 亚洲电影视频在线| 欧美激情第1页| 亚洲日本激情| 亚洲少妇一区| 午夜欧美精品久久久久久久| 性做久久久久久久免费看| 欧美一级网站| 免费看的黄色欧美网站| 欧美精品黄色| 国产精品一区二区三区四区五区 | 国产日韩欧美高清免费| 黑丝一区二区三区| 亚洲人成毛片在线播放| 99精品99| 欧美中文在线观看| 欧美a级大片| 日韩西西人体444www| 午夜精品成人在线| 久久综合色播五月| 欧美日韩午夜| 国产一区二区精品久久| 亚洲激情成人在线| 亚洲综合国产| 欧美成人综合| 中文成人激情娱乐网| 久久精品国产欧美激情| 欧美精品尤物在线| 国产欧美日韩一区二区三区在线观看 | 亚洲一区久久久| 久久躁狠狠躁夜夜爽| 亚洲三级观看| 久久国产一区二区| 欧美日韩亚洲系列| 狠狠入ady亚洲精品| 一区二区精品| 你懂的网址国产 欧美| 亚洲一级在线观看| 欧美成人性生活| 国产在线播放一区二区三区| 亚洲精品国产精品乱码不99 | 亚洲成在人线av| 欧美亚洲免费电影| 亚洲精品乱码| 老司机一区二区| 国产真实乱偷精品视频免| 中文欧美在线视频| 欧美 日韩 国产在线 | 免费亚洲一区二区| 亚洲欧美日韩综合国产aⅴ| 欧美精品尤物在线| 亚洲激情一区| 欧美成人免费在线观看|