Professional Documents
Culture Documents
USING COMPUTERS (PSUC)
Introduction to computers
Algorithms &Flowcharts
C++ Fundamentals
Operators and Expressions
Flow of control
Derived Data types
Functions
Structures
Pointers
File Manipulation
Text Books:
E. Balaguruswamy, “Computing Fundamentals & C Programming”,
Tata McGraw Hill, 2008.
E. Balaguruswamy, “Object Oriented Programming with C++”, Tata
McGraw Hill, 2nd Edition 2007.
References:
Kernighan and Ritchie,” ANSI C Language”, Prentice Hall of India, New
Delhi, 1992.
Yashavant Kanetkar, “Let Us C”, 10th Edition, BPB Publications, 2010.
Byron S. Gottfried, “Programming with C”, Schaum's Outline Series,
2nd Edition 1996.
Robert Lafore, “Object Oriented Programming with Turbo C++”,
Gagotia Publications, 2002.
Ellis Horowitz, Sartaj Sahni, Sanguthevar Rajasekaran, “Computer
Algorithms”, Galgotia Publications, 2001.
Slides and books of Infosys Campus Connect – Foundation Program.
7/23/2012 Department of CSE 2
Mode of evaluation – Theory
Internal
• Sum of two Sessional tests
20 +20 = 40 marks
• Sum of best two Assignments/quizzes/open book tests
5 + 5 = 10 marks
Sub Total = 50 marks
External
• Semester Exam = 50 marks
Total = 100 marks
• End Semester Exam = 40 marks
(Write‐up =15 marks,
Execution =25 marks)
Total = 100 marks
If a student is absent on a particular week, he/she will loose 50% of
execution marks.
What is a computer?
Storage devices
(CD-RW, Floppy,
Hard disk, zip,…)
Mouse
(input)
Scanner Keyboard
(input) (input)
• Input
• Process/Computation
• Storage
• Output
• Accuracy.
• Once the program is stored in memory the computer can start the
operation by executing the program instructions one after the
other.
Central Processing
unit Output Device
Arithmetic Logic
Input Device Unit
Control unit
Auxiliary storage
Device
Primary storage
Control unit
Auxiliary storage
Device
Primary storage
Central Processing
unit Output Device
Arithmetic Logic
Input Device Unit
Control unit
Auxiliary storage
Device
Primary storage
Control unit
Auxiliary storage
Device
Primary storage
Representation:
(Floppy) disks
Hard disks
CD‐ROM’s
Flash drives
… and more
Central Processing
unit Output Device
Arithmetic Logic
Input Device Unit
Control unit
Auxiliary storage
Device
Primary storage
Software:
Software
Application System
Software Software
MS Access
7/23/2012 Department of CSE 30
Computer Languages
• Machine Language‐ The only programming language available
in earlier days
– Consists of only 0’s and 1’s; e.g.:- 10101011
• Symbolic language or Assembly language‐
– symbols or mnemonics used to represent instructions
– hardware specific
e.g. ADD X,Y; Add the contents of y to x
• High‐level languages‐ English like language using which the
programmer can write programs to solve a problem.
– more concerned with the problem specification and not
oriented towards the details of computer.
– e.g.: C, C++, C#, Fortran, BASIC, Pascal etc.
Machine level language High Level Language
1. Uses only 2 symbols, zero and one. Uses alphabets, digits, punctuations and some
special symbols
2. Each instruction is a sequence of zero’s and Each instruction is English like statement.
one’s.
3. Can be directly executed. Cannot be directly executed.
4. Machine dependent. Machine independent.
5. Difficult to understand, modify, write and Easy to understand, write, modify and debug.
debug.
6. Efficient (Fast). Less Efficient (Slow).
7. Not Standardized. Standardized.
8. Called as First generation programming Called as Third generation programming
language. language.
Assembly language High Level Language
1. Assembly language increases the efficiency They are to be compiled or interpreted & are
of the MLP resulting from it. less efficient compared to ALP
2. Difficult and time consuming to write a It is easy to write a program in this language as
program. it uses English like statements.
3. Assembly language programmer must be Only the syntax of this language is to be learnt
an expert who knows all about the logical to write programs in this language.
structure of the computer.
4. It is machine dependent. They are designed independent of the structure
Program written for one model of The compiler translates the high level language
computer can’t be executed on another into machine language and the program written
model. In other words it is not portable in high level language can be executed on
from one machine to another. different computers.
5. It has greater flexibility in writing programs More device independent but syntax
well matched to the computers. dependent program to be written. Just usage of
the available syntax of structures within high
level language.
Compiler Interpreter
1. Takes entire high level language Takes one statement of a high level
program as input and translate language program as input &
into machine language translates into machine language &
executes.
2. Errors that occur in the program Errors that occur only in the
are listed & displayed. statement being taken for translation
are displayed.
3. Debugging is faster. Debugging is slower.
4. Requires more memory. Requires less memory.
5. Costlier Cheaper.
Types:
Single user [DOS] and Multi user OS [Windows XP, Unix],
Real time OS [Windows CE, QNX],
Single‐tasking [DOS] and Multi‐tasking [Unix],
Distributed OS [Amoeba],
Embedded OS [Windows CE, Symbian OS] etc.
• A program that runs on the “raw” hardware and supports
– Resource Sharing
• Abstracts and standardizes the interface to the user across
different types of hardware
– OS hides the messy details which must be performed
• Manages the hardware resources
– Each program gets time with the resource
– Each program gets space on the resource
• Manages different goals:
– Use hardware efficiently and give maximum performance to each user.
Common Number Systems
Used by Used in
System Base Symbols humans? computers?
Decimal 10 0, 1, … 9 Yes No
Binary 2 0, 1 No Yes
Octal 8 0, 1, … 7 No No
Hexa- 16 0, 1, … 9, No YES/No
decimal A, B, … F
to some power.
1 0 0 1 1 0 1
26 25 24 23 22 21 20
Decimal Octal
Binary Hexadecimal
Weight
Base
• Technique
the bit
on the right
Bit “0”
1010112 => 1 x 20 = 1
1 x 21 = 2
0 x 22 = 0
1 x 23 = 8
0 x 24 = 0
1 x 25 = 32
4310
7248 => 4 x 80 = 4
2 x 81 = 16
7 x 82 = 448
46810
• Technique
– Multiply each bit by 16n, where n is the “weight”
of the bit
• The weight is the position of the bit, starting from 0
on the right
274810
• Technique
– Divide by two, keep track of the remainder
– First remainder is bit 0 (LSB, least‐significant bit)
– Second remainder is bit 1
– So on.
12510 = 11111012
• Technique
binary representation
7058 = ?2
7 0 5
7058 = 1110001012
10AF16 = ?2
1 0 A F
10AF16 = 00010000101011112
– Keep track of the remainder
123410 = ?8
8 1234
8 154 2
8 19 2
8 2 3
0 2
123410 = 23228
– Keep track of the remainder
123410 = ?16
16 1234
16 77 2
16 4 13 = D
0 4
123410 = 4D216
10110101112 = ?8
1 3 2 7
10110101112 = 13278
– Convert to hexadecimal digits
10101110112 = ?16
10 1011 1011
2 B B
10101110112 = 2BB16
10768 = ?16
1 0 7 6
2 3 E
10768 = 23E16
1F0C16 = ?8
1 F 0 C
1 7 4 1 4
1F0C16 = 174148
Hexa-
Decimal Binary Octal decimal
33
1110101
703
1AF
• What is the value of “kB”, “MB”, and “GB” …?
• In computing, particularly w.r.t. memory, the base‐2
interpretation generally applies.
7/23/2012 Department of CSE 83
Example
In your laptop/lab machine…
1. Double click on My Computer
2. Right click on C:
3. Click on Properties
/ 230 =
Free space
Drive Bytes GB
A:
C:
D:
E:
etc.
ab ac = ab+c
A B A+B
0 0 0
0 1 1
1 0 1
1 1 10
“two”
– Propagate carries
– E.g.,
1 1 1
10101 29
+ 11001 + 25
101110 54
35
x 105
175
000
35
3675
A B AB
0 0 0
0 1 0
1 0 0
1 1 1
– E.g., 1110
x 1011
1110
1110
0000
1110
10011010
• Decimal to binary x
.14579
2
3.14579 0.29158
x 2
0.58316
x 2
1.16632
x 2
0.33264
x 2
0.66528
x 2
1.33056
11.001001... etc.
Hexa-
Decimal Binary Octal decimal
29.8
101.1101
3.07
C.82
Do not use a calculator!
bits.
• Represent -1810 using 8‐bit 2’s complement
• Since number is negative we need to do 1’s complement and add 12
– Step 1: Convert 1810 to 8‐bit binary = 000100102
– Step 2: Invert bits = 111011012
– Step 3: Add 12 = 111011102
– Final result: ‐1810 = 1 1 1 0 1 1 1 0 2 in 8‐bit 2’s complement