Additional methods of the taskbook
The methods presented in this section are implemented in the classes
included in the pt4net.dll assembly. When creating project templates
using the PT4Load module, this assembly is automatically connected to the created projects.
Although programs for different languages of the .NET Framework use different classes from the pt4net.dll assembly
(PT for C#, PTVB for VB.NET, pt for F#), their methods are mostly the same.
Therefore, for the sake of brevity, only variants of method descriptions for the C# language will be given below.
In programs that solve tasks in the C# and VB.NET languages,
all the methods described below can be used without specifying their class name.
In F# programs, when calling all methods, you should specify the pt class, for example, pt.GetInt() or pt.Put(a, b, c).
Task initialization, data input-output
// Task initialization:
static void Task(string name);
// Data input:
static bool GetBool();
static int GetInt();
static double GetDouble();
static char GetChar();
static string GetString();
static Node GetNode();
// Data output:
static void Put(params object[] a);
The Task method initializes a task named Name.
It must be called at the beginning of the task solution.
If the Task method call is absent, then the program output the error
message "The Task procedure 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.
Starting from the version 4.8, the Task method 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 method 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 method 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).
The Get methods must be used to input initial data values in the program.
They must be called after the Task method, otherwise the program output the error message
"The Task procedure with a task name is not called at the beginning of the program".
F# provides input functions that allow you to input a tuple of 2, 3, or 4 data items of the same type.
The names of these functions are followed by a corresponding number,
for example, pt.GetChar2(), pt.GetInt3(), pt.GetDouble4().
In addition, the synonym functions GetFloat, GetFloat2, GetFloat3, GetFloat4 are provided for input real numbers,
since the System.Double type can be described as both double and float in the F# language.
Since version 4.22, similar functions for input tuples of ValueTuple type (for example, GetChar2(), GetInt3(),
GetDouble4()) can be used for C# and VB.NET languages (except for SharpDevelop environment,
which uses C# 5.0 that does not support tuples of this type).
Each input method 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 GetInt method will be called for input a string.
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".
The Put method 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 method, otherwise the program output the error message
"The Task procedure with a task name is not called at the beginning of the program".
The Put method may be used for output data of any admissible type:
bool, int, double, char, string, Node for C# and corresponding types for VB.NET and F#.
Due to a parameter-array it is possible to use any number of parameters in the Put method.
If one of parameters is of invalid type then the program output the error message.
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".
The Node class
public sealed class Node: object, IDisposable
{
// Constructors:
public Node();
public Node(int aData);
public Node(int aData, Node aNext);
public Node(int aData, Node aNext, Node aPrev);
public Node(Node aLeft, Node aRight, int aData);
public Node(Node aLeft, Node aRight, int aData,
Node aParent);
// Properties:
public int Data { get; set; }
public Node Next { get; set; }
public Node Prev { get; set; }
public Node Left { get; set; }
public Node Right { get; set; }
public Node Parent { get; set; }
// Method that releases resources used by the Node object:
public void Dispose();
}
The Node class is used in the Dynamic and Tree group tasks.
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 this class implements IDisposable interface, so
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.
Additional tools for input and output of data structures (version 4.19)
static IEnumerable<int> GetSeqInt([int count]);
static IEnumerable<double> GetSeqDouble([int count]);
static IEnumerable<char> GetSeqChar([int count]);
static IEnumerable<string> GetSeqString([int count]);
static int[] GetArrInt([int count]);
static double[] GetArrDouble([int count]);
static char[] GetArrChar([int count]);
static string[] GetArrString([int count]);
static List<int> GetListInt([int count]);
static List<double> GetListDouble([int count]);
static List<char> GetListChar([int count]);
static List<string> GetListString([int count]);
static int[,] GetMatrInt([int m [, int n]]);
static double[,] GetMatrDouble([int m [, int n]]);
static char[,] GetMatrChar([int m [, int n]]);
static string[,] GetMatrString([int m [, int n]]);
static int[][] GetArrArrInt([int m [, int n]]);
static double[][] GetArrArrDouble([int m [, int n]]);
static char[][] GetArrArrChar([int m [, int n]]);
static string[][] GetArrArrString([int m [, int n]]);
static List<List<int>> GetListListInt([int m [, int n]]);
static List<List<double>> GetListListDouble([int m [, int n]]);
static List<List<char>> GetListListChar([int m [, int n]]);
static List<List<string>> GetListListString([int m [, int n]]);
In version 4.19, the set of input methods for C# and VB.NET has been extended with methods to make
it easier to input linear and two-dimensional data structures.
Each group of methods reads structures with elements of one of the four basic types of T:
int, double, char, and string. Five groups of methods are implemented, described below.
For F#, this set of methods is available since version 4.20, and there are synonymous methods
for input real structures; in the names of these methods, instead of the word Double, the word Float
is indicated: GetArrFloat, GetListFloat, etc.
Input methods for linear structures are represented by the GetSeq..., GetArr... and GetList... groups.
They can be called without parameters (in this case, they first read the size of the structure,
and then read all of its elements) or with one parameter (count) of the integer type,
which determines the size of the structure (in this case, only the elements themselves are read).
The GetSeq... group methods return a sequence IEnumerable<T>,
the GetArr... group methods return a one-dimensional array T[],
the GetList... group methods return a list List <T>.
Two-dimensional structure input methods are represented by the GetMatr..., GetArrArr... and GetListList... groups.
They can be called without parameters, and in this case, they first read two integers that
determine the size of the structure by the first index (the number of rows)
and the second index (the number of columns), and then read all the elements by rows.
When you specify one integer parameter m, it determines both the number of rows and the number
of columns (that is, the structure corresponds to a square matrix of order m);
the method only reads the elements of the structure. When specifying two integer parameters m and n,
the first of them determines the number of rows, the second determines the number of columns;
in this case, the method reads only the structure elements.
Methods of the GetMatr... group return a two-dimensional array T[,],
methods of the GetArrArr... group return an array of arrays T[][],
methods of the GetListList... group return a list of lists List<List<T>>.
The Put method has been changed so that not only the basic data types int, double, char, string, bool, and Node
can be specified as its parameters, but also any sequences (i.e., objects that implement the IEnumerable interface),
as well as tuples (objects of type Tuple and ValueTuple).
In the case of tuples, all their components are displayed sequentially; in the case of sequences,
all their elements are displayed.
Output debug info
The possibility to output debug information directly to the taskbook window
(in a special debug panel) appeared in version 4.9 of the Programming Taskbook.
The Show, ShowLine and HideTask methods were designed for this.
Debug output has been enhanced in version 4.19.
The Show and ShowLine methods can now contain an arbitrary number of parameters
(previously, only one parameter could be specified),
and you can set the width of the data output, as well as the number of fractional digits for real numbers.
In addition, it became possible to visualize composite data with the use of auxiliary formatting elements.
Since version 4.22, the debug panel can contain text data with any Unicode characters.
// Debug methods:
static void Show(params object[] args);
static void ShowLine(params object[] args);
static void ShowLine();
static void HideTask();
static void SetWidth(int w);
static void SetPrecision(int p);
The Show, ShowLine, and HideTask methods are intended to output some debug data into the
debug panel located below the task panels of the Programming Taskbook window.
The Show method shows a data item of any type in the debug panel.
The parameter of the method is automatically converted to its string representation.
The string parameter may contain explicit line-breaks as follows:
carriage return ('\r' in C# and F#, ChrW(13) in VB.NET),
new line ('\n' in C# and F#, ChrW(10) in VB.NET) or their combination
"\r\n" in C# and F#, ChrW(13) & ChrW(10) in VB.NET.
The ShowLine method additionally breaks the current screen line.
The HideTask method 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 HideTask procedure is ignored.
All subsequent calls of this procedure 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.
The SetWidth(w) method appeared in version 4.19 of the taskbook.
It allows you to set the minimum width w (w >= 0) of the output field for data items displayed
by the Show and ShowLine methods; by default, the minimum width is set to 0.
The specified setting applies to all subsequent calls to the Show and ShowLine methods.
Numeric data is right justified, other data is left justified.
The SetPrecision(d) method also appeared in version 4.19 of the taskbook.
It sets the number d of fractional characters when displaying real numbers (for d <= 0,
the floating point format is used; the number of fractional characters in this case is –d or 6 if d is 0);
the default is d = 2. A point is used as the decimal separator. The specified setting applies to all subsequent
calls to the Show and ShowLine methods.
In version 4.19, the implementation of the Show and ShowLine methods was changed
in such a way as to provide formatted output of data sets, including nested ones.
|