Programming Taskbook


E-mail:

Password:

User registration   Restore password

Russian

SFedU SMBU

1100 training tasks on programming

©  M. E. Abramyan (Southern Federal University, Shenzhen MSU-BIT University), 1998–2024

 

Tasks | Input-output operations

PrevNext


Input-output operations

If a task is solving with using Programming Taskbook then special input-output methods (procedures or functions) should be called in the student's program.

Brief information about input-output methods connected with the specific programming language is available from the Programming Taskbook window by pressing F1 key or «?» button on the window title (the Programming Taskbook window can be shown by using PT4Demo tool or running a program template created by PT4Load tool).

Brief description of input-output methods of programming languages that are supported by Programming Taskbook is shown below. See the Examples section for additional information.

Pascal language

Data input:
   procedure GetB(var A: boolean);
   procedure GetN(var A: integer);
   procedure GetR(var A: real);
   procedure GetC(var A: char);
   procedure GetS(var A: string);
   procedure GetP(var A: PNode);
Data output:
   procedure PutB(A: boolean);
   procedure PutN(A: integer);
   procedure PutR(A: real);
   procedure PutC(A: char);
   procedure PutS(A: string);
   procedure PutP(A: PNode);

Starting with the version 4.13, you may also use the overridden Get and Put procedures for input and output respectively (for example, Get(A) or Put(A)). Also input functions without parameters are available: GetBoolean (or GetBool), GetInteger (or GetInt), GetReal (or GetDouble), GetChar, GetString, GetPNode. Each function returns the next element of input data.

See additional information about PNode type in the description of the Dynamic and Tree groups of tasks.

C and C++ languages

Starting with version 4.23, in which support for the C language was added, the following functions are provided for data input and output:

Data input:
   void GetB(bool* a);
   void GetN(int* a);
   void GetD(double* a);
   void GetC(char* a);
   void GetS(char* a);
   void GetS(std::string& a); // C++ only
   void GetP(PNode* a);
Data output:
   void PutB(bool a);
   void PutN(int a);
   void PutD(double a);
   void PutC(char a);
   void PutS(char* a);
   void PutS(std::string a); // C++ only
   void PutP(PNode a);

A special input-output stream called pt may be used for input-output operations. For instance, function calls GetN(&a); GetD(&b); GetS(s); may be replaced by one stream-read statement as follows: pt >> a >> b >> s;

In version 4.22, functions that return the input data item were added for C++:

Data input (C++, starting with taskbook version 4.22):
   bool GetBool();
   int GetInt();
   double GetDouble();
   char GetChar();
   std::string GetString();
   PNode GetNode();

See additional information about PNode type in the description of the Dynamic and Tree groups of tasks.

Before version 4.23, C++ input functions used references instead of pointers as parameters:

Data input (C++, before taskbook version 4.23):
   void GetB(bool& a);
   void GetN(int& a);
   void GetD(double& a);
   void GetC(char& a);
   void GetS(char* a);
   void GetS(string& a);
   void GetP(PNode& a);

.NET languages (C#, VB.NET, F#)

Data input (C#):
   public static bool GetBool();
   public static int GetInt();
   public static double GetDouble();
   public static char GetChar();
   public static string GetString();
   public static Node GetNode();
Data input (VB.NET):
   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
Data input (F#):
   pt.GetBool() : bool
   pt.GetInt() : int
   pt.GetDouble() : double
   pt.GetChar() : char
   pt.GetString() : string
   pt.GetNode() : Node
Data output (C#):
   public static void Put(params object[] a);
Data output (VB.NET):
   Public Shared Sub Put(ParamArray a() As Object)
Data output (F#):
   pt.Put([<ParamArray>] args: obj[]) : unit

The I/O operations for the C# and VB.NET languages are implemented as static methods of a special class (PT for C#, PTVB for VB.NET) available to any program that solves a task. There is no need to specify the class name when calling these methods, since the solution to the task is executed in the form of the Solve method of the class, which is a descendant of the PT or PTVB class (and, therefore, inherits all I/O methods). For F#, use the methods of the pt class, explicitly specifying this class when calling methods.

The Put method contain any number of output parameters of any valid type (namely, any of the types for which an input method is provided).

In version 4.19, the Put method has been changed so that it can be used to output data of composite types. In version 4.20, the set of input methods was expanded for all languages of the .NET Framework by adding methods for quickly input the following data structures with elements of four basic types (int, double, string, and char):

  • arrays (GetArrInt, GetArrDouble, etc.),
  • sequences, that is, objects of the IEnumerable<T> type (GetSeqInt, GetSeqDouble, etc.),
  • lists (GetListInt, GetListDouble, etc.),
  • two-dimensional arrays (GetMatrInt, GetMatrDouble, etc.),
  • jagged arrays (GetArrArrInt, GetArrArrDouble, etc.),
  • lists of lists (GetListListInt, GetListListDouble, etc.).

There are also methods available for F# (and, starting with version 4.22, also available for C# and VB.NET) that provide tuple input (for example, GetInt2, GetInt3, GetInt4).

See additional information about Node type in the description of the "object" variant of the Dynamic and Tree groups.

Python language

Data input:
   get()
   get_bool()
   get_int()
   get_float()
   get_str()
   get_Node()
Data output:
   put(a, ...)

All input methods are functions that return the next item of input data. The get method may be used for input data of any admissible type (that is, any type that an input method is provided for). The get_str method may be used for both string and character data input.

The put method may be used for output several data items of the bool, int, float, str, Node types and also for tuples and lists output (in the case of tuple/list output all items of the tuple/list are output sequentially).

In version 4.19 of the taskbook, the set of input functions was expanded by adding functions for quickly input tuples (get2, get3, get4, get5), lists (get_list) and matrices (get_matr).

See additional information about Node type in the description of the "object" variant of the Dynamic and Tree groups.

Java language

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();
Data output:
   public static void put(Object... a);

Input-output operations for Java language are implemented as class methods of the PT class (the PT class is available for any student's program using Programming Taskbook).

The put method may be used for output several data items of any admissible type (that is, any type that an input method is provided for).

See additional information about Node type in the description of the "object" variant of the Dynamic and Tree groups.

Ruby language

Data input:
   get
   get_b
   get_i
   get_f
   get_s
   get_node
Data output:
   put(a, ...)
   a.put

All input methods are functions that return the next item of input data. The get method may be used for input data of any admissible type (that is, any type that an input method is provided for). The other functions allow to input data item of definite type: boolean data (true, false), integers (Fixnum and Integer), real numbers (Float), characters and strings (String), nodes of dynamic structures (Node).

In version 4.22, input functions get2, get3, get4, get5 were added, which return 2, 3, 4 and 5 next input data items.

The put method may be used for output several data items of any admissible type (boolean, integer, float, string, Node) and also for arrays output; in the case of array output, all items of the array are output sequentially.

You can also use the put method without parameters; this method should be applied to the data item of the TrueClass, FalseClass, Fixnum (Integer), 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.

See additional information about Node type in the description of the "object" variant of the Dynamic and Tree groups.

Julia language

Data input:
   get
   get_b
   get_i
   get_f
   get_c
   get_s
   get_node
Data output:
   put(a, ...)

All input functions return the next item of input data. The get method may be used for input data of any admissible type (that is, any type that an input method is provided for). The other functions allow to input data item of definite type: boolean (Bool), integers (Int), real numbers (Float64), characters (Char), strings (String), nodes of dynamic structures (Node).

Also input functions get2, get3, get4, get5 are available, which return 2, 3, 4 and 5 next input data items.

The put method may be used for output several data items of any admissible type (boolean, integer, float, char, string, Node) and also for arrays output (AbstractVector); in the case of array output, all items of the array are output sequentially.

See additional information about Node type in the description of the "object" variant of the Dynamic and Tree groups.


PrevNext

 

  Рейтинг@Mail.ru

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

Last revised:
01.01.2024