It is a netizen post asked. I helped him get the addition. After subtraction, I will make up.
#include
Char * Integer; Bool NEGATIVE; Public: Myint () {}; myint (int LEN); myint (char * s); // ~ myint (); This is not available. The system is automatically recovered. Mainly a string space , Another function is released. Const void operator = (myint s) // does not need to use & {integer = new char [strlen (S.Integer) 1]; // private member is accessible just like .STRCPY (Integer, sinteger; negative = s.negative;} Friend Myint Operator (Const Myint & Left, Const Myint & Right); // Solving Friends Void Display () {for (INT I = Strlen (Integer) -1; I> = 0; I -) // To reverse the output cout << integer [i]; couid freeint () / / Call when the space is released here. Class members only provide a char * Pointer, pointer refers to this type of this class. {Delete integer;}}; myint :: myint (int LEN) {integer = new char [len]; negative = false;} myint :: Myint (char * s) {INT i = Strlen (s), j = 0, t = 0; Negative = false; if (s [0] == '-' || s [0] == ' ') // Judgment S symbol Question, if it is a negative, other cases do not store {t = 1; if (s [0] == '-') Negative = true; integer = new char [i]; / change} else integer = new Char [i 1]; / change I -; while (i> = t) {IF (s [i] <0 '|| s [i]>' 9 ') {cout << "set error "<< Endl; i = -1;} else {integer [j] = s [i]; - i; j;} // Save S in Integer} Integer [J] = '/ 0';} Myint Operator (const myint & left, const myint & right) / / It is best to return. No use. {INT i, j = 0; int a; int = Strlen (Left.integer); int Right.integer; int maxlen = (Leftlen> Rightlen? LEFTLEN: Rightlen) 1; Myint T (Maxlen 1); if (Left.Negative == Right.negative) // {同 同 号 号 号 号 (为 为 为 为 为 为 为 为 为 为 为 为 为 为 为 为 为 为 为 为 为 为 为 为 为 为 为 为 为 为 为 为 为 为 为 为
Right.integer [I] - '0' J; // T.INTEGER [I] = Left.integer [i] - '0' Right.integer [i] - '0' J; you didn't Wrong, just think that it is more clear. J = A / 10; T.INTEGER [i] = a% 10 '0';} if (leftlen> rightlen) for (; i