Студопедия
Случайная страница | ТОМ-1 | ТОМ-2 | ТОМ-3
АрхитектураБиологияГеографияДругоеИностранные языки
ИнформатикаИсторияКультураЛитератураМатематика
МедицинаМеханикаОбразованиеОхрана трудаПедагогика
ПолитикаПравоПрограммированиеПсихологияРелигия
СоциологияСпортСтроительствоФизикаФилософия
ФинансыХимияЭкологияЭкономикаЭлектроника

Fundamentals of programming I

Programs and algorithms | Data in a program (variables and literals) | Operations on data (operators and expressions) | Fundamentals of programming II | Write down and run this program on your computer | Write down and run this program on your computer | Introduction to objects | The first program | Types. Primitive types. | Types of variables. Declarations. |


Читайте также:
  1. Algorithms and programming languages
  2. Application Fundamentals
  3. Classes of programming languages
  4. Classification of data types in the programming language Java.
  5. Computer programming
  6. Computing Programming
  7. Creation and using one-dimensional and multi-dimensional arrays in the programming language Java.

The lecture introduces basic programming terms and demonstrates them using very simple programs and simple programming language. Special attention is drawn to the meaning of features common to all programming languages. Thanks to the language chosen for presentation, which hides sophisticated technical details from a programmer, students are able to produce their own working programs soon.

The language

In the previous lecture we learnt the notion of an algorithm and found out, that solving a problem with a computer requires an algorithm. Writing a program, we encode an abstract algorithm into some programming language.

We are going to use the Java language to learn programming. Lecture 4 introduces reader to this enormous and fascinating environment. The lectures following that discover its secrets step by step.

Before it takes place, its worth looking at fundamental programming principles using much simpler and more intuitive environment.
We start with the REXX language, or rather its simplified (for the sake of this lecture) version.

Note that for now we don't deal with object oriented programming concepts. These ideas appear gradually starting with the next lecture, their full treatment being put off till next semester.
Object oriented model of programming came into being as a way to eliminate some drawbacks specific to structural programming concept and based on it programming languages (for example Algol, Fortran, PL/I, C or REXX).
Thus, the meaning and the essence of object oriented programming are better understood by those who have some knowledge of non-object languages. For this reason it is worth reading this lecture. Besides, all language elements presented here have their counterparts in Java language.
But if all of these elements are present in Java, why should one start with another language?

There are four characteristic features of the REXX language:

which allow using it as a kind of pseudocode for encoding of algorithms.

This lecture is not about REXX (in fact only fundamental fragments of it are presented here, and some of them are modified for this lecture's needs); however it is worth discovering this language because of its simplicity and usability.


Interesting links related to REXX, NetRexx and ObjectRexx.

2.2. Quick start: first program and basics of syntax

To execute programs written in REXX its interpreter is required. It has to be installed on the system together with specially prepared preprocessor enabling some - indispensable for this lecture - syntax changes, which make future transition to Java easier.
Programs prepared in a text editor are saved on the hard disk as text files (pure text, not formatted as some application's document - for example Word). File name's extension should be either "rexx" or "rex".

Our first program implements the following algorithm:
1. Ask for a name displaying appropriate message at the command prompt.
2. Read the name typed in at the command prompt.
3. If the typed string is not empty, display greeting with the read name appended at the prompt.
In other case display greeting without name.
4. Display current time.

Here is the source code of this algorithm:

/* The first program: greeting */ say "What is your name?"; /* display text at the prompt */ name = linein(); /* read data */ /* if name hasn't been typed in, display string "Hello" in other case display "Hello", name and exclamation mark "!".*/ if name = "" then say "Hello!"; else say "Hello," name "!"; /* display current time */ say "It is" time();

Дата добавления: 2015-11-16; просмотров: 62 | Нарушение авторских прав


<== предыдущая страница | следующая страница ==>
Algorithms and programming languages| Student is obliged to write down and run this program by himself

mybiblioteka.su - 2015-2024 год. (0.007 сек.)