Additional functions
Functions and the Node class described below will be available in a program
if, for Ruby, the PT.rb module is imported or, for Julia, the PT.jl file is included in the program.
Any template program contains the corresponding directive.
Task initialization, data input-output
task(name)
This function initializes a task named name (a string parameter).
It must be called at the beginning of the program.
If the source code does not contain the task function call then the program output the error
message "The task function with a task name is not called".
A task name must contain a name of a task group and an
order number (for example, "Begin3" ).
If the group name is invalid then the program output the error message "Invalid task group".
If the task number is invalid then the program output
the error message with information about the range of the available task numbers for this group.
The symbol "?" placed after the task name (for example, "Begin3?" )
means that the program will be run in the demo mode.
The task function may be also used for creating and displaying an html-page
containing a description of a task or a task group.
In this case the name of the required task or the task group ended by the "#" symbol must be used for the name parameter,
for example, "Begin3#" or "Begin#" .
Starting from the version 4.13, the Programming Taskbook provides a program testing
on several sets of input data during a single running of the program. You should place
the sumbol "!" after the task name (for example, "Begin3!" ) in order to switch off this new feature.
All subsequent calls of the task function are ignored with the following exception:
if several calls are used for creation of an html-page containing a description of various tasks
or task groups then all these calls will be taken into account.
Starting from the version 4.12, the name parameter may include the "_en" or "_ru" suffix that determines
the interface language (English or Russian respectively) for Programming Taskbook window and the task itself.
The "?", "#", and "!" symbols should be placed before the suffix, for example,
"Begin3#_en" .
If several calls of the task function are used (for creation of an html-page)
then only the suffix of the first call will be taken into account.
If the suffix is absent then the default language is applied (the default language may be changed by means
of a pop-up menu of the PT4Load tool).
get()
get_b()
get_i()
get_f()
get_s()
get_node()
[Julia]
get_c()
These functions must be used to input initial data values in the program.
They must be called after the task function, otherwise the program output the error message
"The task function with a task name is not called at the beginning of the program".
Each function call returns the next item of input data. The get function allows to input
data item of any type: boolean (TrueClass and FalseClass for Ruby, Bool for Julia),
integer (Integer (Fixnum) for Ruby, Int for Julia), float (Float for Ruby, Float64 for julia),
Char (for Julia), String, Node,
whereas the other functions allow to input
data item of definite type and must correspond to the type of data item,
otherwise the program output the following message: "Invalid type is used for an input data item".
For example, this message will be output if get_i function will be called for input a string.
Starting from version 4.22, functions get2, get3, get4, get5 are available
that return 2, 3, 4 or 5 consecutive elements of the input data (the elements can be of different types), for example:
[Ruby]
a, b, c = get3
[Julia]
a, b, c = get3()
In the case of input of more data than the task requires, the program output
the error message "An attempt to input superfluous data".
In the case of input of less data than the task requires, the program output
the error message "Some required data are not input".
put(a, ...)
[Ruby]
a.put
The put function must be used to output results on the screen
and compare obtained results with control data
(i.e., correct results). It must be called after the task function, otherwise the program output the error message
"The task function with a task name is not called at the beginning of the program".
The put function may be used for output one or more data items of any admissible type:
boolean, integer, float, char (for Julia), string, Node.
Also it may output arrays (Array for Ruby, AbstractVector for Julia) with items of above-mentioned types.
If one of parameters is of invalid type then the program raises an exception with the error
message "The put function has an argument of invalid type".
A parameter type must correspond to the type of output data item, otherwise the program output the error message
"Invalid type is used for an output data item".
In the case of output of more data than the task requires, the program output
the error message "An attempt to output superfluous data".
In the case of output of less data than the task requires, the program output
the error message "Some data are not output".
In Ruby, you can also use the put method without parameters; this method should be applied to the data item of the
TrueClass, FalseClass, Integer (Fixnum), Float, String, Node, and Array type.
For instance, you can output the integer value 1 by means one of the following expressions:
put 1 and 1.put .
The Node class
# Constructors:
Node.new()
Node.new(data)
Node.new(data, next)
Node.new(data, next, prev)
Node.new(left, right, data)
Node.new(left, right, data, parent)
# Properties (available to read and write):
data
next
prev
left
right
parent
# Method that releases resources used by the Node object:
dispose()
[Julia]
# Constructors:
node()\m\|');
node(data::Integer)
node(data::Integer, next::Node)
node(data::Integer, next::Node, prev::Node)
node(left::Node, right::Node, data::Integer)
node(left::Node, right::Node, data::Integer, parent::Node)
# Accessors to properties (the ! symbol means changing the property):
data(node::Node)
data!(node::Node, value::Integer)
next(node::Node)
next!(node::Node, value::Node)
prev(node::Node)
prev!(node::Node, value::Node)
left(node::Node)
left!(node::Node, value::Node)
right(node::Node)
right!(node::Node, value::Node)
parent(node::Node)
parent!(node::Node, value::Node)
# Function that releases resources used by the Node object:
dispose!(node::Node)
The Node class is used in the Dynamic and Tree task groups.
In the introductory tasks of the Dynamic group (Dynamic1Dynamic2) and in the tasks
devoted to stacks and queues (Dynamic3Dynamic28) the data
and next properties of the Node class are used. In the tasks
devoted to lists (Dynamic29Dynamic80)
all properties (data, next, prev) of Node class are used.
In the most tasks devoted to binary trees the data, left, and right properties of the Node class are used.
The parent property is used in the tasks devoted to doubly linked binary trees
(Tree48Tree56 and Tree70Tree71).
Note that the dispose method should be called for any Node object, except objects that are output data for this task.
If the dispose method is not called for required objects then the program output the
error message.
Output debug info
Functions described below are intended to output some debug data into the
debug panel located below the task panels of the Programming Taskbook window.
Since version 4.22, the debug panel can contain text data with any Unicode characters.
show(a, ...)
This function shows data items of any type in the debug panel.
The parameters of the method are automatically converted to their string representations.
String parameters may contain explicit line-breaks as follows:
"\r" (Ruby), '\r' (Julia) carriage return;
"\n" (Ruby), '\n' (Julia) new line; their combination
"\r\n" .
show_line(a, ...)
The show_line function additionally breaks the current screen line
after output debug information.
hide_task()
The hide_task function hides all sections of the Programming Taskbook window
with the exception of the debug section (and therefore increases the debug panel height).
If the debug panel contains no data then the call of the hide_task function is ignored.
All subsequent calls of this function are ignored too.
After displaying the Programming Taskbook window
you can hide/restore task sections of this window
by means of the space key or the command of the pop-up menu.
|