Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Could you complete this code without adding any header file? Explain your code p

ID: 3597804 • Letter: C

Question

Could you complete this code without adding any header file?

Explain your code please(Like leave a comment on each loop and statement)

----------------------------------------------------------------------------------------------------------

#include <iostream>

#include <string>

using namespace std;

class BigInt {

private:

int* arr;

int size;

public:

// constructor with size and pointer to an array

BigInt(int s, int* a) {

size = s;

arr = a;

}

// this constructor should convert str into an array of ints,

// storing the values on the RIGHT SIDE of the array :)

BigInt(string str) {

size = str.length();

arr = new int [size];

for(int i = 0; i < size; i++) {

arr[i] = str[i] - '0';

}

}

// copy constructor

BigInt(const BigInt& other) {

size = other.getSize();

arr = new int [size];

for(int i = 0; i < size; i++) {

arr[i] = other[i];

}

}

// get the size of the array

int getSize() const {

return size;

}

// this function gets the digit at 'index' from arr

// and returns 0's if 'index' is negative

int operator [] (int index) const {

if(index >= 0) {

return arr[index];

} else {

return 0;

}

}

// this function should add the argument "num"

// to the private array and return the sum

BigInt operator + (BigInt num) {

}

// this function should subtract the argument "num"

// from the private array and return the difference

BigInt operator - (BigInt num) {

}

// this function will print the BigInt

void print() {

for(int i = 0; i < size; i++) {

cout << arr[i];

}

cout << endl;

}

};

int main() {

string str1, str2;

cout << "num 1: ";

cin >> str1;

cout << "num 2: ";

cin >> str2;

BigInt num1(str1);

BigInt num2(str2);

cout << endl;

cout << "num 1: ";

num1.print();

cout << "num 2: ";

num2.print();

cout << endl;

cout << "sum: ";

BigInt sum = num1 + num2;

sum.print();

cout << "difference: ";

BigInt diff = num1 - num2;

diff.print();

// pause and exit

getchar();

return 0;

}

Explanation / Answer

#include <iostream>

#include <string>

using namespace std;

class BigInt {

private:

int* arr;

int size;

public:

// constructor with size and pointer to an array

BigInt(int s, int* a) {

size = s;

arr = a;

}

// this constructor should convert str into an array of ints,

// storing the values on the RIGHT SIDE of the array :)

BigInt(string str) {

size = str.length();

arr = new int [size];

for(int i = 0; i < size; i++) {

arr[i] = str[i] - '0';

}

}

// copy constructor

BigInt(const BigInt& other) {

size = other.getSize();

arr = new int [size];

for(int i = 0; i < size; i++) {

arr[i] = other[i];

}

}

// get the size of the array

int getSize() const {

return size;

}

// this function gets the digit at 'index' from arr

// and returns 0's if 'index' is negative

int operator [] (int index) const {

if(index >= 0) {

return arr[index];

} else {

return 0;

}

}

// this function should add the argument "num"

// to the private array and return the sum

BigInt operator + (BigInt num) {

}

// this function should subtract the argument "num"

// from the private array and return the difference

BigInt operator - (BigInt num) {

}

// this function will print the BigInt

void print() {

for(int i = 0; i < size; i++) {

cout << arr[i];

}

cout << endl;

}

};

int main() {

string str1, str2;

cout << "num 1: ";

cin >> str1;

cout << "num 2: ";

cin >> str2;

BigInt num1(str1);

BigInt num2(str2);

cout << endl;

cout << "num 1: ";

num1.print();

cout << "num 2: ";

num2.print();

cout << endl;

cout << "sum: ";

BigInt sum = num1 + num2;

sum.print();

cout << "difference: ";

BigInt diff = num1 - num2;

diff.print();

// pause and exit

getchar();

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote