Перейти из форума на сайт.

НовостиФайловые архивы
ПоискАктивные темыТоп лист
ПравилаКто в on-line?
Вход Забыли пароль? Первый раз на этом сайте? Регистрация
Компьютерный форум Ru.Board » Компьютеры » Прикладное программирование » Задачи по C/С++

Модерирует : ShIvADeSt

 Версия для печати • ПодписатьсяДобавить в закладки
На первую страницук этому сообщениюк последнему сообщению

Открыть новую тему     Написать ответ в эту тему

Stitchi16

Junior Member
Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору
#include <iostream>
 
using namespace std;
 
class BigInt
{
    int mas[64];
public:
    // конструкторы:
    // конструктор по умолчанию
    BigInt()
    {
        for (int i = 0; i < 64; i++)
        {
            mas[i] = 0;
        }
    }
    // конструктор с параметрами
    BigInt(int n)
    {
        while (n >= 10)
        {
            cout << "Enter other number: ";
            cin >> n;
        }
        for (int i = 0; i < 64; i++)
        {
            mas[i] = n;
        }
}
    // конструктор копирования
    BigInt(const BigInt &b)
    {
        for (int i = 0; i < 64; i++)
        {
            mas[i] = b.mas[i];
        }
    }
    // деструктор
    ~BigInt()
    {}
    // перегрузка операторов:
    // ввод
    friend ifstream &operator << (ifstream &out, const BigInt &b);
    // вывод
    friend ofstream &operator << (ofstream &out, const BigInt &b);
 
    // операция сравнения "<"
    bool operator < (BigInt b) const
    {
        cout << "\nComparsion operation(<)\n";
        for (int i = 0; i < 64; i++)
        {
            return (mas[i] < b.mas[i]) ? true : false;
        }
    }
    // операция сравнения ">"
    bool operator > (BigInt b) const
    {
        cout << "\nComparsion operation(>)\n";
        for (int i = 0; i < 64; i++)
        {
            return (mas[i] > b.mas[i]) ? true : false;
        }
    }
    // операция сравнения "=="
    bool operator == (BigInt b) const
    {
        cout << "\nComparsion operation(==)\n";
        for (int i = 0; i < 64; i++)
        {
            return (mas[i] == b.mas[i]) ? true : false;
        }
    }
    // сложение
    BigInt operator + (BigInt b) const
    {
        cout << "\nAddition(+):\n";
        int mastemp[64];
        for (int i = 0; i < 64; i++)
        {
            mastemp[i] = mas[i] + b.mas[i];
 
            return BigInt(mastemp[i]);
        }
    }
    // вычитание
    BigInt operator - (BigInt b) const
    {
        cout << "\nSubtraction(-):\n";
        int mastemp[64];
        for (int i = 0; i < 64; i++)
        {
            mastemp[i] = mas[i] - b.mas[i];
 
            return BigInt(mastemp[i]);
        }
    }
    // !умножение
    BigInt operator * (BigInt b) const
    {
        cout << "\nMultiplication(*):\n";
        int mastemp[64];
        for (int i = 0; i < 64; i++)
        {
            mastemp[i] = mas[i] * b.mas[i];
 
            return BigInt(mastemp[i]);
        }
    }
    // !деление
    BigInt operator / (BigInt b) const
    {
        cout << "\nDivision(/):\n";
        int mastemp[64];
        for (int i = 0; i < 64; i++)
        {
            mastemp[i] = mas[i] / b.mas[i];
        }
        return mastemp[64];
    }
    // преобразование типов
    operator char () const
    {
    }
    // методы:
    void printMas() const
    {
        for (int i = 0; i < 64; i++)
        {
            cout << "Elemet massive: " << i << "\t" << " - Number: " << mas[i] << "\n";
        }
    }
};
//
ostream &operator << (ostream &out, const BigInt &b)
    {
        for (int i = 0; i < 64; i++)
        {
            //out << b.mas[i] << "\n";
 
            return out;
        }
    }
//
 
int main()
{
    int n1, n2;
    
    cout << "Enter initial value of the first big integer: ";
    cin >> n1;
    BigInt b1(n1);
 
    cout << "Enter initial value of the second big integer: ";
    cin >> n2;
    BigInt b2(n2);
 
    if (b1 < b2)
        cout << "b1 < b2\n";
    else
        cout << "b2 >= b2\n";
 
    if (b1 > b2)
        cout << "b1 > b2\n";
    else
        cout << "b2 <= b2\n";
 
    if (b1 == b2)
        cout << "b1 == b2\n";
    else
        cout << "b2 != b2\n";
 
    BigInt b3;
    b3 = b1 + b2;
    b3.printMas();
    b3 = b1 - b2;
    b3.printMas();
    b3 = b1 * b2;
    b3.printMas();
    b3 = b1 / b2;
    b3.printMas();
 
    getchar();
    getchar();
 
    return 0;
}

Всего записей: 37 | Зарегистр. 08-03-2007 | Отправлено: 16:58 19-10-2008
Открыть новую тему     Написать ответ в эту тему

На первую страницук этому сообщениюк последнему сообщению

Компьютерный форум Ru.Board » Компьютеры » Прикладное программирование » Задачи по C/С++


Реклама на форуме Ru.Board.

Powered by Ikonboard "v2.1.7b" © 2000 Ikonboard.com
Modified by Ru.B0ard
© Ru.B0ard 2000-2024

BitCoin: 1NGG1chHtUvrtEqjeerQCKDMUi6S6CG4iC

Рейтинг.ru