Programming Taskbook

Russian

E-mail:

Password:

User registration   Restore password

1000 training tasks on programming

©  M. E. Abramyan, 1998–2010

 

Examples | C++ | PT4 functions

PrevNext


Additional types and functions

Types and functions described below will be available in a program if pt4.cpp file is included (any template project created for task solving on C++ includes this file).


void Task(char* name);

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

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.


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(TNode*& a);

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 procedure is not called at the beginning of the program".

Each input function 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 GetN function will be called for input a string.

Note that string data item can be read to a variable of char* or string type.

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".


void PutB(bool a); void PutN(int a); void PutD(double a); void PutC(char a); void PutS(char* a); void PutS(string a); void PutP(TNode* a);

These functions must be used to output results on the screen and compare obtained results with control data (i.e., correct results). They must be called after the Task function, otherwise the program output the error message "The Task procedure is not called at the beginning of the program".

Unlike the Get-functions, parameters of the Put-functions can be expressions (in particular, constants of a corresponding type). The used function should correspond to output data item, otherwise the program output the error message "Invalid type is used for an output data item".

Note that the PutS function can receive parameters of two types: char* and string.

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".


Input-output stream pt

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


void DeleteNode(TNode* p);

This function provides freeing the memory allocated for a structure of TNode type (see the TNode description below). It must be used in the tasks of the "Dynamic" group.


struct TNode { int Data; TNode* Next; TNode* Prev; }; typedef TNode* PNode;

PNode and TNode types are used in the tasks of the "Dynamic" group. In the introductory tasks (Dynamic1–Dynamic2) and in the tasks devoted to stacks and queues (Dynamic3–Dynamic28) the Data and Next fields of the TNode structure are used. In the tasks devoted to lists (Dynamic29–Dynamic80) all fields (Data, Next, Prev) of TNode structure are used.

All initial and resulting pointers have PNode type in the tasks. They must be input and output by GetP and PutP functions respectively or by the pt stream. Students should not redefine the PNode and TNode types in their programs.


PrevNext

 

 

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

Last revised:
02.05.2010