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;
}
相关推荐
随意起个昵称19 小时前
区间dp-基础题目1(石子合并)
算法·动态规划
吞下星星的少年·-·20 小时前
线段树模板
算法
星空椰20 小时前
Python 面向对象高级:继承与类定义详解
开发语言·python
wunaiqiezixin20 小时前
如何在C++中创建和管理线程
c++
段一凡-华北理工大学20 小时前
2026 高炉炼铁智能化技术全景与演进路径~系列文章11:演进路径与行业未来
大数据·网络·人工智能·算法·工业智能体·高炉炼铁智能化
白露与泡影20 小时前
2026大厂Java面试题大全!牛客网最新版
java·开发语言
凯瑟琳.奥古斯特20 小时前
高阶子查询题目精炼
开发语言·数据库·python·职场和发展·数据库开发
雪度娃娃20 小时前
转向现代C++——在意为改写的函数添加 override
开发语言·c++
王老师青少年编程20 小时前
csp信奥赛C++高频考点专项训练之前缀和&差分 --【一维差分】:[NOIP 2018 提高组] 铺设道路
c++·前缀和·差分·csp·高频考点·信奥赛·铺设道路
叶小鸡20 小时前
小鸡玩算法-力扣HOT100-多维动态规划
算法·leetcode·动态规划