Pascal simple learning

Source: Internet
Author: User
Tags constant definition time in milliseconds
1. PascalProgramBasic Structure

First, explain the basic structure of the PASCAL program (note in advance that the comments in Pascal are included in ):
Program program name; {the name that identifies the program, which can be omitted. However, using a readable program name can clearly display the functions implemented by the program .}
Uses call unit {when the program uses a variable, function, or process in another unit, it needs to make a call declaration for the unit here, let the compiler know the sources of the "unfamiliar" variables, functions, or processes. Generally, the program must reference the CRT unit, because it is responsible for the input and output of the program through the monitor}
Const
{Constant definition}
VaR
{Variable definition}
Begin
{Program subject definition}
End;
You can use read (or readln) and write (or writeln) to interact with input and output. The difference between read and readln is that the latter will automatically wrap the output string, this also applies to write and writeln.

2. Compile a PASCAL program

The function we want to implement now is to display a string "Hello, world!" on the screen !". In fact, it only involves the definition and output of a string. In the integrated environment of Turbo Pascal, select new in the File menu to create a new program. In the new edit box, enter the following program:
Program Hello;
Uses CRT;
VaR
{Variable definition}
Mystring: string;
Begin
{Variable assignment}
Mystring: = 'Hello, world! ′;
{Call writeln to output on screen}
Writeln (mystring );
End;

3. Use Pascal to compile audio programs

In PASCAL, the sound syntax is sound (freqner), the parameter FE-QUENCY frequency, in Hz. The syntax of the delay process is: delay (duration). The parameter represents the delay time in milliseconds. Nosound is used to close the speaker.
We can use Pascal to compile a small program that simulates phone ringtones, which is very interesting and realistic. The procedure is as follows:

Program Sm (input, output );
Uses CRT;
Procedure M (F: integer; D: Real );
Begin
Sound (f );
Delay (trunc (200 * D ))
End;
VaR I: integer;
Begin
For I: = 1 to 15 do
Begin
M (random, 10 );
M (520,10 );
Nosound
End;
End.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.