PF Lecture 1&2
PF Lecture 1&2
Fundamentals
Lecture 01
Introduction
Course Policy
Program
Critical Skills
Analysis
Critical Thinking
Attention to Detail
Design Recipe
Computers are
STUPID
Think Reuse
Think User Interface
Comments liberally
Think Reuse
Software categories
System software
Communicates with computer hardware and controls
different aspects operations. Sub categories are:
System
Software
Device Drivers
Utilities
Software categories
Application software
A group of program design for end user.
e.g. Payroll Systems, MS Word, Accounting Systems.
Tools of Trade
Home work
Editors
It is a tool for writing the code of program.
Debugger
Corrects Logical errors during the execution of program.
Linker
Links the program with routines and functions located on other file.
Loader
Load the program in main memory and instruct the processor to execute
the program from first instruction.
Programming Fundamentals
Lecture 02
Basic Syntax
# include <iostream.h>
main()
{
cout << "Welcome to Indus University ";
}
Basic Syntax
# include <iostream.h>
# include is pre-processor directive. It is an instruction to compiler to
add file iostream.h
<iostream.h>
Name of the library definition file for all Input Output Streams.
main()
main is actually the one which is run when your program is used.
{}
Braces allows to group together pieces of a program.
cout
cout takes data from computer and sends it to the output.
<<
The sign << indicates the direction of data. Here it is towards cout and the
function ofcout is to show data on the screen.
<<
The sign << indicates the direction of data. Here it is
towards cout and the function ofcout is to show data on the
screen.
Welcome to Indus University
The thing between the double quotes ( ) is known as
character string. In C++ programming character strings
are written in double quotes.
;
All C statements end with semicolon (;). Missing of a
semicolon (;) at the end of statement is a syntax error and
compiler will report an error during compilation.
Variables
Variable
Picture of the memory
25
name
10323 of the
variable
Variable
Variable starts with
1. Character
2. Underscore _ (Not Recommended)
Variable
Variables
Name
Type
Size
Value
Scope of variable
Local Variable
Variables that are declared inside a function or block are local variables.
They can be used only by statements that are inside that function or block
of code. Local variables are not known to functions outside their own.
#include <iostream.h>
void main ()
{
// Local variable declaration:
int a, b; int c;
// actual initialization
a = 10; b = 20;
c = a + b;
cout << c;
}
Global variable
Global variables are defined outside of all the functions, usually on top of the
program. The global variables will hold their value throughout the life-time of your
program.
include <iostream.h>
// Global variable declaration:
int g;
void main ()
{
// Local variable declaration:
int a, b;
// actual initialization
a = 10;
b = 20;
g = a + b;
cout << g;
}
Assignment Operator
=
x=2
X
Assignment Operator
L.H.S = R.H.S.
X+ 3 = y + 4 Wrong
Z = x +4
x +4 = Z
Wrong
X = 10 ;
10
30
X = 30 ;
X = X + 1;
10
+ 1
= 11
Data types
Data type
int i ; ->
Declaration line
Data types
Type
Keyword
Boolean
bool
Character
char
Integer
int
Floating point
float
double
Valueless
void
Typical Range
char
1byte
unsigned char
1byte
0 to 255
signed char
1byte
-127 to 127
int
4bytes
-2147483648 to 2147483647
unsigned int
4bytes
0 to 4294967295
signed int
4bytes
-2147483648 to 2147483647
short int
2bytes
-32768 to 32767
Range
0 to 65,535
Range
-32768 to 32767
long int
4bytes
-2,147,483,647 to 2,147,483,647
4bytes
4bytes
0 to 4,294,967,295
float
4bytes
double
8bytes
long double
8bytes
#include <iostream.h>
main ( )
{
int x ;
int y ;
int z ;
x = 10 ;
y = 20 ;
z=x+y;
cout << " x = " ;
cout << x ;
cout << " y = " ;
cout << y ;
Operators
Arithmetic Operators
Relational Operators
Logical Operators
Bitwise Operators
Assignment Operators
Misc Operators
Arithmetic operators
Plus
Minus
Multiply
Divide
Modulus
+
*
/
%
Arithmetic operators
i+j
x*y
a/b
a%b
% = Remainder
5%2=1
2%2=0
4/2=2
5/2=?
Precedence
Highest:
()
Next:
*,/,%
Lowest:
+,