Home c++ C++ "Cl.exe" ended with code 2

C++ “Cl.exe” ended with code 2

Author

Date

Category

It’s not how I can’t understand and do with the error “cl.exe” ended with the code 2. I don’t even know what she says about. The error disappears if you remove the line in Int main (); a – = g; . How to fix it and did not understand. (I apologize for the big code)

# include & lt; iostream & gt;
#Include & lt; vector & gt;
#Include & lt; String & GT;
#Include & lt; Functional & gt;
#Include & lt; algorithm & gt;
//////////////////////////////////////// // ////////////////////////////////// //
//////////////////////////////////////// // ////////////////////////////////// //
//////////////////////////////////////// // ////////////////////////////////// //
//////////////////////////////////////// // ////////////////////////////////// //
//////////////////////////////////////// // ////////////////////////////////// //
Class monomial {
Public:
  void get_num (std :: string :: iterator & amp; it, int & amp; num, const std :: string & amp; str) const {
    While (IT! = str.end () & amp; & amp; '0' & lt; = * it & amp; & amp; * it & lt; = '9') {
      num + = * it - '0';
      num * = 10;
      ++ IT;
    }
    num / = 10;
  }
  Monomial (int x): COEF (X), DEEGS (26) {}
  Monomial (std :: string str = ""): degs (26) {// Example Input: + 21x71z1
    if (str.size () == 0) {
      COEF = 0;
      Return;
    }
    STD :: STRING :: ITERATOR IT = STR.BEGIN ();
    COEF = 0;
    if (* it == '-') {
      ++ IT;
      get_num (IT, COEF, STR);
      COEF * = -1;
    } else {
      ++ IT;
      get_num (IT, COEF, STR);
    }
    INT CURR_X = 0;
    While (IT! = str.end ()) {
      CURR_X = * IT - 'A';
      ++ IT;
      INT CURR_DEEG = 0;
      get_num (IT, CURR_DEEG, STR);
      DEEGS [CURR_X] = CURR_DEEG;
    }
  }
  Monomial (Const int & amp; COEF_TMP, const std :: vector & lt; int & gt; & amp; degs_tmp): coef (coef_tmp), degs (degs_tmp) {}
  int get_coef () const {
    RETURN COEF;
  }
  INT Operator [] (Size_t i) Const {
    RETURN DEEGS [I];
  }
  BOOL IS_EQUAL (CONST Monomial & Amp; Other) Const {
    For (Size_t i = 0; i & lt; 26; ++ i) {
      if (degs [i]! = Other [i]) {
        Return 0;
      }
    }
    Return 1;
  }
  BOOL IS_DIV (Const Monomial & Amp; Other) Const {
    Size_t i = 0;
    For (Size_t i = 0; i & lt; 26; ++ i) {
      if (degs [i] & lt; other [i]) {
        RETURN FALSE;
      }
    }
    RETURN TRUE;
  }
  AUTO Begin () Const {
    Return degs.begin ();
  }
  AUTO END () CONST {
    Return degs.end ();
  }
  AUTO RBEGIN () Const {
    Return degs.rbegin ();
  }
  AUTO REND () CONST {
    Return degs.rend ();
  }
  Monomial & amp; Operator * = (int x) {
    COEF * = X;
    RETURN * THIS;
  }
  Monomial Operator * (int x) const {
    Monomial tmp_m = * this;
    Return TMP_M * = X;
  }
  Monomial & amp; Operator * = (Const Monomial & Amp; Other) {
    Coef * = Other.get_coef ();
    For (Size_t i = 0; i & lt; 26; ++ i) {
      Degs [i] + = Other [i];
    }
    RETURN * THIS;
  }
  Monomial Operator * (Const Monomial & Amp; Other) Const {
    Monomial tmp_m = * this;
    RETURN TMP_M * = * THIS;
  }
  Monomial & amp; Operator + = (Const Monomial & Amp; Other) {
    // Check for Equal
    COEF + = Other.Get_Coef ();
    RETURN * THIS;
  }
  Monomial Operator + (Const Monomial & Amp; Other) Const {
    Monomial TMP_M;
    RETURN TMP_M + = OTHER;
  }
  Monomial Operator / (Const Monomial & Amp; Other) Const {
    std :: vector & lt; int & gt; TMP_Deegs (26);
    For (Size_t i = 0; i & lt; 26; ++ i) {
      TMP_Deegs [i] = Degs [i] - Other [i];
    }
    RETURN {COEF / Other.get_coef (), TMP_Deegs};
  }
  BOOL OPERATOR == (Const Monomial & Amp; Other) Const {
    RETURN IS_EQUAL (OTHER);
  }
  BOOL OPERATOR! = (Const Monomial & Amp; Other) Const {
    Return! (IS_EQUAL (Other));
  }
Private:
  INT COEF;
  std :: vector & lt; int & gt; degs; 
};
////////////////////////////////////////////////// //////////////////////////////////////
////////////////////////////////////////////////// //////////////////////////////////////
////////////////////////////////////////////////// //////////////////////////////////////
////////////////////////////////////////////////// //////////////////////////////////////
////////////////////////////////////////////////// //////////////////////////////////////
class MonomialOrder {
Public:
  MonomialOrder () {}
  MonomialOrder (const std :: vector & lt; std :: function & lt; bool (const Monomial & amp ;, const Monomial & amp;) & gt; & gt; & amp; tmp_mon_ord) {
    orders = tmp_mon_ord;
  }
  void add_order (const std :: function & lt; bool (const Monomial & amp ;, const Monomial & amp;) & gt; & amp; func) {
    orders.push_back (func);
  }
  std :: function & lt; bool (const Monomial & amp ;, const Monomial & amp;) & gt; & amp; operator [] (size_t i) {
    return orders [i];
  }
  bool compair_less (const Monomial & amp; mon1, const Monomial & amp; mon2) const {
    for (auto func: orders) {
      if (func (mon1, mon2)! = func (mon2, mon1)) {
        return func (mon1, mon2);
      }
    }
    return 0;
  }
  //! (Pravlno not as it should be without the first parameter to the method) [correctly as this class of Order]
  bool compair_less_or_eq (const Monomial & amp; mon1, const Monomial & amp; mon2) const {
    for (auto func: orders) {
      if (func (mon1, mon2)! = func (mon2, mon1)) {
        return func (mon1, mon2);
      }
    }
    return 1;
  }
private:
  std :: vector & lt; std :: function & lt; bool (const Monomial & amp ;, const Monomial & amp;) & gt; & gt; orders;
};
bool lexicograph (const Monomial & amp; mon1, const Monomial & amp; mon2) {
  for (size_t i = 0; i & lt; 26; ++ i) {
    if (mon1 [i]! = mon2 [i]) {
      return mon1 [i] & lt; mon2 [i];
    }
  }
  return 0;
}
////////////////////////////////////////////////// //////////////////////////////////////
////////////////////////////////////////////////// //////////////////////////////////////
////////////////////////////////////////////////// //////////////////////////////////////
////////////////////////////////////////////////// //////////////////////////////////////
////////////////////////////////////////////////// //////////////////////////////////////
class Polynomial {
Public:
  Polynomial () {}
  Polynomial (const Monomial & amp; other_mon) {
    monoms.push_back (other_mon);
  }
  std :: vector & lt; Monomial & gt; & amp; get_monoms () {
    return monoms;
  }
  size_t size () const {
    return monoms.size ();
  }
  void dell_same_monoms_or_add (const Monomial & amp; other) {
    for (auto & amp; monom: monoms) {
      if (monom.is_equal (other)) {
        monom + = other;
        Return;
      }
    }
    monoms.push_back (other);
  }
  // Same fragments
  Polynomial & amp; operator + = (const Monomial & amp; other) {
    bool diff = true;
    for (size_t i = 0; i & lt; monoms.size (); ++ i) {
      if (monoms [i] .is_equal (other)) {
        monoms [i] + = other.get_coef ();
        diff = false;
      }
    }
    if (diff) {
      monoms.push_back (other);
    }
    return * this;
  }
  Polynomial operator + (const Monomial & amp; other) const {
    Polynomial tmp_p = * this;
    return tmp_p + = other;
  }
  Monomial operator [] (const size_t & amp; i) const {
    return monoms [i];
  }
  Polynomial & amp; operator + = (const Polynomial & amp; other) {
    for (const auto & amp; mon_from_other: other.monoms) {
      * This + = mon_from_other;
    }
  }
  Polynomial operator + (const Polynomial & amp; other) const {
    Polynomial tmp_pol = * this;
    return tmp_pol + = other;
  }
  Polynomial & amp; operator * = (const int x) {
    for (auto & amp; mon: monoms) {
      mon * = x;
    }
    return * this;
  }
  Polynomial operator * (const int x) const {
    Polynomial tmp_p = * this;
    return tmp_p * = x;
  }
  Polynomial & amp; operator * = (const Polynomial & amp; other) { 
Polynomial TMP_P = * this;
    monoms.clear ();
    For (Const Auto & Amp; Mon_From_This: TMP_P.monoms) {
      For (Const Auto & Amp; mon_from_other: other.monoms) {
        * this + = mon_from_this * mon_from_other;
      }
    }
    RETURN * THIS;
  }
  Polynomial Operator * (Const Polynomial & Amp; Other) Const {
    Polynomial TMP_P = * this;
    RETURN TMP_P * = OTHER;
  }
  AUTO Begin () Const {
    Return monoms.begin ();
  }
  AUTO END () CONST {
    Return monoms.end ();
  }
  Polynomial & amp; Operator - = (Const Polynomial & amp; Other) {
    For (Size_t i = 0; i & lt; size (); ++ i) {
      monoms [i] * = -1;
    }
    * this + = Other;
    For (Size_t i = 0; i & lt; size (); ++ i) {
      monoms [i] * = -1;
    }
    RETURN * THIS;
  }
  Polynomial Operator - (Const Polynomial & Amp; Other) Const {
    Polynomial TMP_P = * this;
    Return TMP_P - = OTHER;
  }
  Void Sort_POL (Const MonomialOrder & Amp; ORD) {
    STD :: SORT.
    (
      monoms.begin ()
      , monoms.end ()
      , [& amp; ORD] (Monomial Const & amp; Mon1, Monomial Const & Amp; Mon2)
      {
        Return Ord.comPair_Less (Mon1, Mon2);
      }
    );
  }
  Size_t Size () {
    Return monoms.size ();
  }
  AUTO RBEGIN () Const {
    Return monoms.rbegin ();
  }
  AUTO REND () CONST {
    Return monoms.rend ();
  }
Private:
  std :: vector & lt; monomial & gt; Monoms;
};
INT MAIN () {
  Monomial F1 ("+ 1A1B2"), F2 ("- 1A1B1C2"), F3 ("+ 1B4C1");
  Monomial a1 ("+ 2a2b2"), a2 ("+ 2a1b4c1"), a3 ("+ 1b4c6");
  Monomial g1 ("+ 1a2b2"), g2 ("+ 2a1b4c1"), g3 ("+ 1a4c6");
  POLYNOMIAL F, G, ANS, A;
  f + = f1;
  f + = f2;
  f + = f3;
  G + = G1;
  G + = G2;
  G + = G3;
  a + = a1;
  a + = a2;
  a + = a3;
  a - = g;
  Return 0;
}

Added to Monomial:

monomial & amp; Operator * = (Const int & amp; x) {
  COEF * = X;
  RETURN * THIS;
}
Monomial Operator * (Const int & amp x) const {
  Monomial tmp_m = * this;
  Return TMP_M * = X;
}

And in Polynomial changed Polynomial & amp; Operator – = (Const Polynomial & Amp; Other) on:

polynomial & amp; Operator - = (Const Polynomial & amp; Other) {
    For (Size_t i = 0; i & lt; size (); ++ i) {
      monoms [i] * = -1;
    }
    * this + = Other; // for some reason, if you remove this line, the error disappears
    For (Size_t i = 0; i & lt; size (); ++ i) {
      monoms [i] * = -1;
    }
    RETURN * THIS;
  }

But still does not work: (


Answer 1, Authority 100%

Forgot Return in Polynomial & Amp; Operator + = (Const Polynomial & Amp; Other);

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions