C++(思维导图更新)

复制代码
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <unistd.h>
#include <sstream>
#include <vector>
#include <memory>
#include <math.h>
using namespace std;

class myDouble{
	private:
		int a;
		int b;
	public:
		//myDouble(int a=0,int b=0){};
		myDouble(int a=0,int b=0):a(a),b(b){}

		void show()
		{
			cout <<a<<"."<<abs(b)<<endl;
		}
		myDouble operator+(const myDouble& r){
			myDouble temp;
			temp.a=this->a+r.a;
			temp.b=this->b+r.b;
			return temp;
		}	

		myDouble operator-(const myDouble& r){    
			myDouble temp;
			temp.a=this->a-r.a;
			temp.b=this->b-r.b;
			return temp;
		}   
		/*
		   myDouble operator*(const myDouble& r){    
		   myDouble temp;
		   int ten=0,sum=0,count=0,count1=0,count2=0;
		   int m=this->b,n=r.b;
		   while(m/10!=0){count1++;m/=10;}
		   while(n/10!=0){count2++;n/=10;}
		   sum=(pow(10,count1)*this->a+this->b)*(pow(10,count2)*r.a+r.b);
		   count=count1+count2;
		   ten=pow(10,count);
		   temp.a=sum/ten;
		   temp.b=sum%ten;
		   return temp;
		   }   
		   */
		myDouble operator*(const myDouble& r) {
			myDouble temp(0, 0);
			int count1 = countdi(this->b);  // this->b的小数位数
			int count2 = countdi(r.b);      // r.b的小数位数
			long long sum = (long long)(this->a * pow(10, count1) + this->b) * (long long)(r.a * pow(10, count2) + r.b);
			int count = count1 + count2;
			temp.a = sum / pow(10, count);
			temp.b = sum % (int)pow(10, count);
			return temp;
		}
		int countdi(int num) {
			int count = 0;
			if (num == 0) {
				return 1;  // 特殊情况:0有1位
			}
			while (num != 0) {
				num /= 10;  // 每次将数字除以10,直到它变为0
				count++;    // 每除一次,位数增加1
			}
			return count;
		}
};

int main(int argc,const char** argv){
	myDouble x(3,14);
	myDouble y(2,41);
	//相加
	myDouble a=x+y;
	myDouble b=x-y;
	//a.show();//相加后的值
	a.show();
	b.show();
	myDouble z=x*y;
	z.show();
}

#include <iostream>
#include <cstring>
#include <cstdlib>
#include <unistd.h>
#include <sstream>
#include <vector>
#include <memory>
#include <math.h>
using namespace std;

class myOut{
	public:
		myOut(){}
		myOut& operator<<(const int&value){    
			printf("%d",value);
			return *this;
		}   

		myOut& operator<<(const double&value){    
			printf("%f",value);
			return *this;
		}   
		myOut& operator<<(const char*value){    
			printf("%s",value);
			return *this;
		}   
		myOut& operator<<(const myOut&(myOut&)) {
			return manip(*this);
		}



};
myOut out;
myOut endl(myOut& out)
{
	printf("\n");
	return out;
}
int main(int argc,const char** argv){
	out<<1;
	out<<3.14;
	out<<"fuck";
	out<<endl;
}
相关推荐
努力还债的学术吗喽2 分钟前
【项目】pyqt5基于python的照片整蛊项目
开发语言·python·qt
m0_569531017 分钟前
shell(4)--shell脚本中的循环:(if循环,for,while,until)和退出循环(continue,break, exit)
开发语言
星释11 分钟前
Rust 练习册 :掌握文本处理与词频统计
开发语言·后端·rust
火龙谷12 分钟前
DrissionPage遇到iframe
开发语言·前端·javascript
Boop_wu21 分钟前
[Java EE] 多线程 -- 初阶(1)
java·jvm·算法
HalvmånEver27 分钟前
Linux的第二章 : 基础的指令(二)
linux·运维·服务器·开发语言·学习
egoist202333 分钟前
[linux仓库]线程同步与生产者消费者模型[线程·陆]
linux·c语言·开发语言·线程同步·阻塞队列·生产者消费者模型
郝学胜-神的一滴36 分钟前
Linux的waitpid函数:深入解析与应用实践
linux·服务器·c++·程序人生
陌路2036 分钟前
Linux33 网络编程-多线程TCP并发
网络·算法
资深web全栈开发3 小时前
[特殊字符]图解 Golang 反射机制:从底层原理看动态类型的秘密
开发语言·后端·golang