当前位置: 首页 > news >正文

企炬网站域名解析

企炬网站,域名解析,qq云 wordpress,wordpress转移服务器后不能访问练习&#xff1a;将图形类的获取周长和获取面积函数设置成虚函数&#xff0c;完成多态 再定义一个全局函数&#xff0c;能够在该函数中实现&#xff1a;无论传递任何图形&#xff0c;都可以输出传递的图形的周长和面积 #include <iostream>using namespace std; class Sh…

练习:将图形类的获取周长和获取面积函数设置成虚函数,完成多态

再定义一个全局函数,能够在该函数中实现:无论传递任何图形,都可以输出传递的图形的周长和面积

#include <iostream>using namespace std;
class Shape
{
protected:double ZC;double MJ;
public:Shape(double a,double b):ZC(a),MJ(b){}~Shape(){}Shape(const Shape &other):ZC(other.ZC),MJ(other.MJ){}Shape &operator=(const Shape&other){if(this!=&other){this->ZC=other.ZC;this->MJ=other.MJ;}return *this;}virtual double get_zc(){return ZC;}virtual double get_mj(){return MJ;}void show(){cout<<"矩形周长"<<ZC<<endl;cout<<"矩形面积"<<MJ<<endl;}
};
class Jx:public Shape
{
private:double k;double g;
public:Jx(int c,int d):Shape(2*(c+d),c*d),k(c),g(d){cout<<"矩形构造"<<endl;}~Jx(){cout<<"矩形析构"<<endl;}Jx(const Jx& other):Shape(other),k(other.k),g(other.g){cout<<"矩形拷贝构造"<<endl;}Jx &operator=(const Jx&other){if(this!=&other){Shape::operator=(other);this->k=other.k;this->g=other.g;}cout<<"矩形拷贝赋值"<<endl;return *this;}void show(){cout<<"矩形::k="<<k<<"  g="<<g<<endl;cout<<"矩形周长"<<ZC<<endl;cout<<"矩形面积"<<MJ<<endl;}double get_zc(){return ZC;}double get_mj(){return MJ;}
};
class Yuan:public Shape
{
private:int r;
public:Yuan(int c):Shape(3.14*c,3.14*c*c),r(c){cout<<"圆构造"<<endl;}~Yuan(){cout<<"圆析构"<<endl;}Yuan(const Yuan& other):Shape(other),r(other.r){cout<<"圆形拷贝构造"<<endl;}Yuan &operator=(const Yuan&other){if(this!=&other){Shape::operator=(other);this->r=other.r;}cout<<"圆形拷贝赋值"<<endl;return *this;}void show(){cout<<"圆形::r="<<r<<endl;}double get_zc(){return ZC;}double get_mj(){return MJ;}};
void display(Shape &s)
{cout<<"面积:"<<s.get_mj()<<"  周长"<<s.get_zc()<<endl;
}
int main()
{Jx s1(2,8);             //构造s1.show();                         //调用的是继承下来的show函数cout<<"********************************"<<endl;Shape *ptr=&s1;ptr->show();cout<<"********************************"<<endl;display(s1);cout<<"********************************"<<endl;Yuan r1(2);             //构造r1.show();                        //调用的是继承下来的show函数cout<<"********************************"<<endl;Shape *ptr2=&r1;ptr2->show();cout<<"********************************"<<endl;display(r1);cout<<"********************************"<<endl;return 0;
}

2> 手动实现一个循环顺序队列

#include <iostream>
using namespace std;class SeqQueue
{
private:int *table;    //顺序队列指针int head;           //队头下标int tail;           //队尾下标int lenth;          //实际长度int size;           //队容量
public://无参构造SeqQueue():table(new int[100]), head(0), tail(0), lenth(0), size(100) {}//有参构造SeqQueue(int size):table(new int[size]) ,head(0), tail(0), lenth(0), size(size){}//析构函数~SeqQueue(){delete [] table;}//拷贝构造函数SeqQueue(const SeqQueue &R):table(new int[R.size]), head(R.head), tail(R.tail), lenth(R.lenth), size(R.size){//拷贝数据for(int i = 0; i < lenth; i++){this->table[(head+i)%size] = R.table[(head+i)%size];}}//拷贝赋值函数SeqQueue &operator=(const SeqQueue &R){//申请与拷贝源相同大小的内存空间delete [] this->table;this->table = new int[R.size];//拷贝数据this->head = R.head;this->size = R.size;this->tail = R.tail;this->lenth = R.lenth;for(int i = 0; i < lenth; i++){this->table[(head+i)%size] = R.table[(head+i)%size];}return *this;}//访问第一个元素int &front(){return this->table[this->head];}//访问最后一个元素int &back(){return this->table[this->tail-1];}//判空bool is_empty(){if(this->head == this->tail){return true;}else{return false;}}//判满bool is_full(){if((this->tail+1)%size == this->head){return true;}else{return false;}}//查看队列容量大小int get_size(){return this->size;}//查看队列实际长度int get_lenth(){return lenth;}//尾插一个元素void push(int e){if(is_full()){cout << "队列已满" << endl;return;}else{this->table[this->tail] = e;this->tail = (this->tail+1)%size;this->lenth++;}}//修改最后一个元素void emplace(int e){this->table[this->tail-1] = e;}//删除首个元素void pop(){if(is_empty()){cout << "队列已空" << endl;return;}else{this->head = (this->head+1)%size;this->lenth--;}}//展示void show(){int count = 0;for(int i = 0; i < lenth; i++){cout << this->table[(head+i)%size] << " ";count++;if(count % 5 == 0){cout << endl;}}if(count % 5 != 0){cout << endl;}}
};int main()
{SeqQueue A;for(int i = 0; i < 10; i++){A.push(i);}cout << "初始队列:" << endl;A.show();cout << "出队3个元素:" << endl;for(int i = 0; i < 3; i++){A.pop();}A.show();SeqQueue B = A;cout << "将A的数据拷贝给B" << endl;B.show();cout << "修改B的最后一个元素" << endl;B.emplace(100);B.show();cout << "其中" << endl;cout << "第一个元素:" << B.front() << endl;cout << "最后一个元素:" << B.back() << endl;cout << "队列容量:" << B.get_size() << endl;cout << "队列长度:" << B.get_lenth() << endl;return 0;
}

X-Mind

http://www.15wanjia.com/news/31735.html

相关文章:

  • phpweb网站打开很慢如何建立一个网站平台
  • 徐州做汽车销售的公司网站百度推广销售话术
  • 家具网站开发目的电商运营培训哪个机构好
  • wordpress调用网站域名东莞网站推广哪里找
  • 网站域名背景企业网站如何优化
  • 青海专业网站建设推广平台建设加快实施创新驱动发展战略
  • 上海服饰网站建设提升关键词
  • 网站备案 阿里云网络优化基础知识
  • vs做网站出现显示bug推广赚钱一个2元
  • 三亚百度推广公司外贸网站优化公司
  • 公司建网站一般多少钱百度云电脑网页版入口
  • 郑州新感觉会所网站哪里做的seowhy教研室
  • 活动网站怎么建设seo按照搜索引擎的什么对网站
  • 网站建设包括哪些方面开淘宝店铺怎么运营推广
  • 建设银行网站打不开其他网站可以退吗重大军事新闻最新消息
  • 网站建设期间注意事项百度问答app下载
  • 如何用阿里云做网站电商网站开发平台
  • 自己设计网页的网址广州网站优化推广方案
  • 深圳网站设计必选成都柚米科技09做武汉seo网站优化技巧
  • 虹口房产网站建设在线看crm系统
  • 北京网站建设公司分形科技最近新闻报道
  • 松江集团网站建设网站营销推广有哪些
  • 上海网站改版方案短信广告投放
  • wordpress制作论坛福州seo排名优化公司
  • 什么是小程序商城长沙百度seo代理
  • 做蛋糕视频教学网站适合30岁女人的培训班
  • 做桑拿网站挣钱吗广州抖音推广
  • 仁怀哪里可以做网站投广告哪个平台好
  • 怎么给自己的网站做域名标题优化
  • 怎么整理网站网站建站教程