Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
38 views

Programming: Lesson 1. Course Overview. Introduction To Programming

The document provides an overview of programming lessons, which introduce algorithms and programming languages, and cover basic elements of the C programming language including data types, variables, functions, selection statements, loops, arrays, pointers, and file processing. It also outlines course projects involving algorithms, sorting, character and string processing, and team projects.

Uploaded by

Jonny Cernei
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

Programming: Lesson 1. Course Overview. Introduction To Programming

The document provides an overview of programming lessons, which introduce algorithms and programming languages, and cover basic elements of the C programming language including data types, variables, functions, selection statements, loops, arrays, pointers, and file processing. It also outlines course projects involving algorithms, sorting, character and string processing, and team projects.

Uploaded by

Jonny Cernei
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 55

Programming

Lesson 1. Course overview. Introduction to programming


1
Algorithms, programming, programming
languages. Algorithmizing problems. Methods of
description for algorithms. Algorithms with linear,
branched and cyclic structure.

Course 2
Basic elements of the C programming language.
overview Structure and syntax of C programs. Function
main(). Data types and variables.

3
Data input and output. scanf () and printf ()
functions. C++ input and output
4
C expressions and operators. Operands and
operators. C keywords and library math
functions. Simple and Composite (Structured)
expressions. Priority of operations.

Course 5
Selections. If and switch. Variations. Nested if.
overview Implementation.
Relational operations
Logical experssions and functions.
5
Loops. Counted controlled and condition-
controlled loops. Pre and post conditions. Nested
loops. Applications.

6
Course Arrays. Arrays declaration and initialization.
Assigning values to array’s elements. Displaying
overview
array content. Algorithms for one- and two-
dimensional arrays processing. Sorting arrays.
7
Pointers. Operations & and *. Operations with
pointers. Arrays and pointers. Operations with
pointers on arrays. Arrays of pointers. Pointer to
the array. Equivalent notations.
Course
8
overview User defined Functions. Function body, definition
and call. Values return, Function parameters. Data
exchange between functions. Local and global
variables. Time of existence and visibility. Memory
classes.
9
Methods of memory allocation in C. Standard
allocating, reallocating, and free dynamic
memory. Dynamic assignment of one-
dimensional and two-dimensional arrays

Course 10
Character processing. Read and display
overview characters. Standard character processing.
String processing. Array of chars and string in C.
Operations on strings and arrays of char. Input /
output data. Functions to process strings.
11
File Processing Pointer to file. Opening and
closing a file. Standard functions for file
processing

12
Recursion. Introduction. Recursive functions.
Course When to use recursion? Direct and indirect
overview recursion. Recursive problem solving.
13
User data Types. Structures. Access to structure
elements (fields). The typedef statement. Unions.
Bit maps. Enumerative types. Arrays of structures
processing.

Course 14
C-preprocessor directives. Macro Definition and
overview pseudo function. Conditional compilation.
Arguments of the main () function.
Seminars
1
Project 1. Hello World
1.1 Data input / output
1.2 User scanf and user printf
1.3 Formatted output
1.4 Draw in pseudographics
Course
overview 2
Project 2 Simple algorithms
2.1 Babylon algorithm for square root
2.2 Euclid's algorithm for GCD
2.3 Prime numbers
2.4 Perfect numbers (the sum of divisors)
3
Project 3. Long numbers operations (Arrays)
3.1 Big numbers sum
3.2 Big numbers difference
3.3 Big numbers multiplication
Course
overview 4
Project 4. Slow sorting algorithms
4.1 Bubblesort
4.2 Insertion sort
4.3 Selection sort
4.4 Time estimation and counting
5
Project 5 Combining arrays
5.1 3x3 0 – X game
5.2 infinite Ran Zee game
5.3 Snake
Course
overview 6
Project 6. Bit by bit
6.1 binary arithmetic + power 2 fast calculation
6.2 binary logics
6.3 Logical function evaluation
Project 7 Characters processing 1:
7.1 Development of string operation and conversion
functions
7.2 Proto Zuma game development

Course
overview Project 8 Characters processing 2
8.1 reading and editing text from file
8.2 formatting text files
Team projects
Project 1. Groups of 5. Random numbers generators
(October 10)

Course Project 2. Groups of 5. The magic of π


overview (November 10)

Project 3. Groups of 5. The ”Life” game


(December 10)
Books
Basic 6
Basic 5
Basic 6
More 2
What is Programming?
Lesson 1. Part 2.
Programming - The planning, scheduling of a task or an event.

- often attrib (1646): one that computes; specif: a


Computer
programmable electronic device that can store, retrieve, and
process data

Computer - The process of planning a sequence of instructions for a


Programming computer to follow.

Computer - A sequence of instructions outlining steps to be performed


Program by a computer.
Our definition of programming leaves a lot unsaid- In order to write
a sequence of instructions for a computer to follow, we must go
through a certain process.
This process is composed of a problem-solving phase and
an implementation phase .

Problem-Solving Phase
Analysis — Understand (define) the problem.
General Solution (Algorithm) — Develop a logical sequence of
steps to be used to solve the problem.
Test — Follow the exact steps as outlined to see if the solution
truly solves the problem.

Implementation Phase
Specific Solution (Program) — Translate the algorithm into a
programming language (code).
Test — Have the computer follow the instructions. Check the
results and make corrections until the answers are correct.
Use — Use the program.
The computer, alas, is not intelligent. It cannot
analyze a problem and come up with a solution. The
programmer must arrive at the solution and
communicate it to the computer.

Meditations...
The problem solving is done by the programmer —
not the computer.

So, you may ask, what's the advantage of using a


computer if it can't solve any problems?
The advantage is that once we have a solution for
a problem and have prepared a version of it for the
computer, the computer can rapidly repeat the
solution again and again and again.
Meditations...
Thus the computer may be used to free people from
tasks that are repetitive and boring or that require
great speed or consistency.
The programmer begins the programming process by
analyzing the problem and developing a general
solution called an algorithm .
Algorithms

Understanding, analysis of a problem and algorithm


developing are the heart of the programming
process.
- A step-by-step procedure for solving a
Algorithm
problem in a finite amount of time

Algorithms
1. Insert the key.
2. Make sure the transmission is in Park (or Neutral).
3. Depress the gas pedal.
4. Turn the key to the start position.
Start the car 5. If the engine starts within six seconds, release the
key to the ignition position.
6. If the engine doesn't start in six seconds, wait ten
seconds and/repeat steps 3 through 6 (but not more
than five times).
7. If the car doesn't start, call the garage.
1. Lift hand.
2. Move hand to right side of book.
Go to next 3. Grasp cover of top page.
page (reffers 4. Move hand from right to left until page is
to a book) positioned so that what is on the other side
can be read.
5. Let go of page.
- In computer systems, an algorithm is basically
an instance of logic written in software by
Computer
software developers, to be effective for the
Algorithm
intended "target" computer(s) to
produce output from given (perhaps null) input.

Algorithms
After developing a general solution, the programmer "walks through" the
algorithm by performing each step mentally or manually. If this testing of the
algorithm doesn't produce satisfactory answers, the programmer repeats
the problem-solving process, analyzing the problem again and coming up
with another algorithm. Often the second algorithm is just a variation of the
original one.

When the programmer is satisfied with the algorithm, it is translated into


Programming a programming language.
Languages We use a programming language, rather than English, because a
programming language restricts us to writing only instructions that the
computer can carry out.

Programming - A set of rules, symbols and special words, used to


language construct a program
Translating an algorithm into a programming language
is called coding the algorithm.
The resulting program is tested by running (executing)
it on the computer. If the program fails to produce the
Implementation desired results, the programmer must determine what
is wrong and modify the algorithm and program as
needed.
The combination of coding and testing an algorithm is
often referred to as implementing an algorithm.
Differences in
implementation
The Basic Instinct –

The Basic Mistake


Remember that in the digital computer all data, whether it is
alphabetic or numeric data or instructions, is stored and used
in binary codes of 1's and 0's. When computers were first
developed, the only programming language available was
the primitive instruction set of each machine, known
Programming as machine language (or machine code).
languages Even though most computers perform (he same kinds of
operations, different designers have chosen different sets of
binary codes of 1 's and 0's to stand for each instruction. So
Mashine the machine code for one computer is not the same as for
language another.

Machine - The language used directly by the computer


language and composed of binary-coded instructions.
When programmers used machine language for
programming, they had to enter the binary codes for the
various operations of the computer, a tedious and error
prone process. The resulting programs were difficult to read
Programming and modify, so assembly languages were developed to make
languages the programmer's job easier.

Assembly
language
- A low-level programming Language in which a
Assembly mnemonic is used to represent each of the
Language machine language instructions for a particular
computer.
An instruction in assembly language is in an easy-to-remember form called
a mnemonic (pronounced "ni-mon'ik"). Typical instructions for addition
and subtraction might look like this:

Assembly Language Machine Language


ADD 100101
SUB 010011

The only problem with assembly language was that intinctions written in it
could not be directly executed by a computer. So a program called the
assembler was written to translate the assembly language instructions
into machine language instructions (machine code).

- A program that translates an assembly language program


Assembler
into machine code.
Development of the assembler was a step in the right
direction, but a programmer was still forced to think in terms
of individual machine instructions.

Eventually high-level programming languages were


High level developed that were closer to natural languages such as
English and thus less limiting than machine code.
programming
languages Programs in these high-level languages (such as C, COBOL,
JAVA, Python etc. ) must be translated into machine language
instructions by a translator program called the compiler, or, in
some cases - interpreter .
- A program that translates a high-level language into machine
Compiler
code.
If we write a program in a high-level language, we can run it on any computer that has the appropriate
compiler. This is because most high-level languages are standardized, meaning that an official description of
the language exists.

A program in a high-level language is called a source program. When the source program is compiled by
running the compiler with the program as data, a machine language program called an object
program results. The object program can be run directly on the computer.

Notice that compilation/execution is a two-step process. During the compilation phase of the process, the
computer is running the compiler program.

To the compiler program, a source program is just input data. The compiler program outputs a machine
language translation of the source program. In the execution phase of the process, the machine language
version of the program (object code) replaces the compiler program in the computer's memory. The
computer then runs the object program, doing whatever the program instructs it to do.

Source Program - A program written in a high-level programming language.


- The machine language version of a program that results when a compiler translates a source
Object Program
program into binary codes for a particular computer.
1. Write your code
 Create it by typing on your computer's keyboard.
 Result: a text file such as HelloWorld.cpp.

Program 2. Compile your code


 Use the C / C++ compiler
development  Result: a C bytecode file such as HelloWorld.o
 Error? Go back to 1. to fix and recompile.
in C / C++ 3. RUN your program
 • Use the exe file.
 • Result: your program’s output.
 • Wrong answer? Go back to 1. to fix, recompile, and run.
Any creative process
involves cyclic
refinement / development.
My first C program
C IDEs and compilers

a) Dev C / C++ (local installation)


b) CodeBlocks (local installation)
c) Visual C (Microsoft) (local installation)
Tools d) OnlineGDB (web)
e) CSAcademy.com (web)
Etc.

IDE - Integrated Development Environment


Historical
background
before 1970

Switches to
input...

Output lights in
another room
mid 1970

Punched cards to
input...

Line printer to output


late 1970

first terminals (keyboards)


to input...

and output (monitor)


1980 to present...

program development with personal


computer

1980s to present day: Use multiple


virtual terminals to interact with
computer.
 Edit your program using any text
editor in a virtual terminal or IDE.
 Compile it in another virtual
terminal or in IDE.
 Run it by typing HelloWorld or Run
button
Personal
computers
2 x FDD of 720 KB each!

No HDD

DOS operating system

C compiler (and IDE)

EGA Graphics (480 x 320 )


These days
working place
of an ICT
professional
That’s all, folks!

You might also like