Skip to content

Commit

Permalink
Fixes to exercises after advanced session of Oct 2023
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastien Ponce authored and sponce committed Oct 16, 2023
1 parent 0bf049c commit 91ca7b5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions exercises/operators/operators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Fraction {
m_denom /= gcd;
}

int m_num, m_denom;
unsigned int m_num, m_denom;
};

// TODO: operators
Expand Down Expand Up @@ -55,7 +55,7 @@ int main() {
printAndCheck("One third times two", f, Fraction{2, 3});

f *= athird;
printAndCheck("One third times one third", f, Fraction{2, 9});
printAndCheck("Two third times one third", f, Fraction{2, 9});

// you might have some redundancy between the implementation of operator* and
// operator*=. Can you refactor your code and implement operator* in terms of
Expand Down
6 changes: 3 additions & 3 deletions exercises/operators/solution/operators.sol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ class Fraction {

private:
void normalize() {
const int gcd = std::gcd(m_num, m_denom);
auto const gcd = std::gcd(m_num, m_denom);
m_num /= gcd;
m_denom /= gcd;
}

int m_num, m_denom;
unsigned int m_num, m_denom;
};

void printAndCheck(std::string const & what, Fraction const & result, Fraction const & expected) {
Expand Down Expand Up @@ -90,7 +90,7 @@ int main() {
printAndCheck("One third times two", f, Fraction{2, 3});

f *= athird;
printAndCheck("One third times one third", f, Fraction{2, 9});
printAndCheck("Two third times one third", f, Fraction{2, 9});

// you might have some redundancy between the implementation of operator* and
// operator*=. Can you refactor your code and implement operator* in terms of
Expand Down

0 comments on commit 91ca7b5

Please sign in to comment.