Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 19

COMPUTER PROGRAMMING

IN C++
LECTURE 01
CS- 123
Reference Book
• Object Oriented Programming in C++ by Robert Lafore
Programming languages
• A program is a set of instructions that help computer to perform tasks. This
set of instructions is also called as scripts. Programs are executed by
processor whereas scripts are interpreted. The languages that are used to
write a program or set of instructions are called "Programming languages".
Types of Programming Language
•.
Machine Level Language

• Machine language is lowest level of programming language. It handles binary


data i.e. 0’s and 1’s. It directly interacts with system. Machine language is
difficult for human beings to understand as it comprises combination of 0’s and
1’s.
Assembly Level Language

• Assembly language is a middle-level language. It consists of a set of


instructions in a specific format called commands. It uses symbols to
represent field of instructions. It is very close to machine level language. The
computer should have assembler to translate assembly level program to
machine level program. Examples include ADA, PASCAL, etc.
High-level Language

• High-level language uses format or language that is most familiar to users.


The instructions in this language are called codes or scripts. The computer
needs a compiler and interpreter to convert high-level language program to
machine level language. Examples include C++, Python, Java, etc. It is easy
to write a program using high level language and is less time-consuming.
Debugging is also easy and is a human-readable language.
Language translator
• The translator is a programming language processor that converts a high-level
or assembly language program to machine-understandable low-level machine
language without sacrificing the code's functionality.
Why Computer Language Translator?
• The computer only understands machine code. It is unable to understand any
low, assembly, or high-level language. There must be a program to convert the
source code into object code so that your computer can understand it. This is
the job of the language translator. The programmer creates source code and
then converts it to machine-readable format (object code)
Types
• There are 3 types of computer language translators: They are:
• Compiler
• Interpreter
• Assembler
compiler
• The compiler is a language translator program that converts code written in a
human-readable language, such as high-level language, to a low-level
computer language, such as assembly language, machine code, or object
code, and then produces an executable program.
interpreter
• The interpreter converts high-level language to machine-level language, while
the compiler accomplishes the same but in a different method. The
Interpreter's source code is transformed into machine code at run time. The
compiler, however, converts the code to machine code, i.e. an executable file,
before the program starts.
• The interpreter program executes directly line by line by running the source
code. So, it takes the source code, one line at a time, and translates it
and runs it by the processor, then moves to the next line, translates it and runs
it, and repeats until the program is finished.
Assembler
• Assembler converts code written in assembly language into machine-level
code. Assembly language contains machine opcode mnemonics so that
assemblers translate from mnemonics to direct instruction in 1:1 relation
Bug or Error
• A software bug is an error, flaw or fault in the design, development, or
operation of computer software that causes it to produce an incorrect or
unexpected result, or to behave in unintended ways.
Programming errors

• When developing programs there are three types of error that can occur:
• syntax errors
• logic errors
• runtime errors
Syntax errors

• A syntax error occurs when the code given does not follow the syntax rules of
the programming language. Examples include:
• misspelling a statement, eg writing pint instead of print
• using a variable before it has been declared
• missing brackets, eg opening a bracket, but not closing it
• A program cannot run if it has syntax errors. Any such errors must be fixed
first. A good integrated development environment (IDE) usually points out any
syntax errors to the programmer.
Logic errors
• A logic error is an error in the way a program works. The program can run but
does not do what it is expected to do.

• Logic errors can be caused by the programmer:


• incorrectly using logical operators, eg expecting a program to stop when the
value of a variable reaches 5, but using <5 instead of <=5
• incorrectly using Boolean operators
• unintentionally creating a situation where an infinite loop may occur
• incorrectly using brackets in calculations
• Unlike a syntax error, a logic error does not usually stop a program from
running. The program will run, but not function as expected.
Runtime errors
• A runtime error is an error that takes place during the running of a program.
• An example is writing a program that tries to access the sixth item in
an array that only contains five items. A runtime error is likely to crash the
program.
Debugging
• Debugging, in computer programming and engineering, is a multistep
process that involves identifying a problem, isolating the source of the
problem, and then either correcting the problem or determining a way to
work around it. The final step of debugging is to test the correction or
workaround and make sure it works.

You might also like