PPS Notes Unit-I
PPS Notes Unit-I
COMPUTER SYSTEM:
A Computer is an electronic device which performs operations such as accepts the data, stores the data,
manipulates or process the data according to a pre-stored instructions and produces the desired result. All
these tasks are performed at high-speed and accuracy.
A Computer computes the data (input) supplied to it and generates information (output).
A Computer is an electronic device which takes the input, processes it, and gives the output according to the
user needs.
A computer is a system made of two major components: Hardware and software.
Hardware: Hardware of a computer system are the physical components which we can touch and feel.
Example: Keyboard and Mouse.
The hardware of a computer system can be classified as:
1. Input Devices (I/P)
2. Processing Devices (CPU)
3. Output Devices (O/P)
1. Input Devices: Input devices are used to enter the data into the computer system.
Example: Keyboard, Mouse, Scanner, Microphone, Camera…etc.
2. Output Devices: Output devices are used to take the information (output) from a computer system.
Example: Monitor (Display or Standard Output), Printer, Speakers…etc.
(If the output is shown on the monitor we call it as softcopy. If it is printed on a paper using the printer, we
call it as hardcopy)
3. Processing Unit (or) Central Processing Unit:
The CPU is responsible for executing instructions such as arithmetic calculations, comparison between
data, and movement of data inside the system.
The modern day computers can have one or more CPUs in it.
The CPU, internal to it will have three different parts: ALU, CU and MU.
o ALU (Arithmetic and Logic Unit): ALU will performs the Arithmetic and Logical Operations
such as +,-,*,/ (Arithmetic Operations) &&, || ( Logical Operations) inside a computer system.
o CU (Control Unit): Every Operation such as storing, computing and retrieving the data should
be governed by the control unit.
o MU (Memory Unit): The Memory unit is used for storing the data. The Memory unit is
classified into two types. They are:
a) Primary Memory
b) Secondary Memory
MD AFZAL Mob: 8179700193
Asst. Professor [email protected]
a) Primary Memory (Main Memory): The primary memory also known as main memory is a
place where the programs and data are stored temporarily during processing. The data in primary
memory are erased when the computer is turned off. The following are the two memory types, which
are treated as primary memory.
ROM (Read Only Memory): It represents Read Only Memory that stores data and
instructions even when the computer is turned off. The contents in the ROM can‘t be
modified once if they are written. It is used to store the BIOS information which is helpful in
loading the operating system into the RAM from HDD.
RAM (Random Access Memory): It represents Random Access Memory that stores data
and instructions when the computer is turned on. The contents in the RAM can be modified
any number of times by instructions. It is used to store the programs under execution. The
content in the RAM are volatile, that is when the computer turned off the content of RAM
will be lost.
b) Secondary Memory (Auxiliary Memory): The following are the different kinds of secondary
memories. They can also be called as auxiliary memory. The content of these devices will remain
permanent even when the computer is turned off. The programs and data remain in the secondary
storage, ready for the next time use.
Magnetic Storage: The Magnetic Storage devices store information that can be read, erased
and rewritten a number of times. Example: Floppy Disks, Hard Disks, Magnetic Tapes.
Optical Storage: The optical storage devices that use laser beams to read and write stored
data. Example: CD (Compact Disk), DVD (Digital Versatile Disk).
There are other forms of memory devices like: Cache Memory and CPU Registers.
Cache Memory: These are superfast memory locations and are directly accessible by the CPU. The
content are volatile again. They are maintained in very small amounts as they are very costly.
CPU Registers: There are internal memory location of the CPU. The data inside the CPU is stored
in these registers for processing.
Application Software:
The following figure shows the relationship between the system software and application software.
In this figure, each circle represents an interface point.
The inner core is the computer hardware. The outer most layer represents the user.
The user uses application software to work with the system. This application software interacts with
operating system, which is a part of system software layer.
The system software have the direct interaction with the hardware.
The opening at the bottom of the figure is the path followed by the user to interact directly with
operating system when necessary.
COMPUTER LANGUAGES
To write a program for a computer the computer language is used.
The computer languages have changed over the years from machine language to natural language.
The following summary shows, how computer languages have evolved from machine language to
natural language.
1940‘s -- Machine Languages
1950‘s -- Symbolic Languages
1960‘s -- High Level Languages
Machine Languages:
In the early days of computers, the only available programming language was machine language.
The problem with machine language is that, each computer will have its own machine language, which
made up of only 0’s and 1’s.
The following program will give an idea of how instructions can be written in machine language.
All instructions in machine language must be streams of 0’s and 1’s, because internal circuits of the
computer system are made of switches, transistors and other electronic devices.
These devices can be in any one of the two possible states: on or off.
The off state is represented by 0; the on state is represented by 1.
MD AFZAL Mob: 8179700193
Asst. Professor [email protected]
Symbolic Languages
In 1950s, Admiral Grace Hopper, a mathematician developed the concept of a special program that
convert programs into machine language.
During these days, programming languages simply mirrored machine languages using symbols, or
mnemonics, to represent the machine language instructions.
As these languages used special symbols, they were known as symbolic languages.
The computer does not understand any other languages except its own machine language. Hence there is
a need to translate symbolic languages into machine language.
A special program called an assembler is used, which translates symbolic languages into machine
languages.
As symbolic languages are assembled using an assembler into machine languages, they also called as
assembly languages.
High-Level Languages
Symbolic languages required the programmers to concentrate on the hardware of the computer that they
were using, as these languages are still dependent on the machine.
Writing program in symbolic languages is very difficult because each instruction has to be coded separately.
Because of these issues programmers thought that there is a requirement of sophisticated and efficient
programming technique.
This led to the development of high-level programming languages.
MD AFZAL Mob: 8179700193
Asst. Professor [email protected]
High-Level languages are machine independent (portable). They allow the programmers to concentrate
more on application rather than the computer hardware.
The programmers also free from remembering the symbols and mnemonics specific to the computer system.
However like symbolic languages, these languages also be converted to machine language before giving it
to the computer.
The process of converting high-level languages into machine languages is known as compilation.
The most widely used high-level language was FORTRAN created by John Backus and IBM team in 1957,
it is still in use in scientific and engineering applications.
COBOL was also another high-level language used, developed by Admiral Grace Hopper.
C is also a high-level language used for the development of System software and other application
programs. It was developed by Dennis Ritchie in 1972.
4. Executing programs:
Once the program has been linked it is ready for execution.
To execute a program the program has to be loaded into primary memory. The operating system
command ‘run’ can be used to achieve this job.
Getting the program into the main memory is the function of an operating system program known as
loader. It locates the executable program in secondary memory and loads it to main memory.
After loading everything into the memory, the program takes the control and starts the execution.
In today’s integrated development environments (IDEs) these steps are combined under simple
mouse clicks or pull-down menu bars or simple shortcut key combinations.
In typical program execution, the program takes input either from the user or from a file. After
processing the data, it prepares the output either to the user’s monitor or to a file.
Once the execution process finishes the operating system removes the program from main memory.
COMPUTING ENVIRONMENTS
In the early days of computing the only environment available was the mainframe computing environment,
where the mainframe computer is used to satisfy all operations given to it. No sharing of resources from
other computers.
Later with the advancement of minicomputers and personal computers, many computing environment came
into existence. These computing environments are:
1. Personal Computing Environment
2. Time-Sharing Environment
3. Client-Server Environment
4. Distributed Computing Environment
Personal Computing Environment:
In 1971, Marcian E. Hoff of Intel has combined all basic elements of the central processing unit onto a
single chip known as microprocessor.
This was the first computer on a single chip named Intel 4004. It was the grandfather to many of today’s
modern computing processors.
In personal computing environments, a personal computer (PC) will be used where all of the computer
hardware components are connected together inside a single computer.
This environment will have the whole computer of its own. The user can perform whichever operation he
want.
Atypical personal computer is shown in the following.
ALGORITHM:
An algorithm is a step by step process to solve any given computational problem.
That is an Algorithm refers to a set of rules/instructions that step-by-step define how a work is to be done to
get the expected results.
The Algorithm is language-independent, i.e. the plain instructions in an algorithm can be written in any
language to get the expected output.
Characteristics / Specifications of Algorithms:
Not all written instructions can be considered as an algorithm. In order to consider the written statements as an
algorithm it must have the following characteristics.
Input: An algorithm has zero or more inputs, taken from a specified set of objects.
Output: An algorithm has one or more outputs, which have a specified relation to the inputs.
Definiteness: Each step must be precisely defined; each instruction is clear and unambiguous.
Finiteness: The algorithm must always terminate after a finite number of steps.
Effectiveness: An algorithm must be basic and simple. And it has to give the expected solution to the
problem in a finite number of steps.
MD AFZAL Mob: 8179700193
Asst. Professor [email protected]
Example: To cook a new recipe, one reads the instructions/steps and execute them one by one, in the given
sequence. The result can be obtained as a new dish cooked perfectly. Similarly, algorithms help to do a task in
programming to get the expected output.
Example 2:
Problem − Design an algorithm to Calculate the Interest of a Bank Deposit.
Step 1: Start
Step 2: declare amount, year, rate and interest.
Step 3: input amount, year, and rate.
Step 4: interest=Amount*Years*Rate/100.
Step 5: print interest.
Step 6: Stop.
Example-3:
Problem − Design an algorithm to determine whether the Temperature is below or above the
freezing Point (32◦F).
Step 1: Start
Step 2: declare temperature.
Step 3: input temperature.
Step 4: if temperature < 32
print “below freezing point”
else
print “above freezing point”
Step 5: Stop
Example-5:
Problem − Design an algorithm to determine whether a student passed in the exam or not.
Step 1: Start
Step 2: Declare m1, m2, m3, m4, m5, m6 and avg.
Step 3: Read m1, m2, m5, m4, m5 and m6.
Step 4: avg=(m1+m2+m3+m4+m5+m6)/6"
Step 4: if avg < 60
print “FAIL”
else
print “PASS”
Step 5: Stop
Example-6:
Problem − Design an algorithm to find the given number is even or odd.
Step 1: Start
Step 2: Declare num, rem.
Step 3: Read num.
Step 5: if num%2==0
print “num is EVEN”
else
print “num is ODD”
Step 6: Stop
PSEUDO CODE:
Pseudocode is an informal way of programming description that does not require any strict programming
language syntax.
Pseudocode is a methodology that allows the programmer to represent the implementation of an algorithm.
Pseudo codes are used to represent algorithms so that they can be interpreted by programmers irrespective to
their programming background or knowledge.
Pseudo code (as the name suggest, is a false code) is also programming language independent.
Pseudo code has no syntax like any of the programming language, it can’t be compiled or interpreted by the
computer.
Advantages of pseudocode –
• Pseudocode can be understandable by the programmers of all programming languages.
• Pseudocode acts as a bridge between the program and the algorithm or flowchart.
Example:
C code: Pseudocode:
If(i<10) if i is less than 10
{ increment i value by 1
i++;
}
Example-1:
Problem − Design a pseudocode to add, subtract, multiply, divide and to find the reminder of two
numbers and display the result.
This program will allow the user to add two numbers.
Declare variables num1, num2 and sum.
Read values for num1 and num2.
Add num1 and num2 and assign the result to sum.
sum←num1+num2
print the value of sum on the output screen
Example 2:
Problem − Design a pseudocode to Calculate the Interest of a Bank Deposit.
This program will allow the user the user to calculate the interest for a bank deposit.
Declare variables amount, year, rate and interest.
Read values for amount, year, and rate.
Calculate the interest with formula "interest=Amount*Years*Rate/100.
print the value of interest on the output screen.
Example-3:
Problem − Design a pseudocode to determine whether the Temperature is below or above the freezing
Point (32◦F).
This program will allow the user to determine whether the temperature is below or above the freezing
point.
Declare variable temperature.
Read value for temperature.
if temperature value is lesser than 32, print a message “temperature is below freezing point”.
Otherwise print a message “temperature is above freezing point”.
Example-5:
Problem − Design a pseudocode to determine whether a student passed in the exam or not.
This program will allow the user to determine whether a student passed in the exam or not by considering
6 – different course marks.
Declare variables for courses M1, M2, M5, M4, M5, M6 and grade.
Read values for M1, M2, M5, M4, M5 and M6.
Calculate the average grade with formula "Grade=(M1+M2+M3+M4+M5+M6)/6"
if grade value is greater than 60, print a message PASS.
else print a message FAIL.
Example-6:
Problem − Design a pseudocode to find the given number is even or odd.
This program will allow the user to find the given number is even or odd.
Declare variable num, reminder.
Read value for num.
Calculate the reminder by using a formula reminder=num%2.
if reminder is equal to zero, print a message num is EVEN.
else print a message num is ODD
1. Auxiliary Symbols:
These symbols enhance the readability or functionality of the flowchart. They do not show any
instructions or commands.
These symbols are shown in the following figure: (a) Terminal (b) Flow Lines and (c) Connectors
(a) Terminal:
The Oval symbol is used as a terminal.
It is used to show the beginning and ending of an algorithm.
To show the beginning the START is used inside the oval, and to show the ending the
word STOP or RETURN is used inside the oval.
The basic rule of structured programming is every algorithm should have only one
entry point (START terminal) and one exit point (STOP/RETURN terminal).
(b) Flow Lines:
Flow lines are used to connect different symbols of a flowchart. They also shows the
order or sequence of the symbols.
Every symbol in a flowchart will have some entering and some exiting lines.
For example the START oval will have only one exiting line and the STOP oval will
have only one entering line.
(c) Connectors: A connector symbol, a circle with a number in it is used in two situations.
i. When the end of the page is reached but the flowchart is finished: Here a
connector is used at the bottom of the page to show that the flow continues at the
top of the next page. Refer the following figure (a).
2. Primary Symbol:
The primary symbols are used to show the instructions or actions needed to solve the problem.
These category of symbols used to show: (a) Sequence (b) Decision / Condition (Selection
Statements) and (c) Repetition (Looping Statement).
(a) Sequence
Sequence symbols are used to represent actions that must be performed in a linear order.
To this symbols the flow must enter at the top of the symbol, and flow exit at the bottom of the
symbol.
They do not allow any flow change.
There are four different types of sequence symbols:
i. Null statement
ii. Assignment statement
iii. Input / Output statement
iv. Module call statement
v. Compound statement
I. Null statement:
o A null statement is a sequence statement, as it cannot change the flow direction.
o There is no symbol defined to represent a null statement. It is simply a flow line.
V. Compound Statement:
o A broken-line rectangle is used for compound statement.
o All statements that makes the compound statement are encapsulated inside a broken-line
rectangle.
o In C-Programming a compound statement represents a block of code, which is enclosed in curly
brackets.
Example: The following algorithm reads an integer. If the integer’s value is greater than 10, subtract
10 and writes the result. It the value is lesser than 10, it does nothing.
o Although there are three statements in a for loop, but only two actions are performed in each
iteration.
o In the first iteration only initialization and condition are used. In rest of all iterations only
update and condition will be used.
Example: Design a flowchart to read 20 numbers and print the sum. Since the number of times is
known in advance, for loop is an excellent choice.
Example: Design a flowchart that reads numbers from the keyboard and print their total. As the
number of times is not known in advance a conditional loop is the best choice. To break the loop, or
to limit the number of times a negative input -1 can be read from the keyboard.
Example-1:
Problem – Draw a flowchart to add, subtract, multiply, divide and to find the reminder of two numbers
and display the result.
Example-3:
Problem − Draw a flowchart to determine whether the Temperature is below or above the freezing Point
(32◦F).
Example-5:
Problem – Draw a flowchart to determine whether a student passed in the exam or not.
COMMENTS
Comments are helpful in documenting the code.
Comments improves the readability and understanding of the code.
Comments are placed within the program, with actual programming code.
The compiler ignores these comments when it translates the program into executable code.
In C there are two different types of comments:
a. Block Comments
b. Line Comments
(a). Block Comments:
A block comment is used when he comment will span several lines.
A block comment uses an opening token ‘/*’ and a closing token ‘*/’, between opening and closing token
the comment which span more than one line is used.
No space is allowed between the token symbols, that is ‘/’ and ‘*’ should come together like ‘/*’ for
opening comment and ‘*/’ for closing comment.
Example:
/* This is a block comment
Which spans
More than one line */
Nesting of comment: Comments can be nested, one within another. Doing so does not give any specific meaning
but one has to know what happens if we nest the comments. In nesting of comments we have the following
possibilities.
(i) Nesting line comment within a line comment
(ii) Nesting line comment within a block comment
(iii) Nesting block comment within a line comment
(iv) Nesting block comment within a block comment
(i) Nesting line comment within a line comment: Nesting a line comment within a line comment does not raise
any error. The start token of the nested line comment will be ignored by the compiler. Hence will not generate
any error condition.
(ii) Nesting Line comment within a block comment: Nesting a line comment within a block comment will also
not generate any error. The start token of the nested line comment will be ignored by the compiler as part of
the comment. Hence will not generate any error condition.
(iii)Nesting of block comment within a line comment: Nesting of a block comment within a line comment will
generate error, only if the block comment will span more than one line.
IDENTIFIERS:
Identifiers are used to name data and other objects in the program. It is similar to nouns in natural
languages.
When objects are declared in computer program they will be stored at unique memory locations, these
memory locations will have unique addresses to represent them. If we don’t have symbolic names to these
memory locations, then there is need to know and use these addresses to access the memory locations.
Instead of doing the above, we simply give symbolic names (identifiers) to these memory locations, and the
compiler will keep track of where they are stored.
There are some rules while framing the identifier:
1. First character must be an alphabetic character or underscore.
2. Must consisits only of alphabetic characters, digits, or underscores.
3. First 63 characters of an identifier are significant.
4. Cannot be a keyword.
The forst character of the identifier cannot be underscore, because many objects in library files use
underscore as the first letter in their identifiers. If we do the same we may get duplicate names, which
becomes very confusing for the compiler.
MD AFZAL Mob: 8179700193
Asst. Professor [email protected]
C-language is a case sensitive language, that is uppercase and lowercase letters are differently treatted by
the compiler.
No space is allowed withing the identifier. Underscore and Capitalization can be used to separate the words.
KEYWORDS:
Keywords are also known as reserved words. They are syntactical tokens which have special meaning when
used in programming.
Keywords cannot be used as identifiers for variables, functions or named constants in programming.
In C-language there are 37 – keywords, they are listed in the following table:
auto extern short _Bool float signed
break for sizeof case goto static
char if struct _Complex _Imaginary switch
const inline typedef continue int union
default long unsigned do register void
double restrict volatile else return while
enum
The first three types are known as primitive types (or basic types) which are independently defined.
The last type is derived type which are derived from basic types.
1. Void Type:
o The keyword void is used to indicate void type.
o The void type has no values and no operations.
o The void type is used to specify that a function has either no parameters or no return values.
o Example: int main(void); - in this statement the function has no parameters.
o The void type is also used to define a pointer to generic type.
o Example: void* ptr; - in this statement ptr becomes a pointer to the generic type of data.
2. Integral type:
o In C-language there are three integral types namely: Boolean, character and integer.
o Integral types doesn’t hold fractional part they are whole numers.
(a) Boolean:
In C-language Boolean type is included in C99. It is named after the French mathamaticain and
phylosopher George Boole.
A boolean will have only two values: true and false.
Before C99 integers were used to represent the boolean values; a nonzero number (positive or
negetive) is used to represent true, and a zero is used to represent false.
The keyword bool is used refer boolean type.
A boolean type is stored in memory as 0 (false) or 1 (true).
(b) Character:
In computers a character is any value that can be represented in computer’s alphabet (character set).
In C-standard there are two character types: char and wchar_t.
Many computers will use 1-byte to store the char data types. A byte is 8-bits. With 8 bits, there are
256 different possible char values.
In English the letter a is different from x in its visual formation of the graphical associated with the
letter. But in computers the letter a is binary 0110 0001 and letter x is binary 0111 1000. The
decimal values of these two letters 97 for a and 120 for x.
MD AFZAL Mob: 8179700193
Asst. Professor [email protected]
In C99 standard To support non-English languages or languges that don’t use the Roman alphabet
wide charater type (wchar_t) is used.
char
wchar_t
(c) Integer:
An integer type is a number without a fraction part.
C supports four different sizes of integer data types: short int, int, long int and long long int.
A short int also referred as short, long int as long and long long int as long long.
These data types are organized from the smallest to the largest as shown in the following figure.
To know the size of any data type, C provides the sizeof operator, that gives the exact size in bytes.
sizeof(short) < sizeof(int) < sizeof(long) < sizeof(long long)
short int
int
long
long long
3. Floating-Point Types:
In C, there are three floating-point types: real, imaginary and complex.
Floating point types are always signed and there is no possibility for unsigned.
float
double
long double
Type summary: The following type summmerizes the standard data type.
A variable’s type can be any datatype, such as character, integral or real, but cannot be a void type.
To create a variable, first specify the type (datatype) and then the name (identifier).
Variable Creation:
Syntax:
float price;
C-allows multiple variables of same type to be defined at the same time in a single statement. It is
considered as poor programming style
MD AFZAL Mob: 8179700193
Asst. Professor [email protected]
Multiple Variable Creation in Single Statement:
Syntax:
float balance, price;
Variable Initialization:
The variables can be initialized at the same time when they are defined. That is in a single statement it is
possible to do variable declaration, definition and initialization.
To initialize a variable when it is defined, the identifier has to be followed by an assignment operator (=),
and the initilizer value.
Variable declaration, definition and initialization in single
statement:
Syntax:
float price = 3.759;
In multiple variable definitions when initializer is used with only one variable, the initialization will be
applied to that variable only, but not to all.
Multiple variable declaration, definition and initialization in
single statement:
Syntax:
float balance, price = 3.759;
To avoid the above confusion the variables has to be defined in separate lines.
CONSTANTS:
Constants are data values that cannot be changed during program execution.
Like variables, constatns will also have type.
In C there are different types of constants like: Boolean, character, integer, real, complex and string.
Constant Representation:
Boolean Constatnts:
A boolean data type can take only two values. The values are 1(true) and 0(false).
That is, there are only two possible symbols to represent a boolean data type: 1(true) and 0(false).
To use boolean type, requires the inclusion of standard boolean library file into the program stdbool.h.
Integer Constants:
Integer constants are simply coded as they are in real time. The value 15 is simply coded as 15.
By default all integer constants are signed inegers.
To override this default, that is to make the integer constant of different size: for Unsigned (u or U), for long
(l or L), for long long (ll or LL) can be used after the number.
These codes can be combined to get the required meaning.
There is no way to specify a short integer.
If no code is suffixed by default the type will be int.
Examples of Integer Constants
Representation Value Type
+123 123 int
-378 -378 int
-32,228L -32,228 long int
76542LU 76,542 unsigned long int
12789845LL 12,789,845 long long int
Real Constants:
Real constants will have integer part and fractional part seperated by a dot (.). Ex: 37.273
By default all real constants will be in double.
To override this default size: for float (f ot F) and for long double (l or L) can be used as suffix with the
value.
Complex Constants:
Complex constants are widely used in engineering and mathamatical applications.
Complex constants are coded as two parts, the real part and the imaginary part, seperated by a plus sign.
The real part is coded using the real part rules. The imaginary part is coded as real number multipled(*) with
imaginary constant i(√-1).
As with real constant, by default complex constant is double.
To override this for float (f or F) and for long double (l or L) can be used.
Examples of Complex Constants
Representation Value Type
12.3+14.4*i 12.3+14.4*(√-1) double complex
14F+16F*i 14F+16F*(√-1) float complex
1.4736L+4.56756L*i 1.4736L+4.56756L*(√-1) long double complex
String Constants:
A string constant is a sequence of zero or more characters enclosed in double quotes.
“” //An empty String
“h”
“Hello world\n”
“How are your”
“Good Morning!”
“” Empty String
Coding Constants:
General Syntax:
const type identifier = value;
Defining memory constants is similar to defining variable, prefixing const will make the content to be
fixed in the memory location, and cannot be changed.
The memory constants must be initialized where they are defined, otherwise they permanently hold a
garbage value.
For example:
const float PI = 3.141592;
const INTEREST_RATE 0.5