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

C++学习day4

思维导图:

练习:

#include <iostream>
#include <cstring>
#include <cstdlib>
#include <unistd.h>
#include <sstream>
#include <vector>
#include <memory>using namespace std;class mydouble{
private:int a;int b;
public:mydouble(int a,int b):a(a),b(b){};void show(){cout << a << "." << abs(b) << endl;}mydouble operator+(const mydouble& r){mydouble AB(0,0);AB.a= a + r.a;AB.b= b + r.b;                                       return AB;}mydouble operator-(const mydouble& r){mydouble AB2(0,0);AB2.a = a - r.a;AB2.b = b - r.b;return AB2;}mydouble operator*(const mydouble& r){mydouble AB3(0,0);AB3.a = a * r.a;AB3.b = b * r.b;return AB3;}};int main(int argc,const char** argv){mydouble A(3,14);A.show();mydouble B(1,23);B.show();mydouble AB=A+B;printf("A+B的值为:");AB.show();mydouble AB2 = A-B;printf("A-B的值为:");AB2.show();mydouble AB3 = A*B;printf("A*B的值为:");AB3.show();}

#include <iostream>
#include <cstring>
#include <cstdlib>
#include <unistd.h>
#include <sstream>
#include <vector>
#include <memory>using namespace std;class myOut{
private:public:void operator<<(int a){printf("%d\n",a);cout<<a<<endl;}void operator<<(double a ){printf("%f\n",a);cout<<a<<endl;}void operator<<(const char* a){printf("%s\n",a);cout<<a<<endl;                                          }void operator<<(ostream&(*endl)(ostream&)){printf("\n");}
};
/*ostream& operator<<(ostream& out,const myOut& r)
{out<<r;
*/
int main(int argc,const char** argv){myOut out;out<<1;out<<3.14;out<<"hello";out<<endl;return 0;
}


http://www.mrgr.cn/news/96727.html

相关文章:

  • 企业linux常用服务搭建
  • SSH服务
  • 增加等IO状态的唤醒堆栈打印及缺页异常导致iowait分析
  • 设计模式 三、结构型设计模式
  • CMD(命令提示符)、PowerShell 和 Windows Terminal
  • C++练习3
  • ZGC 参数优化与 GC 触发机制解析分享
  • cpu下安装MinerU进行数据清洗
  • Linux centos 7 常用服务器搭建
  • 解决 CMS Old GC 频繁触发线上问题技术方案
  • Spring Boot向Vue发送消息通过WebSocket实现通信
  • 初学STM32系统时钟设置
  • 【SpringBoot + MyBatis + MySQL + Thymeleaf 的使用】
  • Linux基础入门指南:用户管理、基本指令(一)
  • QT 非空指针 软件奔溃
  • RAG优化:python从零实现Proposition Chunking[命题分块]让 RAG不再“断章取义”,从此“言之有物”!
  • SpringIoC和DI
  • Sink Token
  • Day3 蓝桥杯省赛冲刺精炼刷题 —— 排序算法与贪心思维
  • Redis 6.2.6 生产环境单机配置详解redis.conf