C++ 1. Introduction To Programming
C++ 1. Introduction To Programming
PRG1002 - Programming I
Introduction to
Programming
● The computer is device that is used to execute all the instructions in a program.
● Let’s imagine you are giving directions to your friend on how to make his way to the nearby train
station.
○ In this situation, your friend is a computer, going to the nearest train station is the task, and the
directions are a sequence of instructions that tells him how to execute the task.
● The computers are dumb, they will only do what you tell them to do. This might make programming a
bit frustrating at first, but if you do everything right, you know exactly what the computer is going to
do.
How do we write a program?
● Computers have their own language like humans do.
● If we wanted to tell a computer what to do directly, we could give instructions in 1s and 0s.
● The programming language make it easier for us to understand and potentially common to a number
of computer architectures.
● The computer does not understand programming languages directly, they use compiler or interpreter
to convert our language into machine code (0s and 1s).
What happens to the computer program?
● Compilers convert the entire program via a compilation process to machine code before it is used.
○ If there are errors in the program, they are detected during the compilation time and reported
back to us, and no machine code is generated.
● Once successfully generated, the machine code is then executed as a separate step.
● Languages like C++ are compiled, but some languages like JavaScript are interpreted directly.
● Interpreters process the instructions line by line and run the program in the interpreter execution
environment. It runs until it encounters an error in the program.
History of programming language
● The assembly language in the 1940s was probably the first human-readable programming language.
● By 1950s computer engineers realised the assembly language consumes too much time and was
error-prone to build a large program.
● In 1957, the first widely used, high level programming language called FORTRAN was created and
used for science computations.
● Assembly language is a direct translation of the binary instructions the computer executes - each
assembly language instruction directly relates to one in machine code.
LUI R1, 1
LUI R2, 4
DADD R3, R1, R2
● This just did the calculation 1 + 4 = 5. The first two lines load the numbers “1” and “4” into computer’s
memory, and the third instruction tells the computer to add the values together and store the result.
Level of programming languages
● High-level programming language looks more like a natural languages.
● Python, Java and Lua are all examples of high level programming languages.
● The high-level languages are easier to write programs, but slower than the low-level languages.
● C/C++ are medium level languages, a lot of time we don’t think about machine code when writing a
program in C/C++ but we can if we want to.
Summary
● Program is a set instructions given to the computer.