Difference between revisions of "Basic Pascal Tutorial/Chapter 1/Programming Assignment"

From Free Pascal wiki
Jump to navigationJump to search
m (bypass language bar/categorization template redirect [cf. discussion])
 
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Programming_Assignment}}
+
{{Basic Pascal Tutorial/Chapter 1/Programming Assignment}}
{{TYNavigator|Punctuation_and_Indentation|Solution}}
+
{{TYNavigator|Chapter 1/Punctuation and Indentation|Chapter 1/Solution}}
  
1H - Programming Assignment (author: Tao Yue, state: unchanged)
+
1H - Programming Assignment (author: Tao Yue, state: changed)
  
 
Now you know how to use variables and change their value. Ready for your first programming assignment?
 
Now you know how to use variables and change their value. Ready for your first programming assignment?
Line 9: Line 9:
  
 
So, to get you started, here's a snippet from the next few lessons. To display data, use:
 
So, to get you started, here's a snippet from the next few lessons. To display data, use:
<syntaxhighlight>
+
<syntaxhighlight lang=pascal>
 
writeln (argument_list);
 
writeln (argument_list);
 
</syntaxhighlight>
 
</syntaxhighlight>
 
The argument list is composed of either strings or variable names separated by commas. An example is:
 
The argument list is composed of either strings or variable names separated by commas. An example is:
<syntaxhighlight>
+
<syntaxhighlight lang=pascal>
 
writeln ('Sum = ', sum);
 
writeln ('Sum = ', sum);
 
</syntaxhighlight>
 
</syntaxhighlight>
Line 25: Line 25:
 
Then print it all out! The output should look something like this:
 
Then print it all out! The output should look something like this:
 
  Number of integers = 5
 
  Number of integers = 5
  Number1 = 45
+
  Number 1 = 45
  Number2 = 7
+
  Number 2 = 7
  Number3 = 68
+
  Number 3 = 68
  Number4 = 2
+
  Number 4 = 2
  Number5 = 34
+
  Number 5 = 34
 
  Sum = 156
 
  Sum = 156
 
  Average = 3.1200000000E+01
 
  Average = 3.1200000000E+01
Line 36: Line 36:
 
To see one possible solution of the assignment, go to the next page.
 
To see one possible solution of the assignment, go to the next page.
  
{{TYNavigator|Punctuation_and_Indentation|Solution}}
+
{{TYNavigator|Chapter 1/Punctuation and Indentation|Chapter 1/Solution}}

Latest revision as of 15:17, 20 August 2022

български (bg) Deutsch (de) English (en) français (fr) 日本語 (ja) 한국어 (ko) русский (ru) 中文(中国大陆)‎ (zh_CN)

 ◄   ▲   ► 

1H - Programming Assignment (author: Tao Yue, state: changed)

Now you know how to use variables and change their value. Ready for your first programming assignment?

But there's one small problem: you haven't yet learned how to display data to the screen! How are you going to know whether or not the program works if all that information is still stored in memory and not displayed on the screen?

So, to get you started, here's a snippet from the next few lessons. To display data, use:

writeln (argument_list);

The argument list is composed of either strings or variable names separated by commas. An example is:

writeln ('Sum = ', sum);

Here's the programming assignment for Chapter 1:

Find the sum and average of five integers. The sum should be an integer, and the average should be real. The five numbers are: 45, 7, 68, 2, and 34.

Use a constant to signify the number of integers handled by the program, i.e. define a constant as having the value 5.

Then print it all out! The output should look something like this:

Number of integers = 5
Number 1 = 45
Number 2 = 7
Number 3 = 68
Number 4 = 2
Number 5 = 34
Sum = 156
Average = 3.1200000000E+01

As you can see, the default output method for real numbers is scientific notation. Chapter 2 will explain you how to format it to fixed-point decimal.

To see one possible solution of the assignment, go to the next page.

 ◄   ▲   ►