Computer
Programming
• Course Code: CSC-113
• Course Instructor: Mehreen Tariq
• Email:
[email protected]Projects/Homework submission
• Deadlines are always final
• Submission guidelines must be followed.
• Name your submission folder in the format RollNo_Name_HW /
Assignment #
• e.g., 123_Name_HW#3
• No grouping is allowed in assignments.
• No Cell Phone is allowed during class.
• I’ll mark attendance in first 15 minutes. After this I’ll not mark anyone’s
attendance.
2
Dishonesty, Cheating in Quizzes,
Assignments & Presentations
• Copying material in any form (code or otherwise) is not allowed.
• This will still be cheating even if you try to substitute or restructure
words, structures, phrrases.
• You can always discuss to solve problem with your colleagues
however you should not copy code.
• Penalty can be a zero in that and one other assignment on to a penalty
of an F in the course.
3
Assignment = 20% Last two assignments
will be CCP
•5
Grading Quiz = 10%
•5
Mechani
sm MidTerm = 20%
Final Exam = 50%
Course Outline
• Course Introduction
• Problem Understanding
• Introduction to Programming Language
• Interactive Programming
• Library Functions
• Introducing Decision Control
• Extended Decision Control
• Switch Control
• Repetition Control
• MidtermRepetition Control
Extended
Course Outline (cont..)
• Introduction to Functions
• Types of Functions
• Introduction to Arrays
• Types of Arrays
• Arrays and Functions
• Introduction to Structures
• Structures and Arrays
• Introduction to Pointers
• Structures and Pointers
• FinalHandling
File term
Course Skills
• Analysis
• Critical Thinking (Design)
• Attention to detail (Code)
• Test
Book
Deitel & Deitel, “C++ How to Program”
C++ Programming from Problem Analysis to Program Design 5th
Edition by DS Malik
Tony Gaddis, “Starting out with C++”, 6th Edition, Pearson
What is Computer?
“A computer is a programmable electronic device that
accepts raw data as input and processes it with a
program to produce the result as output.”
Computers are STUPID
Humans are even
more…….
What is Program?
“A precise sequence of steps to
solve a particular problem”
Design Recipe
To design a program properly, we must:
• Analyze a problem statement, typically expressed as a word problem
• Express its essence, abstractly and with examples
• Formulate statements and comments in a precise language
• Evaluate and revise the activities in light of checks and tests
Why Program?
Computer – programmable machine designed to follow instructions
Program – instructions in computer memory to make it do something
Programmer – person who writes instructions (programs) to make
computer perform a task
SO, without programmers, no programs; without programs, the
computer cannot do anything
Type of Languages
• Low Level Language (Machine Language)
• High Level Language (Human Language)
Hardware
Hardware refers to the
physical components
that a computer is made
of
control unit and
arithmetic and logic
unit (ALU)
Workflow of a Program
• A program is a sequence of instructions stored in the computer’s
memory. Computer (CPU) follows the fetch/decode/execute cycle to
run the program
Fetch: The CPU’s control unit fetches from main memory the next instruction in the sequence of
program instructions.
Decode: The instruction is encoded in the form of a number. The control unit decodes the
instruction and generates an electronic signal.
Execute: The signal is routed to the appropriate component of the computer (such as the ALU, a
disk drive, or some other device). The signal causes the component to perform an operation.
Software
Operating System (System Software):
An operating system is a set of programs that
manages the computer’s hardware devices and Software refers to the
programs that runs on a
controls their processes.
computer.
E.g., Windows, MacOS, IOS, Android, Dos
Operating systems fall into one of the following
categories.
1. Single Tasking
2. Multitasking
In addition, operating systems fall into one of the
following categories, which describe the number of
users they can accommodate.
Software
Application Software:
Refers to programs that make the computer Software refers to the
useful to the user. These programs solve programs that runs on a
specific problems or perform general computer.
operations that satisfy the needs of the user.
E.g., Word processing, spreadsheet, and
database programs
Checkpoint
1. List the five major hardware components of a computer system.
2. Explain why computers have both main memory and secondary
storage.
Computer Programming
Computer programming is both an art and a science. It is an art
because every aspect of a program should be carefully designed. Listed
below are a few of the things that must be designed for any real-world
computer program:
The logical flow of the instructions
The mathematical procedures
The appearance of the screens
The way information is presented to the user
The program’s “user-friendliness”
Manuals and other forms of written documentation
Programming Languages
A Programming Language is a
special language used to write
a computer program
Programming Process
• Design
• Create
• Test
• Debug Example:
Problem: To calculate the user’s gross pay.
Input: Number of hours worked, hourly pay rate.
Process: Multiply number of hours worked by hourly pay rate.
The result is the user’s gross pay.
Output: Display a message indicating the user’s gross pay.
Ways of Analyzing a Program
Pseudo code:
It’s simply an implementation of an algorithm in the form of
annotations and informative text written in plain English. (a method of
developing an algorithm)
Algorithm:
It’s an organized logical sequence of the actions or the approach towards a
particular problem. A programmer implements an algorithm to solve a problem.
Flowcharts:
Defines the flow of the instructions defined through the pseudocode or algorithm.
Algorithm
Problem: Addition of two numbers
Step 1: Start
Step 2: Declare variables num1, num2 and sum.
Step 3: Read values for num1, num2.
Step 4: Add num1 and num2 and assign the result to a variable sum.
Step 5: Display sum
Step 6: Stop
Algorithm (example #2)
Read the Value of number1 and number2.
SUM = number1+number2.
Display SUM.
Stop.
Pseudocode
Start/Begin
Declare two numbers (number1 and number2)
Assign value to number1
Assign value to number2
Compute number1+number2
Display result
end
Flowcharts
• Flowcharts is a graph used to show a step by step solution using symbols
which represent a task.
• The symbols used consist of geometrical shapes that are connected by
flow lines.
• It is an alternative to pseudo coding; whereas a pseudocode description
is verbal, a flowchart is graphical in nature.
28
Flowchart symbols
Symbols Purpose Description
Indicates the flow of logic by
Flow line
connecting symbols.
Represents the start and the end of a
Terminal(Stop/Start)
flowchart.
Input/Output Used for input and output operation.
Used for arithmetic operations and
Processing
data-manipulations.
Used for decision making between two
Decision
or more alternatives.
Flowchart
Example
START
Step 1: Input M1,M2,M3,M4
Step 2: GRADE (M1+M2+M3+M4)/4
Input
M1,M2,M3,M4
Step 3: if (GRADE <50) then
Print “FAIL”
else
GRADE(M1+M2+M3+M4)/4 Print “PASS”
endif
N IS Y
GRADE<50
PRINT PRINT
“PASS” “FAIL”
STOP
Example 2
• Write an algorithm and draw a flowchart to convert the length in feet
to centimeter.
Pseudocode:
• Input the length in feet (Lft)
• Calculate the length in cm (Lcm) by multiplying LFT with 30
• Print length in cm (LCM)
Example 2
Flowchart
Algorithm
• Step 1: Input Lft START
• Step 2: Lcm Lft x 30 Input
Lft
• Step 3: Print Lcm
Lcm Lft x 30
Print
Lcm
STOP
Example 3
Write an algorithm and draw a flowchart that will read the two sides
of a rectangle and calculate its area.
Pseudocode
• Input the width (W) and Length (L) of a rectangle
• Calculate the area (A) by multiplying L with W
• Print A
Example 3
Algorithm START
• Step 1: Input W,L
Input
• Step 2: AL x W W, L
• Step 3: Print A
ALxW
Print
A
STOP
Flowchart – sequence control structure
Statement 1
Statement 2
Statement 3
36
Flowchart – selection control structure
No Yes
Condition
else- then-
statement(s) statement(s)
37
Flowchart – repetition control structure
yes Loop
Condition
Statement(s)
no
38
Flowchart – example
Begin
Read birth date
Calculate
Age = current year – birth date
Display
age
End
39
Flowchart – example
Begin
Read age
YES Age > 55? NO
print “Pencen” print “Kerja lagi”
End
40
Flowchart – example
Begin
sum = 0
current_number = 1
NO
current_number <= 10? print sum
YES
End
sum = sum + current_number
current_number = current_number + 1
41
Exercises: Algorithm & Flowchart
1.) Create an algorithm and a flowchart that will accept/read two numbers
and then display the bigger number.
2.) Create an algorithm and a flowchart that will compute the sum of two
numbers. If the sum is below or equal to twenty, two numbers will be
entered again. If the sum is above 20, it will display the sum.
3.) Create an algorithm and a flowchart that will output the largest number
among the three numbers.
Reference:
Tony Gaddis, “Starting out with C++”, 6th Edition, Pearson -> Chapter 01
Summary
Course Introduction:
Introduction to course, department, and university regulations and
culture; Course Outline
Problem Solving: Addition problem solve using pseudo-code
Introducing Decision Control:
Flowcharts for pictorial view of decisions (two-way)
if … else