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;
}
相关推荐
总有刁民想爱朕ha7 分钟前
车牌模拟生成器:Python3.8+Opencv代码实现与商业应用前景(C#、python 开发包SDK)
开发语言·python·数据挖掘
沐怡旸15 分钟前
【算法--链表】114.二叉树展开为链表--通俗讲解
算法·面试
一只懒洋洋1 小时前
K-meas 聚类、KNN算法、决策树、随机森林
算法·决策树·聚类
小菜全1 小时前
uniapp新增页面及跳转配置方法
开发语言·前端·javascript·vue.js·前端框架
人衣aoa1 小时前
Python编程基础(八) | 类
开发语言·python
晚云与城1 小时前
今日分享:C++ Stack和queue(栈与队列)
开发语言·c++
小莞尔1 小时前
【51单片机】【protues仿真】基于51单片机停车场的车位管理系统
c语言·开发语言·单片机·嵌入式硬件·51单片机
张烫麻辣亮。1 小时前
golang-gin包
开发语言·golang·gin
yuluo_YX1 小时前
Go Style 代码风格规范
开发语言·后端·golang
百锦再1 小时前
脚本语言的大浪淘沙或百花争艳
java·开发语言·人工智能·python·django·virtualenv·pygame