Programming Taskbook


E-mail:

Password:

User registration   Restore password

Russian

SFedU

1100 training tasks on programming

©  M. E. Abramyan (Southern Federal University), 1998–2018

 

Examples | C# and VB.NET | PT4 classes

PrevNext


Additional classes, their methods and properties

Classes described in this section are defined in pt4net.dll library (the PT4 namespace). Any template project created for task solving on C# or VB.NET includes this library.

The PT class: common description


[C#]

public class PT: object
{
// Method initializing a task:
    public static void Task(string name);
// Methods providing initial data input:
    public static bool GetBool();
    public static int GetInt();
    public static double GetDouble();
    public static char GetChar();
    public static string GetString();
    public static Node GetNode();
// Method providing results output:
    public static void Put(params object[] a);
// Methods providing debug output:
    public static void Show(object a);
    public static void ShowLine(object a);
    public static void ShowLine();
    public static void HideTask();
}

[VB.NET]

Public Class PT
    Inherits Object
' Method initializing a task:
    Public Shared Sub Task(name As String)
' Methods providing initial data input:
    Public Shared Function GetBool() As Boolean
    Public Shared Function GetInt() As Integer
    Public Shared Function GetDouble() As Double
    Public Shared Function GetChar() As Char
    Public Shared Function GetString() As String
    Public Shared Function GetNode() As Node
' Method providing results output:
    Public Shared Sub Put(ParamArray a() As Object)
' Methods providing debug output:
    Public Shared Sub Show(a As Object);
    Public Shared Sub ShowLine(a As Object);
    Public Shared Sub ShowLine();
    Public Shared Sub HideTask();
End Class

The PT class provides tools for task initialization and data input-output. A solution of task should be developed in Solve procedure, which must contain calls of methods of the PT class.

Some features of methods of the PT class are described below.

Task initialization, data input-output

The Task method initializes a task named Name. It must be called at the beginning of the Solve procedure that contains task solution. If the Solve procedure does not contain the Task method call 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".

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#; Boolean, Integer, Long, Double, Char, String, Node for VB.NET. 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".

Output debug info

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#, ChrW(13) in VB.NET), new line ('\n' in C#, ChrW(10) in VB.NET) or their combination "\r\n" in C#, ChrW(13) & ChrW(10) in VB.NET.

Using the concatenation (+ in C#, & in VB.NET) you may output numeric data jointly with the preceding comment as follows:

[C#]

Show("a = " + a);

[VB.NET]

Show("a = " & a);

Here A is a numeric variable.

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 Node class: common description


[C#]

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();
}

[VB.NET]

Public NotInheritable Class Node
    Inherits Object
    Implements IDisposable
' Constructors:
    Public Sub New()
    Public Sub New(aData As Integer)
    Public Sub New(aData As Integer, aNext As Node)
    Public Sub New(aData As Integer, aNext As Node, _
        aPrev As Node)
    Public Sub New(aLeft As Node, aRight As Node, _
        aData As Integer)
    Public Sub New(aLeft As Node, aRight As Node, _
        aData As Integer, aParent As Node)
' Properties:
    Public Property Data() As Integer
    Public Property Next() As Node
    Public Property Prev() As Node
    Public Property Left() As Node
    Public Property Right() As Node
    Public Property Parent() As Node
' Method that releases resources used by the Node object:
    Public Sub Dispose() Implements IDisposable.Dispose
End Class

The Node class is used in the Dynamic and Tree group tasks. In the introductory tasks of the Dynamic group (Dynamic1–Dynamic2) and in the tasks devoted to stacks and queues (Dynamic3–Dynamic28) the Data and Next properties of the Node class are used. In the tasks devoted to lists (Dynamic29–Dynamic80) 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 (Tree48–Tree56 and Tree70–Tree71).

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.


PrevNext

 

  Рейтинг@Mail.ru

Designed by
M. E. Abramyan and V. N. Braguilevsky

Last revised:
06.05.2018