Calendar - for "REAL" programmers: Difference between revisions

m
m (BaCon and BBC BASIC moved to the BASIC section.)
imported>Arakov
Line 1,046:
30 </pre>
=={{header|Elena}}==
ELENA 56.0x :
<syntaxhighlight lang="elena">import system'text;
import system'routines;
Line 1,053:
import extensions'routines;
 
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"};
 
class CalendarMonthPrinter
{
Date theDate _date;
TextBuilder theLine _line;
int theMonth _month;
int theYear _year;
refReference<int> theRow_row;
constructor(year, month)
{
theMonth_month := month;
theYear_year := year;
theLine_line := new TextBuilder();
theRow_row := 0;
}
 
writeTitle()
{
theRow_row.Value := 0;
theDate_date := Date.new(theYear_year, theMonth_month, 1);
 
DayNames.forEach:(name)
{ theLineDayNames.printforEach:(" ",name) }
{ _line.print(" ",name) }
}
writeLine()
{
theLine_line.clear();
 
if (theDate_date.Month == theMonth_month)
{
var dw := theDate_date.DayOfWeek;
 
theLine_line.writeCopies(" ",theDate_date.DayOfWeek == 0 ? 6 : (theDate_date.DayOfWeek - 1));
 
do
{
theLine_line.writePaddingLeft(theDate_date.Day.toPrintable(), $32, 3);
 
theDate_date := theDate_date.addDays:1
}
until(theDate_date.Month != theMonth_month || theDate_date.DayOfWeek == 1)
};
 
int length := theLine_line.Length;
if (length < 21)
{ theLine_line.writeCopies(" ", 21 - length) };
 
theRow_row.append(1)
}
indexer() = new Indexer
{
bool Available = theRow_row < 7;
 
int Index
{
get() = theRow_row.Value;
set(int index)
{
if (index <= theRow_row)
{ self.writeTitle() };
while (index > theRow_row)
{ self.writeLine() }
}
}
 
appendIndex(int index)
{
this self.Index := theRow_row.Value + index
}
get int Length() { ^ 7 }
 
get getValue() = self;
set setValue(o) { NotSupportedException.raise() }
};
printTitleTo(output)
{
output.writePadding(MonthNames[theMonth_month - 1], $32, 21)
}
printTo(output)
{
output.write(theLine_line.Value)
}
}
 
class Calendar
{
int theYear_year;
int theRowLength_rowLength;
constructor new(int year)
{
theYear_year := year;
theRowLength_rowLength := 3
}
printTo(output)
{
output.writePadding("[SNOOPY]", $32, theRowLength_rowLength * 25);
output.writeLine();
output.writePadding(theYear_year.toPrintable(), $32, theRowLength_rowLength * 25);
output.writeLine().writeLine();
var rowCount := 12 / theRowLength_rowLength;
var months := Array.allocate(rowCount).populate:(i =>
Array.allocate(theRowLength_rowLength)
.populate:(j =>
new CalendarMonthPrinter(theYear_year, i * theRowLength_rowLength + j + 1)));
months.forEach:(row)
{
var r := row;
row.forEach:(month)
{
month.printTitleTo:output;
output.write:" "
};
output.writeLine();
ParallelEnumerator.new(row).forEach:(line)
{
DayNames line.forEach:(nameprinter)
{
lineprinter.forEachprintTo:(printer)output;
{
printer.printTo:output;
 
output.write:" "
};
 
output.writeLine()
}
}
}
}
 
public program()
{
var calender := Calendar.new(console.write:"ENTER THE YEAR:".readLine().toInt());
calender.printTo:console;
 
console.readChar()
}</syntaxhighlight>
{{out}}
Line 1,246:
27 28 29 30 31 24 25 26 27 28 29 30 29 30 31
</pre>
 
=={{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:
Anonymous user