Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > IT форум > Помощь студентам
Регистрация

Восстановить пароль

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 03.06.2011, 18:30   #1
soundelly
 
Регистрация: 03.06.2011
Сообщений: 5
По умолчанию программа: арфиметические действия в СС

добрый день!
прошу знающих помочь с поиском или составлением программы.
программа должна выполнять действия сложения, вычитания, деления и умножения в различных системах счисления, в том числе и числа с плавающей запятой.
может быть, у кого-нибудь есть такая программка? или помогите советом... пожалуйста! очень на вас надеюсь...
с уважением.
soundelly вне форума Ответить с цитированием
Старый 03.06.2011, 18:34   #2
Mandrivnyk
Software Developer
Участник клуба
 
Аватар для Mandrivnyk
 
Регистрация: 01.03.2011
Сообщений: 1,098
По умолчанию

Язык какой?
Болтовня ничего не стоит. Покажите мне код. (c) Linus Torvalds
Помог ответ? -- Поставьте отзыв.
Выражения особой благодарности в рублевом эквиваленте отправлять сюда --> R269634919062
Mandrivnyk вне форума Ответить с цитированием
Старый 03.06.2011, 18:38   #3
soundelly
 
Регистрация: 03.06.2011
Сообщений: 5
По умолчанию

паскаль....
soundelly вне форума Ответить с цитированием
Старый 03.06.2011, 20:57   #4
soundelly
 
Регистрация: 03.06.2011
Сообщений: 5
По умолчанию

Mandrivnyk, а у вас в каком-то другом языке есть?..
soundelly вне форума Ответить с цитированием
Старый 03.06.2011, 22:38   #5
soundelly
 
Регистрация: 03.06.2011
Сообщений: 5
По умолчанию

ребят!!!! я нашла в сетях кое-как программу!!! но она выдает ошибку и я в ней ничего не могу понять(((

посмотрите пожалуйста! что там не так, почему не работает?..
п.с. сразу целиком не влезает - так что частями...

очень на вас надеюсь!!!

начало:


Код:
var
    notation: byte;
    decimal1: integer; binary1, octal1, hexa1: string;
    decimal2: integer; binary2, octal2, hexa2: string;
    decimal_res: longint; binary_res, octal_res, hexa_res: string;
    operation: char;

function decimal_binary(decimal:integer): string;
begin
    decimal_binary := '';
    if decimal = 0 then decimal_binary := '0';
    while decimal > 0 do begin
        decimal_binary := chr(ord('0') + (decimal mod 2)) + decimal_binary;
        decimal := decimal div 2
    end;
end;

function decimal_octal(decimal:integer): string;
begin
     decimal_octal := '';
    if decimal = 0 then decimal_octal := '0';
    while decimal > 0 do begin
        decimal_octal := chr(ord('0') + (decimal mod 8)) + decimal_octal;
        decimal := decimal div 8
    end;
end;

function decimal_hexa(decimal:integer):string;
var digit:byte; ch:char;
begin
     decimal_hexa := '';
    if decimal = 0 then decimal_hexa := '0';
    while decimal > 0 do begin
        digit := decimal mod 16;
        if digit in [10..15] then
            case digit of
            10: ch := 'A';
            11: ch := 'B';
            12: ch := 'C';
            13: ch := 'D';
            14: ch := 'E';
            15: ch := 'F'
            end
        else
            ch := chr(ord('0') + digit);
        decimal_hexa := ch + decimal_hexa;
        decimal := decimal div 16
    end;
end;

function binary_decimal(binary:string):integer;
var n,m,i,j,digit:byte; pow:integer;
begin
    n := length(binary);
    binary_decimal := 0;
    m := n;
    for i:=1 to n do begin
        digit := ord(binary[i]) - ord('0');
        m := m - 1;
        if digit = 1 then begin
            pow := 1;
            for j:=1 to m do
                pow := pow * 2;
            binary_decimal := binary_decimal + pow;
        end;
    end;
end;

function octal_decimal(octal:string):integer;
var n,m,i,j,digit:byte; pow:integer;
begin
     n := length(octal);
    octal_decimal := 0;
    m := n;
    for i:=1 to n do begin
        digit := ord(octal[i]) - ord('0');
        m := m - 1;
        pow := 1;
        for j:=1 to m do
            pow := pow * 8;
        octal_decimal := octal_decimal + digit * pow;
    end;
end;

function hexa_decimal(hexa:string):integer;
var n,m,i,j,digit:byte; pow:integer; ch: char;
begin
    hexadecimal := '';
    while decimal > 0 do begin
        digit := decimal mod 16;
        if digit in [10..15] then
            case digit of
            10: ch := 'A';
            11: ch := 'B';
            12: ch := 'C';
            13: ch := 'D';
            14: ch := 'E';
            15: ch := 'F'
            end
        else
            ch := chr(ord('0') + digit);
        hexadecimal := ch + hexadecimal;
        decimal := decimal div 16
    end;
end;
soundelly вне форума Ответить с цитированием
Старый 03.06.2011, 22:39   #6
soundelly
 
Регистрация: 03.06.2011
Сообщений: 5
По умолчанию

конец:

Код:
begin
    write('Decimal: ');
    readln(decimal);

    binary := binary_octal(2,decimal);
    octal := binary_octal(8,decimal);
    hexa := hexadecimal(decimal);
    writeln('notation:':10,'2':10,'8':5,'10':5,'16':5);
    writeln('value:':10,binary:10,octal:5,decimal:5,hexa:5);

readln
end;

procedure manager(var decimal:integer; var binary,octal,hexa:string; notation:byte);
begin
    if notation = 2 then begin
        readln(binary);
        decimal := binary_decimal(binary);
        octal := decimal_octal(decimal);
        hexa := decimal_hexa(decimal)
    end
    else
        if notation = 8 then begin
            readln(octal);
            decimal := octal_decimal(octal);
            binary := decimal_binary(decimal);
            hexa := decimal_hexa(decimal)
        end
        else
            if notation = 10 then begin
                readln(decimal);
                binary := decimal_binary(decimal);
                octal := decimal_octal(decimal);
                hexa := decimal_hexa(decimal)
            end
            else
                if notation = 16 then begin
                    readln(hexa);
                    decimal := hexa_decimal(hexa);
                    binary := decimal_binary(decimal);
                    octal := decimal_octal(decimal)
                end
                else
                    writeln('Must be goto end.');
end;

begin
    write('Notation: '); readln(notation);
    write('Number one: ');
    manager(decimal1,binary1,octal1,hexa1,notation);
    write('Number two: ');
    manager(decimal2,binary2,octal2,hexa2,notation);

    write('Operation (+,-,*,/): ');
    readln(operation);
    if operation = '+' then
        decimal_res := decimal1 + decimal2
    else
        if operation = '-' then
            decimal_res := decimal1 - decimal2
        else
            if operation = '*' then
                decimal_res := decimal1 * decimal2
            else
                if operation = '/' then
                    decimal_res := decimal1 div decimal2
                else
                    writeln('Error operation');
    binary_res := decimal_binary(decimal_res);
    octal_res := decimal_octal(decimal_res);
    hexa_res := decimal_hexa(decimal_res);

    writeln;
    writeln('notation:':10,'2':10,'8':5,'10':5,'16':5);
    writeln;
    writeln('value:':10,binary1:10,octal1:5,decimal1:5,hexa1:5);
    writeln('value:':10,binary2:10,octal2:5,decimal2:5,hexa2:5);
    writeln(' ':10,'-------------------------');
    writeln('result:':10,binary_res:10,octal_res:5,decimal_res:5,hexa_res:5);


readln
end.
soundelly вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Арифметически действия Dem6 БД в Delphi 10 09.11.2009 20:28
строки и действия DeDoK Общие вопросы Delphi 21 08.08.2009 02:55
Действия с массивами Domik92 Паскаль, Turbo Pascal, PascalABC.NET 2 09.12.2008 13:15
Завершение действия SunKnight Общие вопросы Delphi 3 12.02.2008 18:25