Перейти к основному содержанию
EDU-MMCS
Вы используете гостевой доступ (Вход)

cs101 ОП / Basics of programming ENG

  1. В начало
  2. Курсы
  3. Осенний семестр
  4. Фундаментальная информатика и ИТ
  5. cs101 ENG
  6. 1 topic. Basic constructions and loops
  7. Lesson #1. Introduction to PascalABC.NET

Lesson #1. Introduction to PascalABC.NET

Требуемые условия завершения
Открыто с: четверг, 5 сентября 2019, 14:20


Be sure to read the requirements for labs.

[`task-01.pas` ] Examine the example, create a file with this program and run it.

// The program that outputs the greeting - this is a comment to the program
program Hello;
 begin
  Writeln('Hello world');
end.

Definition of variable

In Pascal abc.net variables may be defined within the body of the program between begin and end.  The principle of locality: the variable is defined immediately before its use.

In traditional pascal:

var n: integer;
begin
  n:=1; // assignment statement

pascalabs.net:

1 method:

begin
  var n:integer;
  n:=1;
2 method (canonical method when type is defined depending on the value):

begin
  var n:=1;
Arithmetic operations, assigning value to a variable and expressions

common method:

begin
  var a := 6; // Assigning value 6
  a:= a + 2; // Increase by 2
  a:= a - 2; // Reduction of 2
  a:= a * 3; // Multiplication by 3
  a:= a / 2; // division
end.

short method:

begin
  var a := 6; // Assigning value 6
  a+= 2; // Increase by 2
  a-= 2; // Reduction of 2
  a*= 3; // Multiplication by 3
  a/= 2; // division
end.

Data input

1.

begin
  var n:integer;
  read(n);

begin
  var n:real;
  read(n);

2.

var n:=ReadInteger();
var n:=ReadReal();
3.

(n1, n2) := (1, 2);
4.

var(n1, n2) := readInteger2;

Data output:

1 method:

begin
  var n:integer;
  read(n);
  n: = n * n;
  writeln('n = ',n);
2 method:
begin
  begin
  var n:integer;
  read(n);
  n: = n * n;
  print('n = ',n);

Tasks

Follow the rules:

  • Save your files with names as it is given in tasks (e.g. task-04.pas).
  • Give meaningfull names to your variables.
  • Use comments to make the program clear.
  • Give the task of the program in the form of a comment before the program code. For comments use curly brackets: 
1
  • Give the results of your program (log) as a comment after the program code. It’s easy to do just by copying. Use curly brackets to add comments :

    1

Example

Here is an example of right program which is clear for user:

1

The resulting example:

Input x 
3
Input y 
4
Input z 
5
The result = 1.77800712886037
  !  Make the next program using the same style of coding:

 [task-000.pas] Calculate the value of the function y = 4(x-3)^6 - 7(x-3)^3 + 2 , if x=5.

Note. Use the aúxiliary variable for (x-3)^3. Give the program log in the form of a comment.

[task-001.pas]  The side of the square (a) is entered. Find its perimeter: P = 4·a. Use different methods of assigning, input and output.

begin
  Writeln('the side length of a square:');
// Variable declaration to store the value of the side length
  var a := ReadReal;
// Perimeter calculation
  var P := 4 * a;
   Writeln('Perimeter P = ', P);
end.

[task-002.pas]  The diameter of a circle (d) is given. Find its length: L = π·d. The value of π is 3.14. Use different methods of assigning, input and output.

[task-003.pas] Two numbers a and b are given . Find their average: (a + b)/2. Use different methods of assigning, input and output.

  !   [task-004.pas] Calculate hypotenuse  and perimeter of a right-angled triangle, legs of triangle is given (root of (a2 + b2)) .

Here is an example of right program which is clear for user:

1

Possible result:

Input the values of triangle legs:
3
6
hypotenuse = 6.70820393249937
perimeter = 15.7082039324994

  !   Make the next program using the same style of coding. Pay attention to the names of the variables (they have meaning names, that shows the variables’ task in the program):

[task-006.pas] The length  aof a cube edge is given. Find the volume of the cube and its surface area. Give the program log in the form of a comment.

  !  There is another way of the variables definition (the task about hypotenuse):

1

[extra-task-03.pas] Modify previous program about the cube using this way of variable definition and clear (meaning) variables’ names.

  !  Make the next program twice: using different methods of variables definition. Write comments for user.

[extra-task-04.pas] Find the distance between two points on the plane; coordinates (x1,y1) and (x2,y2) are given. The distance is calculated by the formula:

1

Check: Check the correctness of your program with "simple" values that are easily to calculate. For example:

  1. d((0, 0); (6, 0)) = 6;
  2. d((0, -4); (0, 1)) = 5;
  3. d((-1, 1); (2, 5)) = 5.

Give the results of your program (log) in the form of a comment after the program code. It’s easy to do by simply copying. For comments use curly brackets:

1

[task-007.pas] The temperature in Celsius is given, convert temperature to Fahrenheit. Celsius and Fahrenheit scales are related by the ratio:

The input/output operators and assignment operator

Examine the examples at the link. Make the programm when it's needed.


Right triangle 
begin
  Writeln('Enter the lengths of the legs (two numbers separated by a space):');
// Variable declaration for storing the legs
  var a, b: real;
 // Input. This form is shorter than the ReadReal function, if there are several variables
  Read(a, b);
   var c := sqrt(a*a + b*b);
   Writeln('Hypotenuse c = ', c);
//Calculation of the perimeter of a triangle.
  var P := a + b + c;

Calculation the value of an expression.

  1. [task-02.pas] Cálculate the sine and cosine of the angle given in radians.

    Note. If necessary, use the help for mathematical functions: in menu Help / Помощь/Справка — «Справочник по языку» — «Системный модуль PABCSystem» — «Математические подпрограммы».

  2. {2 points} [task-03.pas] Cálculate the value of the lógarithm of 1024 to base 2, using the ln, function that calculates the natural logarithm of a given number, and the formula:

    \[\log_a b = \frac{\ln b}{\ln a}\]

  3. [task-04.pas] Cálculate the value of the expression:

    \[\frac{x + \sin x}{y - \sin z} + \ln{(x + \sin x)}\]

  4. [task-05.pas]Find the distance between two points with given coórdinates \((x_1, y_1)\) и \((x_2, y_2)\) on the plane. The distance is cálculated by the formula \(d=\sqrt{(x_1 - x_2)^2 + (y_1 - y_2)^2}\).

    Check. Check the correctness of your program on "simple" values that are easily counted manually. For example::
    • d((0, 0); (6, 0)) = 6;
    • d((0, -4); (0, 1)) = 5;
    • d((-1, 1); (2, 5)) = 5.

    Give the results (log) of your program in the output window PascalABC.NET in the form of a comment after the program code. It’s easy to do by simply copying.

  5. {2.5 points} [task-06.pas] Calculate the value of the function \(y = 4(x-3)^6 - 7(x-3)^3 + 2\) for several given x (that is, run the program several times for different values of x).

    Note. Use the aúxiliary variable for \((x-3)^3\). Give the program log in the form of a comment.

  6. [task-7.pas] The temperature in Celsius is given, convert temperature to Fahrenheit. Celsius and Fahrenheit scales are related by the ratio:

  7. \[t^{\circ}C = \frac{5}{9}(t^{\circ}F-32)\]

    Проверка. Check here WolframAlpha. Use the following query : convert 5 Celsius to Fahrenheit. Give the log of the programm.

  8. {Mark: 3} [task-8.pas] The radii of two concentric circles are given. Calculate the area of the ring enclosed between them.

Extra tasks

  1. [task-9.pas] The length of the cube edge a is given. Find the volume of the cube and its surface area. Give the program log in the form of a comment.

  2. [task-10.pas] The perimeter of the réctángle and the length of its diágonal are known. Find the sides of the rectangle. Give the program log in the form of a comment.

◄ Some Olympiad Tasks
Lesson #2. Integers, div and mod operators ►
Пропустить Навигация
Навигация
  • В начало

    • Страницы сайта

      • Мои курсы

      • Теги

    • Мои курсы

    • Курсы

      • Осенний семестр

        • Прикладная математика и информатика

        • Фундаментальная информатика и ИТ

          • Compiler Development

          • CMVSM

          • АЗПК

          • Frontend

          • ТеорЯП

          • Ruby Eng

          • EngCA&OS

          • CS201e

          • Компиляторы - лекции

          • CS202

          • CS211 C++ ENG

          • cs101 ENG

            • Общее

            • 1 topic. Basic constructions and loops

              • ЗаданиеLesson #1. Introduction to PascalABC.NET

              • ЗаданиеLesson #2. Integers, div and mod operators

              • ЗаданиеLesson #3. Boolean Expressions And Conditions

              • ЗаданиеLesson #4. Condition operator & branches. IF s...

              • ЗаданиеLesson #5. IF statement Part II. Max and Min

              • ЗаданиеHometask (until 6/10)

              • ЗаданиеFormatted output using WritelnFormat

              • ЗаданиеLesson #6. Chained IF statements and Case statemen...

              • ЗаданиеLesson #7. Loops

              • ЗаданиеLesson #8. For Loop

              • ЗаданиеLesson #9. Sum, Accumulators, Product and Counter....

              • ЗаданиеLesson #10. Minimum or Maximum value of N numbers

              • ЗаданиеLesson #11. While & Repeat Loops

              • ЗаданиеLesson #12. While & Repeat Loops: digits of a ...

              • ЗаданиеLesson #13. Procedures

              • ЗаданиеLesson #14. Functions

              • ЗаданиеTest Loops (control test)

            • Тема 2

            • Тема 3

            • Тема 4

            • Тема 5

            • Тема 6

            • Тема 7

            • Тема 8

            • Тема 9

            • Тема 10

        • Математика, механика

        • Педагогическое образование

        • Магистратура

          • Разработка мобильных приложений и компьютерных игр

        • Аспирантура

        • Вечернее отделение

        • Другое

      • Весенний семестр

        • Прикладная математика и информатика

        • Фундаментальная информатика и ИТ

        • Математика, механика

        • Педагогическое образование

        • Магистратура

          • Разработка мобильных приложений и компьютерных игр

        • Аспирантура

        • Вечернее отделение

        • Другое

      • Воскресная компьютерная школа

        • Пользователь компьютера плюс

        • Пользователь прикладных программ

        • Программирование I ступень

        • Программирование II ступень

        • Программирование III ступень

        • Архив

      • Воскресная математическая школа

        • Открытое тестирование РНОМЦ и мехмата ЮФУ - 2025

        • Олимпиадная математическая школа

        • Повышение квалификации

        • Доступная математика

        • Лаборатория математического онлайн-образования мех...

        • Осенняя универсиада

        • Научно-практическая конференция

        • ВМШ

          • ВМШ - 24

        • Летняя олимпиадная математическая школа РНОМЦ и ме...

      • Государственная итоговая аттестация

      • Дополнительное образование

      • Олимпиады

      • Видеолекции

      • Разное

      • Архив курсов

      • Заочная школа мехмата ЮФУ

Служба поддержки сайта
Вы используете гостевой доступ (Вход)
cs101 ENG
Сводка хранения данных
Скачать мобильное приложение Яндекс.Метрика