CS1 Lesson 1 Tutorial
3 pages
English
Le téléchargement nécessite un accès à la bibliothèque YouScribe
Tout savoir sur nos offres
3 pages
English
Le téléchargement nécessite un accès à la bibliothèque YouScribe
Tout savoir sur nos offres

Description

Computer Programming 1 Lesson 1: Operators By Abhiram Chivukula Key Terms: Compiler/Compile-When you compile a program, the compiler tests to see if there are syntax errors or logical errors in the program. The program is not executed or built. Naming Conventions-The use of alphanumeric characters and the underscore character to name pieces of data. Names must start with an alphanumeric character. Depending on your compiler, you may be given the option to turn on case-sensitivity, in which case the names of data pieces will differ with capitalization. Foreword: This tutorial will be taught primarily in Pascal, but the concepts can be applied anywhere. The basic structure of a Pascal program is as follows: Program Write_the_name_of_your_program_here; Begin Code; End. Firstly, I would like to point a few things out. There is a rule called Naming Conventions, and it applies to the names that you give to your program data. Naming conventions says that you can have all and only alphanumeric characters and underscore in the names of your program, and the name must not start with a number. This is not just done for aesthetics, it is done so that the program will actually compile. Secondly, with a few exceptions, every line of code in Pascal will have a Semi-Colon at the end of the line. This is to let the compiler know that the end of the set of instructions on that line has come and its time to start a new set of instructions. As you ...

Informations

Publié par
Nombre de lectures 59
Langue English

Extrait

Computer Programming 1
Lesson 1: Operators
By Abhiram Chivukula
Key Terms:
Compiler/Compile-
When you compile a program, the compiler tests to see if there are
syntax errors or logical errors in the program. The program is not executed or built.
Naming Conventions-
The use of alphanumeric characters and the underscore character
to name pieces of data. Names must start with an alphanumeric character. Depending on
your compiler, you may be given the option to turn on case-sensitivity, in which case the
names of data pieces will differ with capitalization.
Foreword:
This tutorial will be taught primarily in Pascal, but the concepts can be applied anywhere.
The basic structure of a Pascal program is as follows:
Program
Write_the_name_of_your_program_here;
Begin
Code
;
End.
Firstly, I would like to point a few things out. There is a rule called Naming Conventions,
and it applies to the names that you give to your program data. Naming conventions says
that you can have all and only alphanumeric characters and underscore in the names of
your program, and the name must not start with a number. This is not just done for
aesthetics, it is done so that the program will actually
compile
.
Secondly, with a few exceptions, every line of code in Pascal will have a Semi-Colon at
the end of the line. This is to let the
compiler
know that the end of the set of instructions
on that line has come and its time to start a new set of instructions. As you can see, there
is no semi-colon after Begin, and there is a reason behind that. Theoretically, your
program is itself a set of instructions, thus signifying that there should be no semi-colon.
The practical reason there is no semi-colon after Begin is that it just won’t
compile.
Thirdly, I would like to point out that after the word End, there is a period. This is to
signify that it’s the end of the program.
We will be expanding on the basic structure as we get to later tutorials.
Operators
Pascal and almost all computer languages take advantage of operators. Operators are
basically symbols that cause an action between two pieces of data, and return the result.
Some examples of operators are as follows:
+
Addition operator-returns the sum of two or more pieces of data
-
Subtraction operator-returns the difference of two or more pieces of data
*
Multiplication operator-returns the product of two or more pieces of data
/
Division operator-returns the quotient of two or more pieces of data
(
or
)
groups two or more pieces of data for use in mathematical operations. Encloses
Boolean statements.
^
Pointer operator-See the lesson on pointers to learn the use of this operator
Examples:
1+2 returns 3
1+-2 returns -1 (note, some compilers do not like this type of notation and force you to
write 1+(-2)
1-2 returns -1
99-1 returns 98
1*2 returns 2
1*-77 returns -77 (note, some compilers do not like this type of notation and force you to
write 1*(-77)
1/2 returns .5
-1/2 returns -.5
Programming Skills:
Essential Commands:
Writeln()- writeln simply writes out text to the screen. If you put a mathematical
expression, it will write out the evaluated result. You can also add words together in
writeln. Writeln goes to the next line after writing the text.
Readln()- for now we will use this only to make the program wait for you to see the
output. In this scenario, it waits for the user to press enter, but is commonly used to read
in a line of data from the keyboard.
Write()- Write does the same thing as writeln except it does not go to the next line after
writing text. It will simply write at the next available space.
Read()-Read serves almost the same functionality as readln, except that read only reads in
one character of the input.
The following program will make use of the operators we have talked about so far. Copy
and paste it into your compiler and run the program.
Program Operators;
Begin
Writeln(‘Hello, this is my operator program’);
Writeln(1+2);
Writeln( (1-2)*3 );
Writeln(1*2);
Writeln(1/2);
Readln;
End.
Notice that when you run this program, everything prints out fine until ½. For .5, it writes
it in exponential notation. This can be fixed with a simple formatter. Replace writeln(1/2)
with writeln(1/2:0:X) where X is any integer you choose. It will return the answer
accurate to X decimal places.
  • Univers Univers
  • Ebooks Ebooks
  • Livres audio Livres audio
  • Presse Presse
  • Podcasts Podcasts
  • BD BD
  • Documents Documents