Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

So I did a question about a project I've been doing and I did the most of it.I would be glad if I can get

So I did a question about a project I've been doing and I did the most of it.I would be glad if I can get the full project from someone, so I can review it.

This is how the main looks, and what have to be done to make it work. The main cannot be changed.

#include  #include "prime.hpp" #include "Uint.hpp" using namespace std; Uint fibo(size_t n) { Uint f_i_moins_1(0), f_i(1), f_i_plus_1; if (n == 0) return f_i_moins_1; if (n == 1) return f_i; for (size_t i = 2; i <= n; i++){ f_i_plus_1 = f_i_moins_1 + f_i; f_i_moins_1 = f_i; f_i = f_i_plus_1; } return f_i; } Uint factorielle(size_t n) { Uint res(1); for (size_t i = 2; i <= n; i++) res *= i; return res; } int main() { Uint a(10); cout << "Constructeur avec size_t OK "; Uint b; cout << "Constructeur vide OK "; b = 3; cout << "Affectation OK "; const Uint c = 13; cout << uint64_t(c) << " = 13: cast explicite vers uint64_t "; if (a < c) cout << "Operateur < OK "; else cout << "a < c : " << (a < c) << " pas bon!!! "; b += a; cout << "Operateur+= "; if (c == b) cout << "Comparaison == OK "; else cout << "c == b : " << (c == b) << " Operateur == ou += pas bon!!! "; a = fibo(50); cout << "fibo(50) "; b = fibo(51); const Uint d = fibo(52); if (d == a + b) cout << "Operateur+ OK "; else cout << "+ ou == pas bon!!! "; if (d - b != a) cout << "- ou != pas bon!!! "; else cout << "Operateur- OK "; a = factorielle(50); cout << "Factorielle "; b = factorielle(51); if (51 * a == b) cout << "Operateur* et *= OK "; else cout << "* ou *= ou == pas bon!!! "; if (51 != b / a) cout << "/ ou != pas bon!!! "; else cout << "Operateur/ OK "; cout << "51! en base 10 = " << b << endl; // Le modificateur set_base(...) n'affecte que la prochaine impression d'un Uint cout << set_base(16) << "Modificateur d'impression Uint "; cout << "51! en base 16 = " << b << endl; cout << "52e terme de la suite de Fibonacci, en base 10 = " << d << endl; a = 1; a <<= 99; cout << "Operateur <<= "; cout << "2 ^ 99 = " << a << endl; b = (Uint(1) << 100) -1; cout << "Operateur << "; cout << set_base(16, LOWER_CASE); cout << "2 ^ 100 - 1 (base 16, bas de casse) = " << b << endl; cout << "10 plus petits nombres premiers > 2^99 "; size_t nb = 0; while (nb < 10) { if (prime(a)) { cout << a << endl; nb++; } ++a; } cout << "10 plus grands nombres premiers < 2^100 "; nb = 0; while (nb < 10) { if (prime(b)) { cout << b << endl; nb++; } --b; } /* Rsultat de l'excution: Constructeur avec size_t OK Constructeur vide OK Affectation OK 13 = 13: cast explicite vers uint64_t Operateur < OK Operateur+= Comparaison == OK fibo(50) Operateur+ OK Operateur- OK Factorielle Operateur* et *= OK Operateur/ OK 51! en base 10 = 1551118753287382280224243016469303211063259720016986112000000000000 Modificateur d'impression Uint 51! en base 16 = EBA8F91E823EE3E18972ACC521C1C87CED2093CFDBE800000000000 52e terme de la suite de Fibonacci, en base 10 = 32951280099 Operateur <<= 2 ^ 99 = 633825300114114700748351602688 Operateur << 2 ^ 100 - 1 (base 16, bas de casse) = fffffffffffffffffffffffff 10 plus petits nombres premiers > 2^99 633825300114114700748351602943 633825300114114700748351603131 633825300114114700748351603197 633825300114114700748351603263 633825300114114700748351603341 633825300114114700748351603389 633825300114114700748351603407 633825300114114700748351603431 633825300114114700748351603467 633825300114114700748351603477 10 plus grands nombres premiers < 2^100 1267650600228229401496703205361 1267650600228229401496703205277 1267650600228229401496703205223 1267650600228229401496703205193 1267650600228229401496703205109 1267650600228229401496703205091 1267650600228229401496703205019 1267650600228229401496703204897 1267650600228229401496703204773 1267650600228229401496703204543 */ }

And this is my class Uint:

class Uint {

public:

// Constructors

Uint(); // Default constructor

Uint(size_t n); // Constructor that takes a size_t as an argument

// Overloaded operators

Uint operator+(const Uint& other) const;

Uint operator-(const Uint& other) const;

Uint operator*(const Uint& other) const;

Uint operator/(const Uint& other) const;

Uint operator%(const Uint& other) const;

Uint operator<<(size_t n) const;

Uint& operator+=(const Uint& other);

Uint& operator-=(const Uint& other);

Uint& operator*=(const Uint& other);

Uint& operator/=(const Uint& other);

Uint& operator%=(const Uint& other);

Uint& operator<<=(size_t n);

bool operator<(const Uint& other) const;

bool operator==(const Uint& other) const;

bool operator!=(const Uint& other) const;

// Other member functions

size_t get_base() const; // Returns the base that the Uint is currently in

void set_base(size_t base); // Sets the base of the Uint

size_t get_size() const; // Returns the number of digits in the Uint

void set_size(size_t size); // Sets the number of digits in the Uint

friend std::ostream& operator<<(std::ostream& out, const Uint& x); // Overloads the << operator for outputting a Uint

friend std::istream& operator>>(std::istream& in, Uint& x); // Overloads the >> operator for reading in a Uint

};

Thank you in advance

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro Database Migration To Azure Data Modernization For The Enterprise

Authors: Kevin Kline, Denis McDowell, Dustin Dorsey, Matt Gordon

1st Edition

1484282299, 978-1484282298

More Books

Students also viewed these Databases questions

Question

The formula =SUM(A1:D1) is an example of a(n) __ reference.

Answered: 1 week ago