Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in C++, please solve it step by step. thank you 1. Write the default constructor. It should simply fill in the array with 0s. Call

in C++, please solve it step by step. thank you

1. Write the default constructor. It should simply fill in the array with 0s. Call it from main (though you wont be able to see whether it was created correctly).

2. Explain how you plan to write the constructor that takes in a string. How can you convert the character 5 to the number 5? Recall your character arithmetic.

3. Write the constructor that takes in a string. Be sure to fill all the extra spots with 0. Call it from main (though you wont be able to see whether it was created correctly).

4. Overload the [] operator to return the ith digit in the biguint (use the array indexing; so if they do [0] you will give the digit in the ones place). What should your function return if the value in a is 1472 and a[900] is called? Call [] from main; use it to see whether the constructors worked.

5. Overload << as a non-member function. Its fine to print out the leading 0s. Call it from main.

6. Explain how you plan to overload +=. Think about how you learned to add in elementary school.

7. Overload += as a member function. Call it from main.

Start from the header file you can find here:

#ifndef BIGUINT_H

#define BIGUINT_H

#include

#include

#include

// WANT: integers with CAPACITY digits, only non-negative

//

// support:

// 2 constructors: int, string

// member functions: [] returns individual digits given position

// +=

// -=

// compare: return +1, 0, -1, depending on

// whether this biguint >, ==, < than given biguint

// +, - (binary), - (unary), <, <=, ==, !=, >=, >

// <<, >>

class biguint

{

public:

// CONSTANTS & TYPES

static const std::size_t CAPACITY = 20;

// CONSTRUCTORS

// pre: none

// post: creates a biguint with value 0

biguint();

// pre: s contains only decimal digits

// post: creates a biguint whose value corresponds to given string of digits

biguint(const std::string &);

// CONSTANT MEMBER FUNCTIONS

// pre: pos < CAPACITY

// post: returns the digit at position pos

// 0 is the least significant (units) position

unsigned short operator [](std::size_t pos) const;

// pre: none

// post: returns 1 if this biguint > b

// 0 if this biguint == b

// -1 if this biguint < b

int compare(const biguint & b) const;

// MODIFICATION MEMBER FUNCTIONS

// pre: none

// post: b is added to this biguint; ignore last carry bit if any

void operator += (const biguint & b);

void operator -= (const biguint & b);

private:

unsigned short data_[CAPACITY];

// INVARIANTS:

// data_[i] holds the i^th digit of this biguint or 0 if not used

// data_[0] holds the least significant (units) digit

};

// nonmember functions

std::ostream& operator <<(std::ostream& out, const biguint& b);

biguint operator + (const biguint &, const biguint &);

biguint operator - (const biguint &, const biguint &);

bool operator < (const biguint &, const biguint &);

bool operator <= (const biguint &, const biguint &);

bool operator != (const biguint &, const biguint &);

bool operator == (const biguint &, const biguint &);

bool operator >= (const biguint &, const biguint &);

bool operator > (const biguint &, const biguint &);

#endif // BIGUINT_H

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

Advanced Database Systems For Integration Of Media And User Environments 98

Authors: Yahiko Kambayashi, Akifumi Makinouchi, Shunsuke Uemura, Katsumi Tanaka, Yoshifumi Masunaga

1st Edition

9810234368, 978-9810234362

More Books

Students also viewed these Databases questions

Question

Mention the bases on which consumer market can be segmented.

Answered: 1 week ago

Question

Explain consumer behaviour.

Answered: 1 week ago

Question

Explain the factors influencing consumer behaviour.

Answered: 1 week ago