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

今天新闻联播主要内容seo团队管理系统

今天新闻联播主要内容,seo团队管理系统,哈尔滨网页设计师招聘,wordpress 登陆信息作业&#xff1a; 1> 思维导图 2> 整理代码 1. 拷贝赋值函数课上代码 //拷贝赋值函数课上代码 #include<iostream> using namespace std;//创建类 class Stu { private://私有的string name;int socer;int *age;//此处注意用到指针类型 public://共有的//无参构…

作业:

1> 思维导图

 2> 整理代码

1. 拷贝赋值函数课上代码

//拷贝赋值函数课上代码
#include<iostream>
using namespace std;//创建类
class Stu
{
private://私有的string name;int socer;int *age;//此处注意用到指针类型
public://共有的//无参构造函数(系统默认设置)Stu(){cout << "Stu:: 无参构造函数 " << endl;}//有参构造函数(自定义,自定义后需要将无参构造函数显性)Stu(string n,int s,int a):name(n),socer(s),age(new int (a))//初始化列表{cout << "Stu:: 有参构造函数" << endl;}//拷贝构造函数Stu(const Stu &other):name(other.name),socer(other.socer),age(new int(*other.age))//此处注意*other.age:因为定义是指针类型所以要去指针指向的内容进行赋值{cout << "Stu:: 拷贝构造函数" << endl;}//拷贝赋值函数Stu &operator=(const Stu &other) //此处不能用初始化列表因为是赋值操作{if(this != &other)//给自己赋值多此一举{name=other.name;socer=other.socer;age = new int (*other.age);//深拷贝赋值因为有指针防止段错误。。。}cout << "Stu:: 拷贝赋值函数" << endl;//注意返回值是自身引用return *this;}//析构函数~Stu()//会自动调用{cout << "Stu:: 析构函数" << endl;}};
int main()
{Stu s1;//无参构造函数Stu s2("王一博",100,23);//有参构造函数Stu s3(s2); //拷贝构造函数====》将s2拷贝给s3==》Stu s3=s2s1=s3;//拷贝赋值return 0;
}

 2.匿名对象(用来初始化有名对象)课上代码

void fun(Stu g)//形参接收实参的值==》Stu g=Stu("lisa",120,25)
{}
int main()
{Stu s1;//无参构造函数Stu s2("王一博",100,23);//有参构造函数Stu s3(s2); //拷贝构造函数====》将s2拷贝给s3==》Stu s3=s2//用到匿名对象给有名对象初始化Stu s4=Stu("赵云",88,40);//给数组初始化Stu s[2]={Stu("哪吒",200,40),Stu("张飞",300,30)};//和c中初始化相似//匿名对象作为函数实参使用fun(Stu("lisa",120,25));s1=s3;//拷贝赋值return 0;
}

 3.全局函数作友元,课上代码

//友元上课代码(全局函数作友元)
#include <iostream>
using namespace std;
//封装 房间类
class Room
{friend void goodfriend(Room &r);//关键字:friend
private://私有的string bedroom;//卧室
public://共有的string sittingroom;//客厅
public:Room(){//在类内赋值bedroom="卧室";sittingroom="客厅";}
};
//全局函数作友元
void goodfriend(Room &r)
{cout << "好朋友正在参观" << r.sittingroom << endl;//共有权限访问成功毋庸置疑cout << "好朋友正在参观" << r.bedroom << endl;//报错原因:私有权限类外不可访问,需要用友元
}int main()
{Room r;goodfriend(r);return 0;
}

4.成员函数作友元,课上代码

//成员函数作友元
#include <iostream>
using namespace std;
class Room;//需要声明一下,以免下面用到系统不知道报错
//封装好朋友类
class goodfriend
{
private:Room *r;//用到指针是因为指针的大小是固定的,而变量的大小不明,系统无法分配空间
public:goodfriend();//在类内声明void vist();//在类内声明
};//封装 房间类
class Room
{/*friend void goodfriend(Room &r);//关键字:friend*/friend void goodfriend::vist();
private://私有的string bedroom;//卧室
public://共有的string sittingroom;//客厅
public:Room(){//在类内赋值bedroom="卧室";sittingroom="客厅";}
};
//类外实现
goodfriend::goodfriend()
{r=new Room;//申请空间
}
void goodfriend::vist()
{cout  << "好朋友正在参观" << r->sittingroom << endl;//共有权限访问成功毋庸置疑cout << "好朋友正在参观" << r->bedroom << endl;//报错原因:私有权限类外不可访问,需要用友元//指针需要用->
}全局函数作友元
//void goodfriend(Room &r)
//{
//    cout << "好朋友正在参观" << r.sittingroom << endl;//共有权限访问成功毋庸置疑
//    cout << "好朋友正在参观" << r.bedroom << endl;//报错原因:私有权限类外不可访问,需要用友元
//}int main()
{Room r;//goodfriend(r);goodfriend g;g.vist();return 0;
}

 5.课前热身

int const a; //......
int const *p; //......
int * const p; //
int const * const p; //
const int fun() {}  //该函数是返回一个常整型变量

 6.常成员函数&&非常成员函数

1.非常对象可以调用常成员函数,也可以调用非常成员函数,优先调用非常成员函数

2.常对象只能调用常成员函数,如果没有常成员函数,则报错

#include <iostream>
using namespace std;
class Stu
{
private:string name;//只对该成员变量在常成员函数中可以被修改mutableint id;
public:Stu(){}Stu(string name,int id):name(name),id(id){}//常成员函数void display()const //==》Stu const * const this;表示指针的值和指向都不可改{//this ->name ="li si";报错原因:因为被const修饰不可以更改cout << name << " " << id <<endl;}//非常成员函数void display()//==>Stu * const this;和常成员重载{this -> name ="lisi";cout << name << " " << id << endl;}};int main()
{cout << "Hello World!" << endl;const Stu s1("zhangsan",1001);//常对象s1.display();//常对象只能调用常成员函数return 0;
}

 7.成员函数来实现运算符重载

//运算符重载
#include<iostream>
using namespace std;//构造类
class Club
{
private://私有的int age;int hight;
public://无参Club(){}Club(int a,int h):age(a),hight(h){}//成员函数实现算数运算符重载 加法const Club operator+(const Club &R)const//const 1:结果 2:右操作数 3:左操作数{//内部运算Club temp;temp.age=age+R.age;temp.hight=hight+R.hight;return temp;}//成员函数实现算数运算符重载 减法const Club operator-(const Club &R)const//const 1:结果 2:右操作数 3:左操作数{//内部运算Club temp;temp.age=age-R.age;temp.hight=hight-R.hight;return temp;}//成员函数实现算数运算符重载 乘法const Club operator*(const Club &R)const//const 1:结果 2:右操作数 3:左操作数{//内部运算Club temp;temp.age=age*R.age;temp.hight=hight*R.hight;return temp;}//成员函数实现算数运算符重载 除法const Club operator/(const Club &R)const//const 1:结果 2:右操作数 3:左操作数{//内部运算Club temp;temp.age=age/R.age;temp.hight=hight/R.hight;return temp;}//成员函数实现算数运算符重载 取余const Club operator%(const Club &R)const//const 1:结果 2:右操作数 3:左操作数{//内部运算Club temp;temp.age=age%R.age;temp.hight=hight%R.hight;return temp;}
关系运算符////成员函数实现关系运算符重载 >bool operator>(const Club &R)const{if(age>R.age && hight>R.hight){return true;}elsereturn false;}//成员函数实现关系运算符重载 <bool operator<(const Club &R)const{if(age<R.age && hight<R.hight){return true;}elsereturn false;}//成员函数实现关系运算符重载 >=bool operator>=(const Club &R)const{if(age>=R.age && hight>=R.hight){return true;}elsereturn false;}//成员函数实现关系运算符重载 <=bool operator<=(const Club &R)const{if(age<=R.age && hight<=R.hight){return true;}elsereturn false;}//成员函数实现关系运算符重载 ==bool operator==(const Club &R)const{if(age==R.age && hight==R.hight){return true;}elsereturn false;}//成员函数实现关系运算符重载 >bool operator!=(const Club &R)const{if(age!=R.age && hight!=R.hight){return true;}elsereturn false;}//赋值运算符//成员函数实现赋值运算符重载 +=Club &operator+=(const Club &R){age += R.age;hight += R.hight;return *this;//返回自身}//成员函数实现赋值运算符重载 -=Club &operator-=(const Club &R){age -= R.age;hight -= R.hight;return *this;//返回自身}//成员函数实现赋值运算符重载 =Club &operator=(const Club &R){age = R.age;hight = R.hight;return *this;//返回自身}//成员函数实现赋值运算符重载 *=Club &operator*=(const Club &R){age *= R.age;hight *= R.hight;return *this;//返回自身}//成员函数实现赋值运算符重载 /=Club &operator/=(const Club &R){age /= R.age;hight /= R.hight;return *this;//返回自身}//成员函数实现赋值运算符重载 %=Club &operator%=(const Club &R){age %= R.age;hight %= R.hight;return *this;//返回自身}void show(){cout << "age= " << age << " " << "hight= " << hight << endl;}
};
int main()
{Club c1(10,10);Club c2(10,10);Club c3=c1+c2;Club c4=c1-c2;Club c5=c1*c1;Club c6=c1/c2;Club c7=c1%c2;cout << "算数运算符" << endl;c3.show();c4.show();c5.show();c6.show();c7.show();cout << "关系运算符" << endl;if(c3!=c1){if(c3>c1){cout << "c3>c1 " << endl;}else if(c3<c1){cout << "c3<c1 " << endl;}cout << "c3!=c1" << endl;}else if(c3 == c1){if(c3>=c1){cout << "c3>=c1" << endl;}else if(c3<=c1){cout << "c3<=c1" << endl;}{cout << "c3==c1" << endl;}}cout << "赋值运算符" << endl;//赋值函数不要加类型否则属于初始化会报错c3+=c2;c4-=c2;c5*=c1;c6/=c2;c7%=c2;c3.show();c4.show();c5.show();c6.show();c7.show();return  0;
}

效果图:

 8.全局函数实现运算符重载

//运算符重载
#include<iostream>
using namespace std;//构造类
class Club
{friend const Club operator+(const Club &L,const Club &R);friend const Club operator-(const Club &L,const Club &R);friend const Club operator*(const Club &L,const Club &R);friend const Club operator/(const Club &L,const Club &R);friend const Club operator%(const Club &L,const Club &R);friend bool operator>(const Club &L,const Club &R);friend bool operator<(const Club &L,const Club &R);friend bool operator<=(const Club &L,const Club &R);friend bool operator>=(const Club &L,const Club &R);friend bool operator==(const Club &L,const Club &R);friend bool operator!=(const Club &L,const Club &R);friend Club &operator+=( Club &L,const Club &R);friend Club &operator-=( Club &L,const Club &R);friend Club &operator*=( Club &L,const Club &R);friend Club &operator/=(Club &L,const Club &R);friend Club &operator%=( Club &L,const Club &R);private://私有的int age;int hight;
public://无参Club(){}Club(int a,int h):age(a),hight(h){}void show(){cout << "age= " << age << " " << "hight= " << hight << endl;}
};
//成员函数实现算数运算符重载 加法
const Club operator+(const Club &L,const Club &R)//const 1:结果 2:右操作数 3:左操作数
{//内部运算Club temp;temp.age=L.age-R.age;temp.hight=L.hight-R.hight;return temp;
}//成员函数实现算数运算符重载 减法
const Club operator-(const Club &L,const Club &R)//const 1:结果 2:右操作数 3:左操作数
{//内部运算Club temp;temp.age=L.age-R.age;temp.hight=L.hight-R.hight;return temp;
}//成员函数实现算数运算符重载 乘法
const Club operator*(const Club &L,const Club &R)//const 1:结果 2:右操作数 3:左操作数
{//内部运算Club temp;temp.age=L.age*R.age;temp.hight=L.hight*R.hight;return temp;
}
//成员函数实现算数运算符重载 除法
const Club operator/(const Club &L,const Club &R)//const 1:结果 2:右操作数 3:左操作数
{//内部运算Club temp;temp.age=L.age/R.age;temp.hight=L.hight/R.hight;return temp;
}
//成员函数实现算数运算符重载 取余
const Club operator%(const Club &L,const Club &R)//const 1:结果 2:右操作数 3:左操作数
{//内部运算Club temp;temp.age=L.age%R.age;temp.hight=L.hight%R.hight;return temp;
}
关系运算符//
//成员函数实现关系运算符重载 >
bool operator>(const Club &L,const Club &R)
{if(L.age>R.age && L.hight>R.hight){return true;}elsereturn false;
}
//成员函数实现关系运算符重载 <
bool operator<(const Club &L,const Club &R)
{if(L.age>R.age && L.hight<R.hight){return true;}elsereturn false;
}
//成员函数实现关系运算符重载 >=
bool operator>=(const Club &L,const Club &R)
{if(L.age>=R.age && L.hight>R.hight){return true;}elsereturn false;
}
//成员函数实现关系运算符重载 <=
bool operator<=(const Club &L,const Club &R)
{if(L.age<=R.age && L.hight>R.hight){return true;}elsereturn false;
}
//成员函数实现关系运算符重载 ==
bool operator==(const Club &L,const Club &R)
{if(L.age==R.age && L.hight==R.hight){return true;}elsereturn false;
}//成员函数实现关系运算符重载 !=
bool operator!=(const Club &L,const Club &R)
{if(L.age!=R.age && L.hight>R.hight){return true;}elsereturn false;
}
//赋值运算符
//成员函数实现赋值运算符重载 +=
Club &operator+=( Club &L,const Club &R)
{L.age += R.age;L.hight += R.hight;return L;//返回自身
}
//成员函数实现赋值运算符重载 -=
Club &operator-=( Club &L,const Club &R)
{L.age -= R.age;L.hight -= R.hight;return L;//返回自身
}//成员函数实现赋值运算符重载 *=
Club &operator*=( Club &L,const Club &R)
{L.age *= R.age;L.hight *= R.hight;return L;//返回自身
}
//成员函数实现赋值运算符重载 /=
Club &operator/=( Club &L,const Club &R)
{L.age /= R.age;L.hight /= R.hight;return L;//返回自身
}
//成员函数实现赋值运算符重载 %=
Club &operator%=(Club &L,const Club &R)
{L.age /= R.age;L.hight /= R.hight;return L;//返回自身
}int main()
{Club c1(10,10);Club c2(10,10);Club c3=c1+c2;Club c4=c1-c2;Club c5=c1*c1;Club c6=c1/c2;Club c7=c1%c2;cout << "算数运算符" << endl;c3.show();c4.show();c5.show();c6.show();c7.show();cout << "关系运算符" << endl;if(c3!=c1){if(c3>c1){cout << "c3>c1 " << endl;}else if(c3<c1){cout << "c3<c1 " << endl;}cout << "c3!=c1" << endl;}else if(c3 == c1){if(c3>=c1){cout << "c3>=c1" << endl;}else if(c3<=c1){cout << "c3<=c1" << endl;}{cout << "c3==c1" << endl;}}cout << "赋值运算符" << endl;//赋值函数不要加类型否则属于初始化会报错c3+=c2;c4-=c2;c5*=c1;c6/=c2;c7%=c2;c3.show();c4.show();c5.show();c6.show();c7.show();return  0;
}

http://www.dinnco.com/news/19614.html

相关文章:

  • 分类网站怎么做seo短网址生成网站
  • 广饶网站定制加拿大搜索引擎
  • 网站制作公司品牌网络营销应用方式
  • 上海的最新新闻吉林关键词优化的方法
  • 独立做网站搭建平台网店推广方式
  • gofair做网站郑州品牌网站建设
  • 网站价值评估怎么做深圳谷歌优化seo
  • 行业前10的网站建设公产品营销策划方案
  • 南宁市做网站哈尔滨seo优化
  • 利用网站空间做代理微指数查询
  • 自己做外贸网站能接到单吗雅思培训班价格一览表
  • 西安关键词快速排名百度一键优化
  • 移动互联网应用技术专业学什么优化营商环境 助推高质量发展
  • 网站开发环境及工具怎样做好销售和客户交流
  • 做网站图片和文字字体侵权谷歌aso优化
  • 中山哪家建网站好培训机构排名
  • 企业网站托管的方案图片搜索引擎
  • 杂志网站建设方案最新新闻消息
  • 哈尔滨有网站的公司如何屏蔽百度广告推广
  • 宝鸡网站建设seo建网站不花钱免费建站
  • 网上购物型网站福州关键词排名软件
  • 响应式电影资讯网站网站建设及网络推广
  • 文登住房与建设局网站今日新闻国际头条新闻
  • 加强门户网站建设的通知北京网络营销咨询公司
  • wordpress mingleseo页面排名优化
  • 网站主色调有几种手机优化大师下载安装
  • 网站域名备案与不备案的区别满十八岁可以申请abc认证吗
  • 河北农业网站建设公司刷赞网站推广永久
  • 江西万通建设有限公司网站app引流推广软件
  • 做推广有什么好网站汕头网站优化