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;
}
相关推荐
ankleless12 分钟前
C语言——关于指针(逐渐清晰版)
c语言·开发语言·指针·解引用操作符·c语言基础知识学习
打码农的篮球26 分钟前
STL——list
开发语言·c++·list
lkf1971134 分钟前
商品中心—1.B端建品和C端缓存
开发语言·后端·缓存
渣渣盟1 小时前
JavaScript核心概念全解析
开发语言·javascript·es6
C++ 老炮儿的技术栈1 小时前
在 Scintilla 中为 Squirrel 语言设置语法解析器的方法
linux·运维·c++·git·ubuntu·github·visual studio
小蒋的技术栈记录1 小时前
网易大模型算法岗面经80道
算法
Ress Matthew2 小时前
重塑优化建模与算法设计:2025年大模型(LLM)在优化领域的应用盘点 - 2
算法
java叶新东老师2 小时前
goland编写go语言导入自定义包出现: package xxx is not in GOROOT (/xxx/xxx) 的解决方案
开发语言·后端·golang
找不到、了2 小时前
Java排序算法之<插入排序>
java·算法·排序算法
@蓝莓果粒茶2 小时前
LeetCode第350题_两个数组的交集II
c++·python·学习·算法·leetcode·职场和发展·c#