Modular array implemented with a string array

xiaoxiao2021-03-14  208

/ * Write a class that calculates a large number of four computational categories (multiplication and division and writing, readers can be derived by themselves). This kind of thought is to represent a large number with a string array, which is not the best and most effective. Method, But it works:) i_love_cpp * /

class CLargeNumberS {public: CLargeNumberS (char * pStr) {m_pStrIn = pStr; m_pStrOut = NULL; m_nLen = strlen (m_pStrIn);} ~ CLargeNumberS () {if (m_pStrOut) delete [] m_pStrOut;} CLargeNumberS (CLargeNumberS & N) {m_pStrIn = N.m_pstrin; m_pstrout = null; m_nlen = strlen;} const char * Operator {if (m_pstrout) delete [] m_pstrout; m_pstrout = new char [Max (m_nlen, n.m_nlen) 2]; int i = m_nlen-1, j = n.m_nlen-1, k = 0, n = 0; // incoming int NTEMP; while (true) {IF ((i <0) && (j <0 )) {IF (n> 0) m_pstrout [k ] = N '0'; Break;} else if (i <0) ntemp = n.m_pstrin [j] n; else if (j <0) ntemp = m_pstrin [i] n; else ntemp = m_pstrin [i] n.m_pstrin [j] n - '0'; n = 0; if (ntemp> '9') {// two numbers plus, up to Before 1, there is no need for while ntemp = ntemp - 10; n; // forward 1} m_pstrout [k] = nTemp; --i; - j; k;} m_pstrout [k] = 0 ; // string end value // reverse string char A; for (i = 0; i

Const char * Operator - (CLARGENUMBERS & N) {if (m_pstrout) delete [] m_pstrout; m_pstrout = new char [Max (m_nlen, n.m_nlen) 2]; int i = m_nlen-1, j = n.m_nlen-1 , K = 0, n = 0; // Liberal INT nTemp; // For simplification of calculation, first compare two numbers of size if (m_nlen 0) m_pstrout [k ] = '-'; BREAK } // else if (i <0) does not appear else if (j <0) ntemp = m_pstrin [i] - n; Else Ntemp = m_pstrin [i] - n.m_pstrin [j] - n; IF (NTEMP <'0') {ntemp = n '0' - m_pstrin [i]; n = 1; // forward 1} --i; - j; k;} m_pstrout [k] = 0; // String end control // reverse string char A; for (i = 0; i

转载请注明原文地址:https://www.9cbs.com/read-129329.html

New Post(0)