Calendar - for "REAL" programmers: Difference between revisions
Content added Content deleted
m (BaCon and BBC BASIC moved to the BASIC section.) |
imported>Arakov |
||
Line 1,046: | Line 1,046: | ||
30 </pre> |
30 </pre> |
||
=={{header|Elena}}== |
=={{header|Elena}}== |
||
ELENA |
ELENA 6.x : |
||
<syntaxhighlight lang="elena">import system'text; |
<syntaxhighlight lang="elena">import system'text; |
||
import system'routines; |
import system'routines; |
||
Line 1,053: | Line 1,053: | ||
import extensions'routines; |
import extensions'routines; |
||
const MonthNames = new string[]{"JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE","JULY","AUGUST","SEPTEMBER","OCTOBER", |
const MonthNames = new string[]{"JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE","JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER"}; |
||
"NOVEMBER","DECEMBER"}; |
|||
const DayNames = new string[]{"MO", "TU", "WE", "TH", "FR", "SA", "SU"}; |
const DayNames = new string[]{"MO", "TU", "WE", "TH", "FR", "SA", "SU"}; |
||
class CalendarMonthPrinter |
class CalendarMonthPrinter |
||
{ |
{ |
||
Date _date; |
|||
TextBuilder _line; |
|||
int _month; |
|||
int _year; |
|||
Reference<int> _row; |
|||
constructor(year, month) |
|||
{ |
|||
_month := month; |
|||
_year := year; |
|||
_line := new TextBuilder(); |
|||
_row := 0; |
|||
} |
|||
writeTitle() |
|||
{ |
|||
_row.Value := 0; |
|||
_date := Date.new(_year, _month, 1); |
|||
⚫ | |||
DayNames.forEach:(name) |
|||
{ _line.print(" ",name) } |
|||
} |
|||
writeLine() |
|||
{ |
|||
_line.clear(); |
|||
⚫ | |||
if (_date.Month == _month) |
|||
{ |
|||
var dw := _date.DayOfWeek; |
|||
_line.writeCopies(" ",_date.DayOfWeek == 0 ? 6 : (_date.DayOfWeek - 1)); |
|||
do |
|||
{ |
|||
_line.writePaddingLeft(_date.Day.toPrintable(), $32, 3); |
|||
_date := _date.addDays:1 |
|||
} |
|||
until(_date.Month != _month || _date.DayOfWeek == 1) |
|||
}; |
|||
int length := _line.Length; |
|||
if (length < 21) |
|||
{ _line.writeCopies(" ", 21 - length) }; |
|||
_row.append(1) |
|||
} |
|||
indexer() = new Indexer |
|||
{ |
|||
bool Available = _row < 7; |
|||
int Index |
|||
{ |
|||
get() = _row.Value; |
|||
set(int index) |
|||
{ |
|||
if (index <= _row) |
|||
{ self.writeTitle() }; |
|||
while (index > _row) |
|||
{ self.writeLine() } |
|||
} |
|||
} |
|||
appendIndex(int index) |
|||
{ |
|||
this self.Index := _row.Value + index |
|||
} |
|||
get int Length() { ^ 7 } |
|||
get Value() = self; |
|||
set Value(o) { NotSupportedException.raise() } |
|||
}; |
|||
printTitleTo(output) |
|||
{ |
|||
output.writePadding(MonthNames[_month - 1], $32, 21) |
|||
} |
|||
printTo(output) |
|||
{ |
|||
output.write(_line.Value) |
|||
} |
|||
} |
} |
||
class Calendar |
class Calendar |
||
{ |
{ |
||
int _year; |
|||
int _rowLength; |
|||
constructor new(int year) |
|||
{ |
|||
_year := year; |
|||
_rowLength := 3 |
|||
} |
|||
printTo(output) |
|||
{ |
|||
output.writePadding("[SNOOPY]", $32, _rowLength * 25); |
|||
output.writeLine(); |
|||
output.writePadding(_year.toPrintable(), $32, _rowLength * 25); |
|||
output.writeLine().writeLine(); |
|||
var rowCount := 12 / _rowLength; |
|||
var months := Array.allocate(rowCount).populate:(i => |
|||
Array.allocate( |
Array.allocate(_rowLength) |
||
.populate:(j => |
.populate:(j => |
||
new CalendarMonthPrinter( |
new CalendarMonthPrinter(_year, i * _rowLength + j + 1))); |
||
months.forEach:(row) |
|||
{ |
|||
var r := row; |
|||
row.forEach:(month) |
|||
{ |
|||
month.printTitleTo:output; |
|||
output.write:" " |
|||
}; |
|||
output.writeLine(); |
|||
ParallelEnumerator.new(row).forEach:(line) |
|||
⚫ | |||
⚫ | |||
{ |
{ |
||
printer.printTo:output; |
|||
{ |
|||
printer.printTo:output; |
|||
output.write:" " |
|||
}; |
|||
output.writeLine() |
|||
} |
|||
} |
|||
} |
|||
} |
} |
||
public program() |
public program() |
||
{ |
{ |
||
var calender := Calendar.new(console.write:"ENTER THE YEAR:".readLine().toInt()); |
|||
calender.printTo:console; |
|||
console.readChar() |
|||
}</syntaxhighlight> |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,246: | Line 1,246: | ||
27 28 29 30 31 24 25 26 27 28 29 30 29 30 31 |
27 28 29 30 31 24 25 26 27 28 29 30 29 30 31 |
||
</pre> |
</pre> |
||
=={{header|Fortran}}== |
=={{header|Fortran}}== |
||
Alas, the header "FORTRAN" is not recognised - REAL programmers were absent that day? Even upon the apperance of lower case, I have preferred to use shouting for programme source, and normal upper/lower case for commentary. Aside from petty details such as 1 and l being nowhere as distinct as 1 and L, this allows the two sorts of blather to be identifiably different without ratiocination as the hours drag past. Further, the names of variables can easily be distinguished from the same word in discussion, as in ... the text in TEXT will be printed as the subtitle to the text in TITLE ... Anyway, in the spirit of old, herewith the source without tedious commentary: |
Alas, the header "FORTRAN" is not recognised - REAL programmers were absent that day? Even upon the apperance of lower case, I have preferred to use shouting for programme source, and normal upper/lower case for commentary. Aside from petty details such as 1 and l being nowhere as distinct as 1 and L, this allows the two sorts of blather to be identifiably different without ratiocination as the hours drag past. Further, the names of variables can easily be distinguished from the same word in discussion, as in ... the text in TEXT will be printed as the subtitle to the text in TITLE ... Anyway, in the spirit of old, herewith the source without tedious commentary: |