Консультация № 181771
06.01.2011, 19:52
64.05 руб.
0 5 1
Здравствуйте, уважаемые эксперты! Прошу Вас ответить на следующий вопрос:
Дан файл x, содержащий различные даты. Каждая дата – это число, месяц и год. Найти:
а) год с наименьшим номером;
б) все весенние даты;
в) самую позднюю дату.


Спасибо!

Обсуждение

Неизвестный
06.01.2011, 21:00
общий
это ответ
Здравствуйте!
Код программы(для хранения дат используется текстовой файл input.txt, даты должны быть в формате дд.мм.гггг):
Код:
uses
CRT;

type
TDate = record
y, m, d: integer;
end;

const
vesna = [3..5];

function StrToDate(str: string): TDate;
var
t: TDate;
i: integer;
ts: string;

begin
Val(str[1] + str[2], t.d, i);
Val(str[4] + str[5], t.m, i);
val(str[7] + str[8] + str[9] + str[10], t.y, i);
StrToDate := t;
end;

var
year: integer;
f: text;
ts: string;
last, tmp_date: TDate;


begin
clrscr;
assign(f, 'input.txt');
reset(f);

year := maxint;
last.y := 0;
last.d := 0;
last.m := 0;

writeln('Весенние даты: ');
while not eof(f) do
begin
readln(f, ts);
tmp_date := StrToDate(ts);
if tmp_date.m in vesna then
write(ts, ' ');
if tmp_date.y < year then
year := tmp_date.y;
if (tmp_date.y >= last.y) and (tmp_date.m >= last.m) and (tmp_date.d > last.d) then
last := tmp_date;
end;

writeln;
writeLn('Год с наим. номером: ', year);
writeLn('Самая поздняя дата: ', last.d, '.', last.m, '.', last.y);
readln;

close(f);
end.

Пример работы:

Удачи!!!
5
Спасибо.
Неизвестный
07.01.2011, 15:57
общий
Здравствуйте на этой строчке:
function StrToDate(str: string): TDate; - Error 34: Invalid function result type.
не могу разобраться, проделал подобное на delphi всё работает, а что может быть тут?
Неизвестный
07.01.2011, 19:35
общий
Попробуйте так:
Код:
uses
CRT;

type
TDate = record
y, m, d: integer;
end;

const
vesna = [3..5];

procedure StrToDate(str: string; var t: TDate);
var
i: integer;

begin
Val(str[1] + str[2], t.d, i);
Val(str[4] + str[5], t.m, i);
val(str[7] + str[8] + str[9] + str[10], t.y, i);
end;


var
year: integer;
f: text;
ts: string;
last, tmp_date: TDate;


begin
clrscr;
assign(f, 'input.txt');
reset(f);

year := maxint;
last.y := 0;
last.d := 0;
last.m := 0;

writeln('Весенние даты: ');
while not eof(f) do
begin
readln(f, ts);
StrToDate(ts, tmp_date);
if tmp_date.m in vesna then
write(ts, ' ');
if tmp_date.y < year then
year := tmp_date.y;
if (tmp_date.y >= last.y) and (tmp_date.m >= last.m) and (tmp_date.d > last.d) then
last := tmp_date;
end;

writeln;
writeLn('Год с наим. номером: ', year);
writeLn('Самая поздняя дата: ', last.d, '.', last.m, '.', last.y);
readln;

close(f);
end.
Неизвестный
07.01.2011, 19:50
общий
Безупречно, Спасибо!
давно
Старший Модератор
31795
6196
07.01.2011, 23:25
общий
function (reserved word)
A function is a program part that computes and returns a value.
Syntax:
function ident : type;
OR
function ident (parameters) : type;

Remarks: The function heading specifies the identifier for the function, the formal parameters (if any), and the function result type.
Valid result types are ordinal, real, string, and pointer.

A function is activated by the evaluation of a function call in an expression.

ТР считает правильными только выделаные типы, т.е. перечислимые(целые), действительные, строка(вернее указатель на неё) и просто указатель. Типы, которые определил программист к ним не относятся. Если быть точными, только целое значение может передаватся как параметр в DX:AX, остальные передаются как указатель на переменную(сегмент:смещение).
Об авторе:
Мне безразлично, что Вы думаете о обо мне, но я рад за Вас - Вы начали думать.

Форма ответа