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).  Call [] from main; use it to see whether the constructors worked.  Overload << as a non-member function. It’s fine to print out the leading 0s. Call it from main. Overload += as a member function. Call it from main

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Initial code is attatched below.

Questions: 

  1. 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).  Call [] from main; use it to see whether the constructors worked. 
  2. Overload << as a non-member function. It’s fine to print out the leading 0s. Call it from main.
  3. Overload += as a member function. Call it from main.  
#include <cstdlib>
#include <iostream>
#include <string>
// 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
//
O is the least significant (units) position
unsigned short operator [](std::size_t pos) const;
// pre: none
// post: returns 1 if this biguint > b
//
O 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
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 &);
std::ostream& operator <<(std::ostream&, const biguint& ) ;
Transcribed Image Text:#include <cstdlib> #include <iostream> #include <string> // 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 // O is the least significant (units) position unsigned short operator [](std::size_t pos) const; // pre: none // post: returns 1 if this biguint > b // O 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 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 &); std::ostream& operator <<(std::ostream&, const biguint& ) ;
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education