Week 2
Week 2
for Mathematics
Week 2
Lecture 3 and 4
Shakeel Ahmad
Minhaj University, Lahore
Administrative information
Course Syllabus
Homework assignments
Class notes
Class programs
Compiler instructions
Link to the class mailing list
5
Introduction to
Programming Languages
The purpose of this course is to teach
you about computing, but particularly,
programming in C++ (a powerful,
widely-used programming language).
What Is a Computer?
Computer
Performs computations and makes logical decisions
Millions / billions times faster than human beings
Computer programs
Sets of instructions by which a computer processes
data
Hardware
Physical devices of computer system
Software
Programs that run on computers
Computer Organization
Six logical units of computer system
Input unit
Mouse, keyboard
Output unit
Printer, monitor, audio speakers
Memory unit
Retains input and processed information
Evolution of Operating
Systems
Batch processing
One job (task) at a time
Operating systems developed
Programs to make computers more convenient to
use
Switch jobs easier
Multiprogramming
Simultaneous jobs
Timesharing operating systems
10
2003 Prentice Hall, Inc. All rights reserved.
11
Operating System
Once it is loaded, it configures the various
hardware components
Then it waits for the user to issue commands
Then you can run your applications
12
Assembly languages
English-like abbreviations representing elementary
computer operations (translated via assemblers)
Example:
LOAD
ADD
STORE
BASEPAY
OVERPAY
GROSSPAY
13
14
COBOL
Used to manipulate large amounts of data
Pascal
Intended for academic use
15
Very reusable
More understandable, better organized, and easier to
maintain than procedural programming
Favor modularity
16
Types of Errors
Syntactic Errors
Input code is not legal
Caught by compiler (or other translation mechanism)
Semantic Errors
Legal code, but not what programmer intended
Not caught by compiler, because syntax is correct
Syntactic Errors
Common errors:
missing semicolon or brace
mis-spelled type in declaration
Semantic Errors
Common Errors
Missing braces to group statements together
Confusing assignment with equality
Wrong assumptions about operator precedence, associativity
Wrong limits on for-loop counter
Uninitialized variables h
missing braces,
so printf not part of if
main () {
int i
int j;
for (i = 0; i <= 10; i++)
j = i * 7;
printf("%d x 7 = %d\n", i, j);
}
Algorithmic Errors
Design is wrong,
so program does not solve the correct problem
Difficult to find
Program does what we intended
Problem might not show up until many runs of program