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

网站开发外包协议会员制网站建设

网站开发外包协议,会员制网站建设,wordpress页面调试分类文章,网站建设 提成输出&#xff1a; cout << "你好世界 我是C" << endl; 其中cout相当于C语言中的printf << 是指最后所有的输入都放在cout中 endl为换行 cerr << "程序错误退出" << endl; cerr 同样为输出 输入&#xff1a;cin …

输出: cout << "你好世界 我是C++" << endl;    其中cout相当于C语言中的printf  << 是指最后所有的输入都放在cout中  endl为换行      cerr << "程序错误退出" << endl;  cerr 同样为输出

输入:cin >> a;    在这里cin和C语言中scanf作用一样  

#include <iostream>using namespace std;int main()
{int a=0;int b=0;cout << "你好世界 我是C++" << endl;cout << "你好世界 我是C++" << "你好,我是补充输出的" << endl;cin >> a;       //在这里cin和C语言中scanf作用一样cin >> b;cout << a << "," << b << endl;cout << a << "+" << b << "="<< a+b << endl;cerr << "程序错误退出" << endl;return 0;
}

创建namespace 

namespace cir {double PI=3.141592653;//获取圆形周长的函数double getlenth0fcircle(double radius){return 2*PI*radius;}//获取圆形面积的函数double getAifCircle(double radius){return PI*radius*radius;}}

在.cpp文件中 首先要引用 #include “cir.h” 然后要加上  using namespace cir  才能够使用

#include <iostream>
#include <stdio.h>
#include "cir.h"using namespace std;
using namespace cir;int main()
{double myRadius =5 ;cout << "Hello World!namespace" << endl;//printf("lenth: %lf ,are:%lf\n", cir::getlenth0fcircle(myRadius),//      cir::getAifCircle(myRadius));printf("lenth: %lf ,are:%lf\n", getlenth0fcircle(myRadius),getAifCircle(myRadius));return 0;
}

Lambda 表达式

Lambda 表达式是C++ 引入的一种匿名函数的方式,它允许你在需要函数的地方内联的定义函数,而无需单独命名函数

int main()
{int x=60;int y=20;auto add=[](int a,int b)->int{return a+b;};int ret =add(x,y);cout << ret;return 0;
}

其中auto为预测  add为命名   【】捕获列表  ()为参数  int 为类型   

int getMax(int a, int b,bool(*p1)(int a,int b))
{if(p1(a,b)){return a;}else{return b;}
}
int main()
{int x=40;int y=20;//bool(*p)(int a,int b)=compare;int max=getMax(x,y,[](int a,int b)->bool {return a>b;});cout << max <<endl;return 0;
}
int max=getMax(x,y,[](int a,int b)->bool {       return a>b;
});   

内联函数和Lambda函数

带有捕获列表的Lambda 函数

方式1

 auto add =[x,y]()->int{//用这种方式捕获,是不能修改变量值的,只能用,可读。return x+y;};int ret =add();cout << ret <<  endl;

方式2

 auto mul =[=]()->int{//用这种方式可以捕获所有的变量,不需要去在列表中写明,是不能修改变量值的,只能用,可读。return x*y;};ret =mul();cout << ret <<  endl;

= 可以捕获所有的变量

方式三

auto modifyAndMul =[&]()->int{//用这种引用的方式来捕获,引用类似指针,进行地址访问。 可修改数值x=15;return x*y*z;};ret =modifyAndMul();cout << ret <<  endl;

& 这种方式可以修改捕获的数值

内联函数

类:

当把在c语言中的结构体搬到c++中 会出现一系列的问题 

以下为c语言的结构体

#include <stdio.h>
#include <stdlib.h>
struct Car{       //汽车“类”char *color ;  //颜色char *brand;   //品牌char *type;    //车型int year;      //年限void (*printCarInfo)(char *color,char *brand,char*type,int year);  //函数指针,指向车介绍函数void (*carRun)(char *type);       //函数指针,指向车运行的函数void (*carStop)(char * type);     //函数指针,执行车停止的函数
};void bwmThreePrintCarInfo(char *color,char *brand,char *type,int year)
{printf("车的品牌是 :%s,型号是 :%s,颜色是: %s,上市年限是: %d\r\n",brand,type,color,year);}
void AodiA6PrintCarInfo(char *color,char *brand,char *type,int year)
{printf("车的品牌是 :%s,型号是 :%s,颜色是: %s,上市年限是: %d\r\n",brand,type,color,year);}int main()
{struct Car BWMthree;BWMthree.color ="白色";BWMthree.brand ="宝马";BWMthree.type ="3系";BWMthree.year =2025;BWMthree.printCarInfo =bwmThreePrintCarInfo;BWMthree.printCarInfo(BWMthree.color,BWMthree.brand,BWMthree.type,BWMthree.year);struct Car *AodiA6;AodiA6 =(struct Car*)malloc(sizeof(struct Car));AodiA6->color="黑色";AodiA6->brand ="奥迪";AodiA6->year =2025;AodiA6->type ="A6";AodiA6->printCarInfo=AodiA6PrintCarInfo;AodiA6->printCarInfo(AodiA6->color,AodiA6->brand,AodiA6->type ,AodiA6->year);return 0;
}

放到C++下

问题①  char * 要换成 string 

问题② 要将结构体struct 换成类 class  且将私有换成public 

问题③ 要将printf 换成结构体的形式cout输出

问题④ 在C++中,通过std::to string ()函数,将整形数转化为字符串

问题⑤ 如果采用指针的形式 那么不能用malloc  要使用 Car *AodiA6 =new Car(); 

如下:

#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
using namespace  std;class Car{       //汽车“类”
public:string color ;  //颜色string brand;   //品牌string type;    //车型int year;      //年限void (*printCarInfo)(string color,string brand,string type,int year);  //函数指针,指向车介绍函数void (*carRun)(string type);       //函数指针,指向车运行的函数void (*carStop)(string type);     //函数指针,执行车停止的函数
};void bwmThreePrintCarInfo(string color,string brand,string type,int year)
{//printf("车的品牌是 :%s,型号是 :%s,颜色是: %s,上市年限是: %d\r\n",//brand,type,color,year);string str = "车的品牌是:" + brand+ ",型号是:" + type+ ",颜色是:"  + color+",上市年限是:" + to_string(year);cout << str << endl;}
void AodiA6PrintCarInfo(string color,string brand,string type,int year)
{//printf("车的品牌是 :%s,型号是 :%s,颜色是: %s,上市年限是: %d\r\n",//brand,type,color,year);string str = "车的品牌是:" + brand+ ",型号是:" + type+ ",颜色是:"  + color+",上市年限是:" + to_string(year);cout << str << endl;}int main()
{Car BWMthree;BWMthree.color ="白色";BWMthree.brand ="宝马";BWMthree.type ="3系";BWMthree.year =2025;BWMthree.printCarInfo =bwmThreePrintCarInfo;BWMthree.printCarInfo(BWMthree.color,BWMthree.brand,BWMthree.type,BWMthree.year);Car *AodiA6=new Car();//AodiA6 =(struct Car*)malloc(sizeof(struct Car));AodiA6->color="黑色";AodiA6->brand ="奥迪";AodiA6->year =2025;AodiA6->type ="A6";AodiA6->printCarInfo=AodiA6PrintCarInfo;AodiA6->printCarInfo(AodiA6->color,AodiA6->brand,AodiA6->type ,AodiA6->year);return 0;
}

真正的成员变量   在class中 不需要像结构体一样 进行传参 

一般在类的外部进行成员函数的实现 在class中只需要进行函数的引用

外部时

void Car::realPrintCarInfo()

{

}

#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>using namespace  std;class Car{       //汽车“类”
public://成员数据string color ;  //颜色string brand;   //品牌string type;    //车型int year;      //年限//其实也是成员数据,指针变量,指向函数的变量,而并非真正的成员函数void (*printCarInfo)(string color,string brand,string type,int year);  //函数指针,指向车介绍函数void (*carRun)(string type);       //函数指针,指向车运行的函数void (*carStop)(string type);     //函数指针,执行车停止的函数void realPrintCarInfo();    //声明成员函数};
void Car::realPrintCarInfo()  //在类的外部进行成员函数的实现
{string str = "车的品牌是:" + brand+ ",型号是:" + type+ ",颜色是:"  + color+",上市年限是:" + to_string(year);cout << str << endl;
}void bwmThreePrintCarInfo(string color,string brand,string type,int year)
{//printf("车的品牌是 :%s,型号是 :%s,颜色是: %s,上市年限是: %d\r\n",//brand,type,color,year);string str = "车的品牌是:" + brand+ ",型号是:" + type+ ",颜色是:"  + color+",上市年限是:" + to_string(year);cout << str << endl;}
void AodiA6PrintCarInfo(string color,string brand,string type,int year)
{//printf("车的品牌是 :%s,型号是 :%s,颜色是: %s,上市年限是: %d\r\n",//brand,type,color,year);string str = "车的品牌是:" + brand+ ",型号是:" + type+ ",颜色是:"  + color+",上市年限是:" + to_string(year);cout << str << endl;}int main()
{Car BWMthree;BWMthree.color ="白色";BWMthree.brand ="宝马";BWMthree.type ="3系";BWMthree.year =2025;//BWMthree.printCarInfo =bwmThreePrintCarInfo;//BWMthree.printCarInfo(BWMthree.color,BWMthree.brand,BWMthree.type,BWMthree.year);BWMthree.realPrintCarInfo();Car *AodiA6=new Car();//AodiA6 =(struct Car*)malloc(sizeof(struct Car));AodiA6->color="黑色";AodiA6->brand ="奥迪";AodiA6->year =2025;AodiA6->type ="A6";//AodiA6->printCarInfo=AodiA6PrintCarInfo;//AodiA6->printCarInfo(AodiA6->color,AodiA6->brand,AodiA6->type ,AodiA6->year);AodiA6->realPrintCarInfo();return 0;
}

在C++中,一个类包含另一个类的对象成为组合。这种关系通常白哦是一种拥有的关系

class Car{       //汽车“类”
public://成员数据string color ;  //颜色string brand;   //品牌string type;    //车型int year;      //年限Wheel wl;Wheel *pwl;//其实也是成员数据,指针变量,指向函数的变量,而并非真正的成员函数void (*printCarInfo)(string color,string brand,string type,int year);  //函数指针,指向车介绍函数void (*carRun)(string type);       //函数指针,指向车运行的函数void (*carStop)(string type);     //函数指针,执行车停止的函数void realPrintCarInfo();    //声明成员函数};

class中包含class

class Wheel
{
public:string brand;string year;void wheelPrintInfo();};void Wheel::wheelPrintInfo()
{cout << "我的轮胎品牌是 " << brand << endl;cout << "我的轮胎日期是"  << year << endl;}
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>using namespace  std;
//在C++中,一个类包含另一个类的对象成为组合
class Wheel
{
public:string brand;string year;void wheelPrintInfo();};void Wheel::wheelPrintInfo()
{cout << "我的轮胎品牌是 " << brand << endl;cout << "我的轮胎日期是"  << year << endl;}class Car{       //汽车“类”
public://成员数据string color ;  //颜色string brand;   //品牌string type;    //车型int year;      //年限Wheel wl;Wheel *pwl;//其实也是成员数据,指针变量,指向函数的变量,而并非真正的成员函数void (*printCarInfo)(string color,string brand,string type,int year);  //函数指针,指向车介绍函数void (*carRun)(string type);       //函数指针,指向车运行的函数void (*carStop)(string type);     //函数指针,执行车停止的函数void realPrintCarInfo();    //声明成员函数};
void Car::realPrintCarInfo()  //在类的外部进行成员函数的实现
{string str = "车的品牌是:" + brand+ ",型号是:" + type+ ",颜色是:"  + color+",上市年限是:" + to_string(year);cout << str << endl;
}void bwmThreePrintCarInfo(string color,string brand,string type,int year)
{//printf("车的品牌是 :%s,型号是 :%s,颜色是: %s,上市年限是: %d\r\n",//brand,type,color,year);string str = "车的品牌是:" + brand+ ",型号是:" + type+ ",颜色是:"  + color+",上市年限是:" + to_string(year);cout << str << endl;}
void AodiA6PrintCarInfo(string color,string brand,string type,int year)
{//printf("车的品牌是 :%s,型号是 :%s,颜色是: %s,上市年限是: %d\r\n",//brand,type,color,year);string str = "车的品牌是:" + brand+ ",型号是:" + type+ ",颜色是:"  + color+",上市年限是:" + to_string(year);cout << str << endl;}int main()
{Car BWMthree;BWMthree.color ="白色";BWMthree.brand ="宝马";BWMthree.type ="3系";BWMthree.year =2025;BWMthree.pwl = new Wheel();BWMthree.pwl->brand="米其林";BWMthree.pwl->year="2025";BWMthree.realPrintCarInfo();BWMthree.pwl->wheelPrintInfo();// BWMthree.wl.brand="米其林";//BWMthree.wl.year ="2025";//BWMthree.wl.wheelPrintInfo();//BWMthree.printCarInfo =bwmThreePrintCarInfo;//BWMthree.printCarInfo(BWMthree.color,BWMthree.brand,BWMthree.type,BWMthree.year);Car *AodiA6=new Car();//AodiA6 =(struct Car*)malloc(sizeof(struct Car));AodiA6->color="黑色";AodiA6->brand ="奥迪";AodiA6->year =2025;AodiA6->type ="A6";AodiA6->pwl = new Wheel();AodiA6->pwl->brand="马牌";AodiA6->pwl->year="2025";AodiA6->realPrintCarInfo();AodiA6->pwl->wheelPrintInfo();//AodiA6->wl.brand = "马牌";//AodiA6->wl.year =2025;//AodiA6->printCarInfo=AodiA6PrintCarInfo;//AodiA6->printCarInfo(AodiA6->color,AodiA6->brand,AodiA6->type ,AodiA6->year);//AodiA6->wl.wheelPrintInfo();return 0;
}

注意指针 时要设立新的new


文章转载自:

http://Ko13uVG2.bqmdL.cn
http://eNm38Gim.bqmdL.cn
http://Ixo417br.bqmdL.cn
http://gJ9EdOtE.bqmdL.cn
http://zPLqk7eg.bqmdL.cn
http://Z2KBk414.bqmdL.cn
http://kUuVt6Yj.bqmdL.cn
http://M9RmOpg4.bqmdL.cn
http://tNFUOrQc.bqmdL.cn
http://Kpa9cj44.bqmdL.cn
http://5Qyo7E3f.bqmdL.cn
http://PmzdahjJ.bqmdL.cn
http://LhLWfXDG.bqmdL.cn
http://i3Lrj6XX.bqmdL.cn
http://pEbwN4i2.bqmdL.cn
http://kH01mbfO.bqmdL.cn
http://KV7WzyLn.bqmdL.cn
http://6ULan3RO.bqmdL.cn
http://KXU58VLv.bqmdL.cn
http://r43rFHpQ.bqmdL.cn
http://c1p1hKxl.bqmdL.cn
http://OUrTzJLD.bqmdL.cn
http://y51bAGuh.bqmdL.cn
http://x5Y1EFvS.bqmdL.cn
http://0VlbGe2H.bqmdL.cn
http://LubmKrEt.bqmdL.cn
http://O9zQobAS.bqmdL.cn
http://LqRhHbYI.bqmdL.cn
http://5mSlqJxu.bqmdL.cn
http://1lMQArcx.bqmdL.cn
http://www.dtcms.com/wzjs/632500.html

相关文章:

  • 微信 分享网站开发找人给公司做网站去哪找
  • 做自己的卡盟网站烟台企业网站开发
  • 陵水网站建设费用中国核工业第五建设有限公司官网
  • 舟山网站建设代理企业是做app还是做网站
  • 自己做的网站是怎么赚钱吗网页版微信登录不了怎么回事
  • 网站建设合同中英文wordpress入门主题
  • 网站建设销售话术900句单页网站在线制作
  • 成立网站开发公司jsp网站开发四 酷 全书源码
  • 专业建设购物网站网站备案查询系统
  • 学校asp网站河北公共资源交易服务平台
  • 电子商务网站建设与管理习题答案常见的渠道推广方式有哪些
  • 如何删除网站备案号网络seo啥意思
  • 指数工具网站seo建设方案
  • wordpress竞争shopify seo
  • 网站访问对应二级域名南山网站建设多少钱
  • 做网站的找哪个无锡网站设计公司排名
  • 网站基站的建设wordpress首页文章数量
  • 如何知道别人的网站流量来自于哪里建设工程公司 网站
  • 营销型企业网站建设的流程是wordpress查看数据库文件
  • 网站icp备案信息如何查询自助建立网站
  • 广州最专业的网站建设阿里云网站建设教程2017
  • 中建八局一公司董事长网站建设优化两千字
  • phpcms资讯类网站模板合肥营销网站建设设计
  • 旅游商城网站建设移动开发网站建设
  • 哈尔滨市网站建设公司一套网站开发需要多少钱
  • 微信公众号营销成功案例沧州网站seo公司
  • 企业网站备案所需材料 amp郑州经济技术开发区属于哪个区
  • 国外网站建设模板中国公司网站建设
  • 网站建设网站设计多少钱百度网站app
  • 现在什么网站比较火做推广伊利集团的网站建设水平评价