Answered step by step
Verified Expert Solution
Question
1 Approved Answer
my divison should work, but I have an error with my operator-= when i try to substract reminder-=tmp.nb . How can I fix it? This
my divison should work, but I have an error with my operator-= when i try to substract reminder-=tmp.nb.
How can I fix it?
This is my code:
//my class Uint.hpp
class Uint { private: string nb; //variable public: // Constructors Uint(); // Default constructeur Uint(size_t n); // Constructeur avec size_t
Uint& operator*=(const Uint& other);
friend Uint operator*(Uint lhs, const Uint & rhs);
//my file Uint.cpp
Uint::Uint() = default; Uint::Uint(size_t n){ string u; while (n > 0) { if (n % 2 == 0) u.insert(u.begin(), '0'); else u.insert(u.begin(), '1'); n /= 2; } this->nb = u; }
Uint& Uint::operator/=(const Uint& autre){ Uint remainder; Uint div; Uint tmp=autre; if(nb==tmp.nb){ div.nb+='1'; } else { for (int i = 0; i < nb.size(); i++) { remainder += nb[i]; int w = stoi(remainder.nb, nullptr, 2); int ww = stoi(tmp.nb, nullptr, 2); if (remainder.nb.size() < tmp.nb.size()) { div.nb += "0"; } else if (remainder.nb.size() >= tmp.nb.size() && (w - ww > 0)) { div.nb += "1"; //The problem si here -->>> remainder-=tmp.nb; } else div.nb += '0'; } } div.eraseZero(); return *this=div; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started