Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a new class called BigNumber Class with the below sepcifications. The main program doesnt neeed to be written just the class. the header file

Create a new class called BigNumber Class with the below sepcifications. The "main" program doesnt neeed to be written just the class. the header file and cpp file is given but i need it changed from dynamic arrays to vectors.

Add a new constructor the BigNumber class. The constructors one parameter is a string. Use the isdigit function to verify that the elements of the string are char versions of digits. To convert a char version of a digit to an int, subtract 48 from the character. What do you do about elements of the string that are not char versions of digits? You decide

Move the add function from the main function to the BigNumber class. Rewrite the add function to use the private vector of integers to compute the product.

The function is incomplete. Some statements are missing from the function. Supply the missing statements.

Test the function thoroughly

Write a private one parameter function that compares two BigNumber objects. The function returns -1 if the first BigNumber is less than the second BigNumber, 0, if the two BigNumber objects are equal, and 1 if the first BigNumber is greater than the second BigNumber. Compare the BigNumber objects digit by digit. Do not convert BigNumber objects to actual numbers.

1 Move the sub function from the main function in file source.cpp to the BigNumber class.

2 Rewrite the sub function to use the private vector of integers to subtract one BigNumber from another BigNumber.

3 The sub function sometimes crashes with a run time error when it tries to subtract a larger BigNumber from a smaller BigNumber. Use the compare function to make sure that the sub function never subtracts a larger BigNumber from a smaller BigNumber.

4 The sub function contains statements that are necessary because the function sometimes subtracts a larger BigNumber from a smaller BigNumber. If you completed step 3 of this problem, then these statements are unnecessary. Remove the unnecessary statements. If you did not complete step 3 then you must change the BigNumber version of this statement,

dynamicArray d12(max(size1, size2));

to stop the functions crashing.

5 For extra credit, explain why the above statement crashes the function

//.cpp file.

image text in transcribed

#include

#include

#include "BigNumber.h"

using namespace std;

const dynamicArray& dynamicArray::operator=(const dynamicArray& source)

{

if (this != &source)

{

delete[] _elts;

copy(source);

}

return *this;

}

dynamicArray::dynamicArray(int new_size)

{

_size = new_size;

_elts = new int[_size];

for (int i = 0; i

_elts[i] = 0;

}

dynamicArray::dynamicArray(const dynamicArray& source)

{

copy(source);

}

dynamicArray::~dynamicArray()

{

delete[] _elts;

_elts = nullptr;

_size = -1;

}

void dynamicArray::copy(const dynamicArray& source)

{

_size = source._size;

_elts = new int[_size];

for (int i = 0; i

_elts[i] = source._elts[i];

}

int dynamicArray::get(int where) const

{

assert(0

return _elts[where];

}

int dynamicArray::size() const

{

return _size;

}

void dynamicArray::put(int where, int new_elt)

{

assert(0

_elts[where] = new_elt;

}

void dynamicArray::show() const

{

for (int i = _size - 1; i >= 0; --i)

cout

}

image text in transcribed

| |#pragma once 2 class dynamicArray 3 4 public: 5 6 7 8 9 const dynamicArray& operator-(const dynamicArray& source); dynamicArray(int new size = 16) dynamicArray (const dynamicArray& source); dynamicArray(); int get(int where) const; int size() const; void put (int where, int what); 10 12 13 14 15 private: 16 17 18 19 1; 20 21 void show) const; void copy (const dynamicArray& source); int _size; int elts | |#pragma once 2 class dynamicArray 3 4 public: 5 6 7 8 9 const dynamicArray& operator-(const dynamicArray& source); dynamicArray(int new size = 16) dynamicArray (const dynamicArray& source); dynamicArray(); int get(int where) const; int size() const; void put (int where, int what); 10 12 13 14 15 private: 16 17 18 19 1; 20 21 void show) const; void copy (const dynamicArray& source); int _size; int elts

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

Step: 3

blur-text-image

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

Data Analytics Systems Engineering Cybersecurity Project Management

Authors: Christopher Greco

1st Edition

168392648X, 978-1683926481

More Books

Students also viewed these Databases questions

Question

2. What are the components of IT infrastructure?

Answered: 1 week ago