Lec 1
Lec 1
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.
LOAD BASEPAY
ADD OVERPAY
STORE GROSSPAY
9
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.cp Compiler converts
p Sample.cpp is your C++ code human readable
#include<iostream.h language to a
typed into a text file using a
> language which is
text editor.. It is a human
void main() understandable by the
readable operating
{ system/hardware
cout<<“hello”;
Examples of C/C++
} compilers of today:
C++ Converts
sample.cpp into
Visual C++
GCC/G++
Compiler sample.exe DJGPP (open source
for windows like GCC)
Borland C
Turbo
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.