How to resolve the algorithm Old Russian measure of length step by step in the Delphi programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Old Russian measure of length step by step in the Delphi programming language
Table of Contents
Problem Statement
Write a program to perform a conversion of the old Russian measures of length to the metric system (and vice versa).
It is an example of a linear transformation of several variables.
The program should accept a single value in a selected unit of measurement, and convert and return it to the other units: vershoks, arshins, sazhens, versts, meters, centimeters and kilometers.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Old Russian measure of length step by step in the Delphi programming language
Source code in the delphi programming language
program Old_Russian_measure_of_length;
{$APPTYPE CONSOLE}
uses
System.SysUtils;
const
units: array[0..12] of string = ('tochka', 'liniya', 'dyuim', 'vershok',
'piad', 'fut', 'arshin', 'sazhen', 'versta', 'milia', 'centimeter', 'meter',
'kilometer');
convs: array[0..12] of double = (0.0254, 0.254, 2.54, 4.445, 17.78, 30.48,
71.12, 213.36, 10668, 74676, 1, 100, 10000);
function ReadInt(): integer;
var
data: string;
begin
Readln(data);
Result := StrToIntDef(data, -1);
end;
function ReadFloat(): Double;
var
data: string;
begin
Readln(data);
Result := StrToFloatDef(data, -1);
end;
var
yn, u: string;
i, unt: integer;
value: Double;
begin
repeat
for i := 0 to High(units) do
begin
u := units[i];
Writeln(format('%2d %s', [i + 1, u]));
end;
Writeln;
unt := 0;
repeat
Writeln('Please choose a unit 1 to 13 : ');
unt := ReadInt();
until (unt >= 1) and (unt <= 13);
dec(unt);
repeat
Writeln('Now enter a value in that unit : ');
value := ReadFloat();
until value >= 0;
Writeln(#10'The equivalent in the remaining units is:'#10);
for i := 0 to High(units) do
begin
u := units[i];
if i = unt then
Continue;
Writeln(format(' %10s : %g', [u, value * convs[unt] / convs[i]]));
end;
Writeln;
yn := '';
Writeln('Do another one y/n : ');
readln(yn);
until yn.toLower = 'n';
end.
You may also check:How to resolve the algorithm Sorting algorithms/Insertion sort step by step in the C# programming language
You may also check:How to resolve the algorithm Tic-tac-toe step by step in the МК-61/52 programming language
You may also check:How to resolve the algorithm Binary search step by step in the Ring programming language
You may also check:How to resolve the algorithm Terminal control/Cursor positioning step by step in the Ada programming language
You may also check:How to resolve the algorithm Anagrams step by step in the VBA programming language