Professional Documents
Culture Documents
Lec1 PDF
Lec1 PDF
Programming
Course Learning Outcomes
1. Use and understand fundamentals of programming such as
variables, data types and operators.-------------------------------------------
--PLO-2
2. Understand, debug & use conditional , selection and iterative
statements according to the specific problems------------------------------
----------------PLO-3
3. Familiarize students with the basics of functions, function calls, built
in functions ----------------PLO-3
4. Have the ability to write error free computer programs using a C++
complier------------------PLO-5
Marks Distribution
Computer Languages
▪ In order to communicate with the computer we use one of
several programming languages.
Languages
▪ Uses English‑like abbreviations to represent the
machine‑language instructions.
▪ Uses a translator program called an assembler to convert each
instruction from the assembly language instruction to the
corresponding machine language binary code e.g., perhaps:
▪ LOAD BASEPAY
▪ ADD OVERPAY
▪ STORE GROSSPAY
Third generation ‑ Compiler 9
Languages
▪ High‑level, machine independent, closer to English‑language , more
natural. Each high-level language statement translates to several low-
level language statements, e.g.:
GROSSPAY = BASEPAY + OVERPAY
▪ Use compilers to translate from the high‑level language into machine
language.
▪ A compiler is a translator program that transforms high-level program
code into a low-level machine-level executable program.
▪ Compilers translate the whole program first, then execute the object
program.
▪ High-level languages are more English-like, easier to code, more costly to
run, less flexible. e.g., FORTRAN, BASIC, COBOL, PL/1, ALGOL, APL,
Pascal, SIMSCRIPT, Smalltalk, C, C++, Java, Python.
High‑level Language Translators 10
compiler
source object
or
program program
interpreter
Compilers Interpreters
Program
▪ A program is a set of instructions in proper
sequence, that causes a computer to perform a
particular task.
▪ Modern programs are projects composed of many
of individual program modules that have to be
linked together in order to be run.
▪ Software == one or more programs
Writing C++ program
▪ A programmer uses a text editor to create or modify
files containing C++ code.
▪ Code is also known as source code.
▪ A file containing source code is called a source file.
▪ After a C++ source file has been created, the
programmer must invoke the C compiler before the
program can be executed (run).
Sample. Compiler converts
cpp Sample.cpp is your C++ code human readable
#include<iostream. language to a
typed into a text file using a
h> language which is
text editor.. It is a human
void main() understandable by
readable the operating system/
{ hardware
cout<<“hello”;
Examples of C/C++
} compilers of today:
C++ Converts sample.
cpp into sample.
Visual C++
GCC/G++
Compiler exe DJGPP (open source
for windows like GCC)
Borland C
Turbo
The compiler takes Sample.cpp
10110111000100100
as an input and converts into 011010010010011
machine readable executable. 100001111001010
Computer runs or executes this 100010011110001
executable 001000000001000
Sample.
exe
Stage 1: Preprocessing
▪ Combines the program object code with other object code to produce the
3 Stages of Compilation
executable file.
▪ The other object code can come from the Run-Time Library, other libraries, or
object files that you have created.
▪ Saves the executable code to a disk file
▪ If any linker errors are received, no executable file will be generated.
Editor
Program Development
Source File gm.cpp
Preprocessor
Modified Source Code in RAM
Compiler
Program Object Code File gm.obj
Linker
● void main ( )
● {
● statement(s)
●
● }
A Simple C++ Program
● #include <iostream.h> //This is a preprocessor directive
● void main ( ) //this tells the starting point of your program
● {
● cout << “Hello World” <<endl ; //print the text on monitor
● }
Comments
▪ A comment is descriptive text used to help the program reader understand its
content.
▪ Single line- Any code description in a single line is expressed using single line
comments. //
▪ Multi line- All comments must begin with the characters /* and end with the
characters */
▪ The program header comment always comes first.
Preprocessor Directives
▪ Lines that begin with a # are called preprocessor
directives
▪ Example: the #include <iostream.h> directive causes the
preprocessor to include a copy of the input/output
stream header file iostream.h at this point in the code.
▪ This header file includes information about the cout
function that is used in this program.
iostream.h
▪ When we write our programs, there are libraries of functions to
help us so that we do not have to write the same code over and
over.
▪ Some of the functions are very complex and long. Not having to
write them ourselves make it easier and faster to write programs.
▪ Using the functions will also make it easier to learn to program!
void main ( )
▪ Every program must have a function called
main. This is where program execution
begins.
▪ main() is placed in the source code file as the
first function for readability.
▪ The reserved word “void” indicates that main(
) function returns nothing.
▪ The parentheses following the reserved word
“main” indicate that it is a function.
cout << “Hello, World!” <<endl ;
▪ This line is a C++ statement.
▪ Notice that this line ends with a semicolon. All statements in
C++ end with a semicolon.