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;
}
相关推荐
生成论实验室7 分钟前
《事件关系阴阳博弈动力学:识势应势之道》第二篇:阴阳博弈——认知的动力学基础
数据结构·人工智能·科技·神经网络·算法
li16709027019 分钟前
第二十七章:智能指针
c语言·数据结构·c++·visual studio
We་ct36 分钟前
深度剖析浏览器跨域问题
开发语言·前端·浏览器·跨域·cors·同源·浏览器跨域
风筝在晴天搁浅37 分钟前
字节高频题 小于n的最大数
算法
LabVIEW开发39 分钟前
LabVIEW水力机组空蚀在线监测
算法·labview·labview知识·labview功能·labview程序
AI科技星44 分钟前
科幻艺术书本封面:《全域数学》第一部·数术本源 第三卷 代数原本(P95-141)完整五级目录【乖乖数学】
算法·机器学习·数学建模·数据挖掘·量子计算
skywalk816344 分钟前
在考虑双轨制,即在中文语法的基础上,加上数学公式的支持,这样像很多计算将更加简单方便,就像现在的小学数学课本里面一样,比如:定x=2*x + 1
开发语言
风筝在晴天搁浅1 小时前
LeetCode 92.反转链表Ⅱ
算法·leetcode·链表
小书房1 小时前
Kotlin的by
android·开发语言·kotlin·委托·by
王老师青少年编程1 小时前
csp信奥赛C++高频考点专项训练之贪心算法 --【贪心与二分判定】:数列分段 Section II
c++·算法·贪心·csp·信奥赛·二分判定·数列分段 section ii