COMP102 Introduction To Programming Slides - 160380
COMP102 Introduction To Programming Slides - 160380
TO
PROGRAMMING
Lec 1.
Dr.Ifra AFZAL
CONTENTS:
◦What is program?
◦What is programming?
◦Why we need to learn programming?
◦What does a programmer do?
◦What is programming language?
◦What types of programming languages?
◦What is language translators?
◦What types of codes are?
03/09/2025
CONTENTS:
◦What is Syntax?
◦Types of error
◦What is C++?
◦Why C++?
◦Who uses C++?
◦What can we do?/By the end of course.
03/09/2025
Video Link
◦ https://www.youtube.com/watch?v=Wchru8alhaE&list=PPSV
03/09/2025
WHAT IS PROGRAM?
◦ A program is a set of instructions that tells a computer what to do. It serves as
a way to communicate with the computer to perform tasks, solve problems, or
create interactive applications.
03/09/2025
Personal Reasons:
Creativity: Build your own apps, games, or tools.
Career Advancement: Tech jobs are in high demand globally.
Broader Impact:
Innovation: Programming drives breakthroughs in AI, robotics, and medicine.
Efficiency: Automates manual processes, saving time and resources.
03/09/2025
WHAT DOES A PROGRAMMER DO?
03/09/2025
WHAT IS PROGRAMMING LANGUAGE?
◦ Programming languages are the
vocabulary and set of grammatical
rules for instructing a computer to
perform specific tasks. There are
many different types of
programming languages each having
a unique set of keywords (words that
it understands) and a special syntax
(grammar)for organising program
instructions.
03/09/2025
WHAT TYPES OF PROGRAMMING LANGUAGES?
◦ A low level language is machine dependent; that is, it is written to run on one
particular computer. A high level language is machine independent, which
means the high level language code can run on many different types of
computer.
03/09/2025
Programming
Language
Procedural Object
Machine Assembly Natural
Oriented Oriented
Language Language Language
Language Language
(1GL) (2GL) (5GL)
(3GL) (4GL)
03/09/2025
WHAT TYPES OF PROGRAMMING LANGUAGES?
◦Machine language
◦ The machine language writes programs using the machine code i.e.
binary Digits (0 and 1), which is directly understood by the computer.
◦ The main problems with using machine code directly are that it is very
easy to make a mistake, and very hard to find it once you realise the
mistake has been made.
◦ Doesn’t require any language translator.
◦ Program execution is faster as no conversion is required.
◦ Program development is difficult and time-consuming.
◦ Machine dependent (may not run on several other processor)
◦ Detail hardware architecture knowledge is required.
03/09/2025
WHAT TYPES OF PROGRAMMING LANGUAGES?
03/09/2025
WHAT TYPES OF PROGRAMMING LANGUAGES?
03/09/2025
High
Level
TASK NO.1
Language
Low Level
Language
03/09/2025
WHAT TYPES OF CODES ARE?
◦ Source code is a program code of either an assembly language or high-
level language that the programmers write in a program editor. Source
code cannot be understood by the computer until it has been translated
into machine code.
03/09/2025
WHAT IS LANGUAGE TRANSLATORS?
◦ Language translators/Language processors
◦ A software that converts programs (High Language) into machine language.
◦ Every computer language has its own translators.
◦ Compiler
◦ Interpreter
◦ Assembler
03/09/2025
WHAT IS LANGUAGE TRANSLATORS?
◦ A Compiler is a program that converts the entire source code(compiles it)
into machine language at one time before the computer can run the
program at a later time.
◦ While compiling the source code into machine code, it checks that the
syntax is properly written by the programmer for the programmer to debug
the program.
◦ C, C++ use the compiler as a language translator.
Source Code
Compile Machine/Object
r Code
03/09/2025
WHAT IS LANGUAGE TRANSLATORS?
◦ The interpreters are programs that translates the high level program
code one statement at a time, that is, it reads a code statement, converts
it to one or more machine language instructions, and then executes the
instruction before moving translating the next code statement in the
program. If there is any error in the statement, the programmer can correct
the error before the interpreter evaluates the next statement. Interpreters
are slower than Compilers because interpreters convert a statement at a
time and runs it before moving to the next line.
◦ Python, Ruby, and PHP use the interpreter as a language translator.
03/09/2025
interpreter
s
Source Code Machine Code
Next
Instruction
03/09/2025
03/09/2025
Interprete
TASK NO.2
ble Co
em mp
s i le
As r r
03/09/2025
WHAT IS SYNTAX?
03/09/2025
WHAT IS SYNTAX?
◦ Syntax refers to the spelling an grammar of a programming language.
◦ Each program defines its own syntactical rules that control which words the
computer understands, which combinations of words are meaningful, and
what punctuation is necessary.
◦ Text-based programming languages are based on sequences of characters.
◦ A set of rules that govern the structure of a programming language,
including the order and combination of symbols, punctuation, and words.
Syntax is important because it ensures that code is written in a consistent
and understandable manner, making it easier to read and execute.
03/09/2025
TYPES OF ERRORS IN PROGRAMMING
◦ Syntax errors
◦ Code doesn't follow the rules of the programming language.
◦ Runtime errors
◦ invalid input, division by zero, or logic errors.
◦ Logical errors
◦ caused by miscalculations in the logic code, such as using the wrong
formula or calling the wrong variables.
◦ Semantic errors
◦ These errors occur when the code doesn't correctly convey the intended
functionality or behaviour. They can be more subtle and complex to
detect than syntax or logic errors.
03/09/2025
TYPES OF ERRORS IN PROGRAMMING
◦ Semantic errors
◦ These errors occur when the code doesn't correctly convey the intended
functionality or behaviour. They can be more subtle and complex to
detect than syntax or logic errors.
◦ Arithmetic errors
◦ These errors involve a mathematical error, such as dividing by zero.
◦ Compilation errors
◦ These errors occur when the compiler doesn't know how to turn the code
into a lower-level language that the computer can understand.
03/09/2025
WHAT IS C++?
◦ C is a programming language developed in the 1 970's alongside the UNIX
operating system.
◦ C provides a comprehensive set of features for handling a wide variety of
applications, such as systems development and scientific computation.
◦ C++ is an "extension" of the C language, in that most C programs are also
C++ programs.
◦ C++, as opposed to C, supports "object-oriented programming."
03/09/2025
WHAT IS C++?
Human Work Model:
03/09/2025
WHY C++?
◦ Bad News:
◦ C++ is not easy to learn
◦ Good News:
◦ Lots of good-paying jobs for programmers
◦ Java uses C++ syntax, it is easy to learn Java if you know
◦ C++ is not the easiest language (Basic and Pascal are easier), it is not the
hardest either (Ada, Prolog and Assembly languages are really difficult!)
03/09/2025
WHO USES C++?
◦ Computer makers such as Sun, SGI, IBM, and HP
◦ Airport
◦ Computer chip manufacturers like Motorola & Intel
Software companies
◦ Banks
◦ Hong Kong Government
◦ Hospital Authority
◦ Telecommunications
◦ Universities
03/09/2025
WHAT CAN WE DO
BY THE END OF THE COURSE?
◦ Program the computer in applications such as the following:
◦ Program a simple calculator
◦ Program simple computer games
◦ Program a small inventory system for a small company
03/09/2025
Cont.…..
03/09/2025