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.
[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);
}
[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)
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.
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 is not called at the beginning of the program".
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 with the list
of all available groups. 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.7, 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#".
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.
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 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 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".
[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);
// Properties:
public int Data { get; set; }
public Node Next { get; set; }
public Node Prev { 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)
' Properties:
Public Property Data() As Integer
Public Property Next() As Node
Public Property Prev() 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" group tasks.
In the introductory tasks (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.
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.
|