高进度头文件计划

还未完全完结,会更新的。
已经通过Visual Studio 2017 编译测试。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
ps:4133chen
update:2019/3/10
web:https://cxy4133.top
mail:f20020101@163.com
*/
#ifndef _H_P_C
#define _H_P_C
#include<string>
#include<iostream>
#include<cstdlib>

enum binary_system_switch { BIN, OCT, DEC, HEX };

class high
{
public:
high(std::string x, binary_system_switch y = DEC) //类构造函数 (数字本体,基数,)
{
_main = x;
b_s = y;
decimal_point = decimal_poinit_find(x);
}
int decimal_poinit_find(std::string a)
{
for (int i = 0; i <= (int)a.length() - 1; i++)
{
if (a[i] == '.')return i;
}
return -1;
}
high(void)
{
return;
}
friend bool binary_carry(high temp); //进位(在每次的计算完成以后)
friend high operator+(const high x, const high y); //加法的重载
friend void print(high x);
private:
std::string _main; //输入的数据用字符串类型按位存储
int decimal_point; //小数点的标记
binary_system_switch b_s; //基数选择
};

int decimal_point_find(std::string a) //小数点位置寻找
{
int mark = -1;
for (int i = 0; i <= (int)a.length(); i++)
{
if ((a[i] == '.' )or( a[i] == ','))mark = i;
}
if (mark == -1)
{
exit(1);
}
else
{
return mark;
}
}

void print(high x)
{
std::cout << x._main;
return;
}

bool string_move_right(std::string & x, int step) //字符串右移
{
std::string temp;
for (int i = 1; i <= (int)x.length(); i++)
{
temp[i] = x[i - 1];
}
x = temp;
return true;
}

bool binary_carry(high temp)
{
int _mod;
int temp_int;
switch (temp.b_s)
{
case BIN:
_mod = 2;
break;
case OCT:
_mod = 8;
break;
case DEC:
_mod = 10;
break;
case HEX:
_mod = 16;
break;
}
for (int i = temp._main.length() - 1; i >= 0; i++)
{
if (temp._main[i] >= _mod + '0')
{
if (i == 0)
{
string_move_right(temp._main, 1);
}
temp_int = (temp._main[i] - '0') % _mod;
temp._main[i - 1] = (temp._main[i - 1] - '0') + temp_int;
}
}
return true;
}

high operator+(const high x, const high y)
{
high z;
for (int i = 0; i <(int)(x._main.length() <= y._main.length() ? x._main.length() : y._main.length())-1; i++)
{
z._main[i] = (x._main[i] - '0') + (y._main[i] - '0') + '0';
}
binary_carry(z._main);
z.decimal_point = decimal_point_find(z._main);
return z;
}

#endif

既然看了33写的文章,不打算投喂一下再走吗?哼!