You are on page 1of 43

CSC103 Programming Fundamentals

Lecture # 01
Muhammad Farhan
Department of Computer Science
COMSATS University Islamabad,
Lahore Campus
muhammadfarhan@cuilahore.edu.pk

The Slides are adopted from C How to Program


by Deitel & Deitel
Course Information
Textbooks
 C How to Program by Deitel & Deitel, Publisher: Prentice Hall; 7
edition (2013)
 Problem Solving and Program Design in C by Elliot Koffman
 C Programming Language by Brian W. Kernighan, Dennis M.
 Ritchie Publisher: Prentice Hall; 2 edition (1988)
Course Evaluation
Theory (100) Lab (100)
 4 Assignments (10%)  4 Assignments (25%)
 4 Quizzes (15%)  Mid term exam (25%)
 Mid term exam (25%)  Final exam (50%)
 Final exam (50%)

= (Theory obt. /100) * 67 + (Lab obt. /100) * 33


Note: 50% marks mandatory in both Theory and Lab
for passing the course
Class Expectations
 Come to lectures on time and participate
 Keep up with reading material
 Complete assignments, projects, etc on time
 Submit clean, organized, and to the point reports
Key to Success
Attendance
 Pay attention to lectures and keep extra notes
 Ask questions
Effort
 Do homework on your own. It’s ok to ask others but
make your own effort.
Consistency
 Keep up with reading, and homework.
Plagiarism Policy
 According to this policy, a student's submitted work must
be the student's own. In this course, this policy will be
applied to all work submitted for grade including exams,
quizzes, homework, and projects.
What is a Computer?
Computer
 Device capable of performing computations and
making logical decisions
 Computers process data under the control of sets of
instructions called computer programs
Hardware
 Various devices comprising a computer
 Keyboard, screen, mouse, disks, memory, CD-ROM,
and processing units
Software
Programs that run on a computer
 System Software
 Application Software
What’s Inside a Computer
Data Hierarchy
• Bits
• Characters
• Character set (Unicode, ASCII, etc)
• Fields
• Records
• Files
• Database
• Big Data
Data Hierarchy
Byte Measurements
Software Categories
There are two main categories of software

 System software

 Application Software

These software often called as computer programs


written by computer programmers using programming
language.
3P’s
Program
A set of rules for your computers to follow in
order to achieve a goal
Programmer
A person who produces the program
A person who makes a living from producing
programs
Programming language
A way for a programmer to write about the set
of rules
The 3P Relationship

Programmers write programs


using programming languages.
Computer Program
A computer program is a collection of
instructions that performs a specific task when
executed by a computer.
A computer program is usually written by a
computer programmer in a Programming
language.
Computer Programmer
A computer programmer, sometimes called
a coder (especially in more informal
contexts), is a person who creates computer
programs.

Computers are creatures from outer space


They speak strange languages

Programmers study their languages


Therefore, they are able to tell the computers
what to do
What is Computer Programming?
A way to solve problems using a computer

Computer programming is the process of designing and


building an executable computer program for accomplishing
a specific computing result.

How?
Through a sequence of very clear and defined steps (algorithm) using a
specific language (programming language) that aim to solve the problem

Algorithms are not only used for computer programming, they are
a general concept for problem solving
Programming Languages
 Programming languages are used in computer
programming to implement algorithms.

Programming languages categories


 Low-level languages
 Machine language
 Assembly language
 High-level languages
Programming Levels
Generations of programming
language
Generation First Second Third Fourth
101010100110
0010 body.top {
100110101000 color :
LDA 34 ADD
Code example 0001 x = x + 1 red; font-
111111111010 #1 STO 34
style :
0010 italic }

(HIGH)  (HIGH) SQL, 
(LOW) Machine (LOW)
Language Visual Basic, C,  CSS, Haskell
Code Assembly Code python etc.  etc.
Machine, Assembly and High
Level Language
Three types of programming languages
1. Machine languages
Strings of numbers giving machine specific instructions. Programs
written in machine language consist of entirely of 1s and 0s
Example:
00101010 000000000001 000000000010
10011001 000000000010 000000000011
2. Assembly languages
English-like abbreviations representing elementary computer operations
(translated via assemblers)
Example:
LOAD BASEPAY
ADD OVERPAY
STORE GROSSPAY
Machine, Assembly and High
Level Language
3. High-level languages
Codes similar to everyday English
Translated via compilers
Example:
grossPay = basePay + overTimePay
Print “Your total pay is ” grossPay
Compilers vs. Interpreters
Compilers
 Compile several machine instructions into short sequences to simulate
the activity requested by a single high-level primitive
 Produce a machine-language copy of a program that would be
executed later
 Convert source code into object code
Interpreters
 Execute the instructions as they were translated
Source Code vs Object Code
Source code is the list of human-readable
instructions that a programmer writes
Object code is the output of a compiler after it
processes source code.
Programming (Revisited)
A way to solve problems using a computer

You are given a problem and asked to write a


program to solve that problem, e.g. decide
whether a number input by user is even or odd?
Steps in developing a program
 Defining the problem
 Analyzing the problem statement
 Planning the solution
 Coding the program
 Testing the program

Documenting the program (optional but important)


 Commenting
Developing a Program

Problem solving Phase

Implementation phase
Problem solving and Implementation
A programming task can be divided into two
phases:
1. Problem solving
Define : Clearly describe a problem
Design its solution (Algorithm): Produce an
ordered sequence of steps that describe solution to the
problem;

2. Implementation phase
Implement the program in some programming
language
write code, compile, link, Test & Debug
Problem solving and Implementation
Defining a Problem:
Break the definition of the problem down into
manageable steps. Example; input, Processing, Output
Program: Write a program which tells whether the
temperature entered by user in below freezing point or
not?

Input ; Read the temperature from keyboard


Processing; Test the Temperature below or above
freezing
Output; Display the result on Screen
Problem solving and Implementation

Design the solution (Algorithm):


Algorithm
A sequence of language independent steps which
may be followed to solve a problem.
Algorithm
The word Algorithm comes from the name of the
muslim author Abu Ja’far Mohammad ibn Musa
al-Khowarizmi.
Algorithm
 A computer algorithm is a detailed step-by-
step method for solving a problem by using a
computer.
 An algorithm is a sequence of unambiguous
instructions for solving a problem in a finite
amount of time.
 An Algorithm is well defined computational
procedure that takes some value, or set of
values, as input and produces some value, or
set of values as output.
Algorithm
Algorithm and Programming
 good understanding of algorithms is essential for a
good programming
 Unlike a program, an algorithm is a mathematical
entity, which is independent of a specific
programming language, machine, or compiler.
 Algorithm design is all about the mathematical
theory behind the design of good programs
Algorithm and Programming
An Algorithm can be developed with a:

• Pseudo Code
Pseudocode is an informal high- level description of
the operating principle of a computer program or
other algorithm
• Flowchart
A flowchart is a type of diagram that represents a
workflow or process.
Pseudo Code (Example)
Example: The following set of instructions forms a
detailed algorithm in pseudo-code calculate the pay
of a person.

Begin
Input the three values into the variables Name, Hours, Rate.
Calculate Pay = Hours * Rate.
Display Name and Pay.
End
Flowcharts (Example)
Programming Languages
(Revisited)
 Programming languages are used in computer
programming to implement algorithms.

Programming languages categories


 Low-level languages
 Machine language
 Assembly language
 High-level languages
 C
History of C
 The C language was evolved by Dennis Ritchie from two previous
programming languages, BCPL and B
 Standard Created in 1989, updated in 1999
 C programs consist of pieces/modules called function
 A programmer can create his own functions
 Programmers will often use the C library functions
 Use these as building blocks
 Avoid re-inventing the wheel
 C++  A superset of C was developed by Bjarne Stroustrup at
Bell Labs
 Object Oriented Design of C++ - Code REUSABILITY Because C+
+ includes C, it’s best to master C then learn C++
 Other object oriented programming languages are: JAVA,
FORTRAN, COBOL, Pascal etc
Built for performance
• Operating Systems

• Embedded Systems

• Real time systems

• Communication Systems
ANSI C
Tools of the trade
 Editor
 Interpreter and Compilers
 Debuggers
Integrated Development Environment
(IDE)
It contains
 Editor
 Compilers
 Debugger
 Linkers
 Loaders
C Program Development Environment
Program is created in the editor
Editor Disk
and stored on disk.
Preprocessor program
Preprocessor Disk processes the code.
Compiler creates object
Compiler Disk code and stores
it on disk.
Linker Disk Linker links the object
code with the libraries
Primary Memory
Loader
Loader puts program in
Disk ..
memory.
..
..

Primary Memory CPU takes each


CPU
  instruction and executes
it, possibly storing new
.. data values as the
..
.. program executes.

You might also like