Помогите с кодом. Класс, протокол класса, конструкторы, деструкторы

Всем привет, прошу помочь с заданием, не могу понять как сделать это, код получался не правильный. Пожалуйста помогите.

Создать класс, использующий массив из 40 элементов для хранения больших целых чисел к состоящим из 40 цифр. Функции-методы должны вводить, выводить, добавлять и вычитать эти великие цели. Сравнение больших целых чисел. Деление и умножение целых больших чисел.

Ниже прикрепляю сам код который я пытался сделать:

#include <iostream>
#include <cstring>

using namespace std;

class BigInt
{
private:
    int digits[40];
public:
    BigInt();
    BigInt(int num);
    void input();
    void output();
    BigInt add(BigInt other);
    BigInt subtract(BigInt other);
    int compare(BigInt other);
    BigInt multiply(BigInt other);
    BigInt divide(BigInt other);
}

BigInt::BigInt() {
    for (int i = 0; i < 40; i++) {
        digits[i] = 0;
    }
}

BigInt::BigInt(int num) {
    for (int i = 0; i < 40; i++) {
        digits[i] = num % 10;
        num /= 10;
    }
}
void BigInt::input() {
    std::string numStr;
    std::cin >> numStr;
    int len = numStr.length();
    for (int i = 0; i < len; i++) {
        digits[i] = numStr[len - i - 1] - '0';
    }
    for (int i = len; i < 40; i++) {
        digits[i] = 0;
    }
}

void BigInt::output() {
    int i = 39;
    while (i >= 0 && digits[i] == 0) {
        i--;
    }
    if (i < 0) {
        std::cout << "0";
    } else {
        for (; i >= 0; i--) {
            std::cout << digits[i];
        }
    }
}
BigInt BigInt::add(BigInt other) {
    BigInt result;
    int carry = 0;
    for (int i = 0; i < 40; i++) {
        int sum = digits[i] + other.digits[i] + carry;
        result.digits[i] = sum % 10;
        carry = sum / 10;
    }
    return result;
}

BigInt BigInt::subtract(BigInt other) {
    BigInt result;
    int borrow = 0;
    for (int i = 0; i < 40; i++) {
        int diff = digits[i] - other.digits[i] - borrow;
        if (diff < 0) {
            diff += 10;
            borrow = 1;
        } else {
            borrow = 0;
        }
        result.digits[i] = diff;
    }
    return result;
}

int BigInt::compare(BigInt other) {
    for (int i = 39; i >= 0; i--) {
        if (digits[i] > other.digits[i]) {
            return 1;
        } else if (digits[i] < other.digits[i]) {
            return -1;
        }
    }
    return 0;
}
BigInt BigInt::multiply(BigInt other) {
    BigInt result;
    for (int i = 0; i < 40; i++)

Ответы (0 шт):