100% found this document useful (1 vote)
161 views80 pages

CS114 - Fundamentals of Programming: Qurrat-Ul-Ain Babar

1. Understand the problem fully by gathering relevant information. 2. Devise a plan or strategy to solve the problem by thinking of possible solutions. 3. Carry out the plan by breaking it down into small, traceable steps. 4. Look back on the solution to check that it correctly solves the problem, and see how it can be improved.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
161 views80 pages

CS114 - Fundamentals of Programming: Qurrat-Ul-Ain Babar

1. Understand the problem fully by gathering relevant information. 2. Devise a plan or strategy to solve the problem by thinking of possible solutions. 3. Carry out the plan by breaking it down into small, traceable steps. 4. Look back on the solution to check that it correctly solves the problem, and see how it can be improved.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 80

CS114 – Fundamentals of Programming

Q U R R AT- U L - A I N B A B A R
Overview

Introduction

Course details

Assessment

What is this course about?

Aims and Outcomes


Introduction

Instructor: Qurrat-ul-ain Babar


 Email: [email protected]
 Office: 115, NIT Building
 Contact No: 051 9085 4015
 Counseling/Consultation Hours
 Tuesday & Wednesday – 1000 – 1200 hrs
 It will be best if you take an appointment by email first
Course Details
CREDITS: 2+1
Course Details

Credits: 2+1
Grade distribution is (67% + 33%) Content
• Theory – 67%
• OHT
• ESE
• Practical – 33%
• Lab Work – 70%
• Lab Project/Exam – 30%

Lecture Lab
Course Description

An introduction to the development of programs using


C++.
Emphasis is given to the development of program
modules that can function independently.
 Object-oriented design
The theory of data structures and programming
language design is continued.
What is this course about?

Problem solving
Designing solutions using flowcharts
Basic computer programming using C/C++
Logic building & algorithms
Text Book

Book
 There are many books on C/C++
 All of them teach almost the same thing

Book only teaches you the syntax.


You must know yourself how to use that syntax.
Text Book
Reference Book
Course Contents
Week Topics
1 Introduction to Course, Introduction to Computer: System components,
networks and operating systems
Lab: Computer Hardware and Operating System

2 Introduction to Logic, Flow Charts, Pseudo Code, Introduction to Programming


Lab: Problem Solving using Flow Charts (Visual Logic), Testing the
Programming Environment and Basic Program
3 Programming Environment, Basic Programming, Statements, Expressions,
Comments
Lab: First Program, Basic statement, and Output Formats
4 First Program, Compilation, Variables, Types, Operators, Debugging
Lab: Variable processing, Arithmetic operations, Finding Errors
5 I/O, interactive programming
Lab: User Input based programming
6 OHT – I
Course Contents
Week Topics
7 Relational operators, logical operators, conditional statements
Lab: Conditional Constructs I

8 If-Else Statement, Switch-Break-Continue


Lab: Conditional Constructs II

9 Iterations, For loop, Do-While Loop, While Loop


Lab: Loops and Iterations

10 Functions, parameters to functions


Lab: Function Definition, Function Parameters and calls

11 More functions, Recursion


Lab: Function reuse and recursion

12 OHT – II
Course Contents
Week Topics
13 Arrays
Lab: Arrays and Operations on Arrays
14 Structures
Lab: Structure definition and usage
15 Pointers
Lab: Pointers, Variable Pointer
16 File I/O
Lab: File Handling and Information storage
17 Project demos, Revision
Lab: Project Demos
18 ESE

19 ESE
Course Outcomes

By the end of the course, you should be able to:


1. Comprehend the fundamental concepts of computer
systems.
2. Apply programming skills to implement computer-
based solutions of well specified problems.
3. Analyze where computer programs fit in the provision
of computer-based solutions to real world problems.
Ground Rules
Attendance Policy

Will be marked at the beginning/end of the class (usually


within first 10 mins)
Any missed attendance is your own responsibility
No late attendance marking
Quiz Policy

5-6 quizzes in whole semester


Unannounced
No drop quiz
Assignment Policy

3 - 4 Assignments
No drop policy
No late/email submissions will be accepted
Zero tolerance for plagiarism/cheating
 Discussing homework concepts is fine, but you must submit your
own work.
Lab Tasks Policy

Each student will submit their own work at the end of


each lab
No late/email submissions will be accepted
Zero tolerance for plagiarism/cheating
 Discussing lab task is fine, but you must submit your own work.
Pop Lab Quiz – which can be unannounced, you should
expect a lab quiz after every 3/4 lab sessions.
Student Civility

In an effort to make this class enjoyable for everybody…


 Please be on time to class!
 Please do not talk to your friends in class! It disturbs everyone, and
makes it hard to concentrate. If you have a question, just raise your
hand!
 Please turn your cell-phones off! No usage of mobiles during class –
will have a penalty.
Interaction is the key
 Please ask questions
 If you don’t understand, ask
 Let me know if I am going too slow/too fast
Student Civility

No room for indecency in this class.


Introduction

Brief Introduction of students


 Name
 Qualification (FSc/A-Levels)
 Day Scholar/ Hostelite
 % in FSc/A-Levels
 Your aim/aspiration in life
Road Map for Today
• Computer Programming in Engineering
• History of Computers
• Introduction to Computers
• Introduction to Programming
Why study Computer
Programming in Engineering?
HISTORY OF COMPUTERS
Hardware and Software
• Charles Babbage
Creator of the Analytical Engine - the first
general-purpose digital computer (1833)

• ENIAC - the Analytical Engine was not built


until 1945 (Harvard Mark I) (courtesy : Wikipedia.org)

– World’s first programmable computer


– Could carryout any calculation
– CPU was 8 feet tall , 100 feet long and
weighed 30 tons

(courtesy of US Army Historic Computer


Images)
History of Computers

• Ada (1815-52)
Wrote a program for computing the
Bernoulli’s sequence on the Analytical
Engine - world’s 1st computer program
INTRODUCTION TO
COMPUTERS

A device that can


perform
computations and
make logical
decisions
Motherboard
Input
devices
Processing
devices
Memory
devices

RAM:
Volatile memory

ROM:
Non-volatile
memory
Storage Magnetic storage:
devices Hard disks
Non-volatile memory

IDE - Integrated SCSI - Small Computer


Drive Electronics Systems Interface
Storage Optical storage:
devices CD/ DVD
Non-volatile memory
Output
devices
Communication
devices
System
Software

Name some other Operating


Systems
Application
Software
A Layered View of the Computer
Application Programs
Word-Processors, Spreadsheets,
Database Software, IDEs,
etc…
System Software
Compilers, Interpreters, Preprocessors, etc.
Operating System, Device Drivers

Machine with all its hardware


Can computers think?
Even the most powerful
supercomputers require
human interaction!
W hy ??
1. Setting up the system
2. Installing software
3. Running programs
4. Managing files
5. Maintaining the system
Commonly used
Programming languages

Perl
Basic

Pascal
Cobol
Microsoft

Net C++
C Python
We teach C++, Why?
• C++ is one of the most popular languages 
– C++ (originally C)
• C++ is portable (runs on Windows, Macintosh, Unix,
Mainframes …)
• C++ is widely used in industries 
• C++ is not easy to learn 

C++

C
DevC++
• We will be using DevC++
• Full-featured Integrated Development Environment
(IDE)
• Home task:
– Download and install DevC++ on your PCs
INTRODUCTION TO
PROGRAMMING

Computer has to
be precisely told
what it needs to
do; otherwise
Program
• Programs are everywhere on the computer and
internet

• Even operating systems are


programs
Program
“a precise sequence of steps to solve a
particular problem”

• Programs are run or executed (like OS runs on


Hardware like laptop or cell phone)
• Programs can also be run by other programs (like
when we play games in a web browser)
Program design
Hierarchy chart

Flow chart
Program
Designing
Pseudo Code

Source Code Machine Code


Program coding
Hierarchy chart

Flow chart a m
g r
r o ng
P d i
Pseudo Code
C o

Source Code Machine Code


Program design

Hierarchy Chart
Program design

2 ways to show details:

i) Pseudocode: describes logic and processing


flow in human-language statements

ii) Flow chart: graphically represents logic flow.

Most projects use both methods


Problem Solving
Problem Solving

Understand the Problem


 Knowledge of the problem, its domain, & details
Devising the Plan
 Thinking of possible solutions
Carrying out the Plan
 Create retraceable steps
Looking Back
 Compare solution to problem. Improve.
Problem

A shepherd's son is helping his father build a pen for their


sheep. The pen will be 24m long and 20m wide, and have
fence posts 4m apart. How many fence post does he
need?
Fence Problem Solution

Understand
 Rectangle
 Length of sides 24x20m
 Posts 4 meters apart
 Number of posts?
Plan
 Drawing a diagram may help
 Start from corner posts perhaps
Fence Problem Solution

Solve
 Draw rectangle
 Show sides to scale
 Place corner posts
 Place posts 4 meters apart
 Count posts
Look Back
 Can you solve it in a better way?
Problem

Mr. Qutb‐ud‐din is arranging a dinner party for his friends


in a large room. 22 people are invited. He has to borrow
square tables, that can seat 1 person on each side. He
wants to arrange tables in a rectangular shape so that
they look like 1 large table. What is the smallest number
of tables that he needs?
Dinner Party Problem Solution

Understand
 Squares tables, 1 person on each side
 Form a large rectangle
 22 people
 Putting them together will reduce the number of people on each
square table
Plan
 Drawing pictures of different arrangements may help
 Few possibilities: 1 single row, 2 rows perhaps
Dinner Party Problem Solution

Carry out the Plan


 Single row: 2 people at each, with 3 people at end tables
 Double Row: 1 person at each, with 2 people at corner tables
Dinner Party Problem Solution

Looking Back
 Single row configuration will be best, given the room is long
enough to hold it.
 What if the number of people is increased to 38?
Another Problem

I say a number between 1 and 70.


If the number is less than 30, you say “Too Young”,
otherwise say “Too Old”.
What happened there?!

Understand
 Too simple
Plan
 Too simple
Carry out the Plan
 Too simple
Looking Back
 Why too simple?
Human Intelligence

A very general mental capability that, among other


things, involves the ability to reason, plan, solve
problems, think abstractly, comprehend complex ideas,
learn quickly and learn from experience.

Can you understand this definition?


Why were you able to find answer for 38 people in
dinner party?
Machines

 Are machines intelligent?

O. Why ?
N
They need instructions
• Accurate
• In order
New Problem

Take the problem “ I say a number between 1 and 70. If the


number is less than 30, you say “Too Young”, otherwise say “Too
Old”. ” and provide a solution so that a machine could do the same
what you did.

 Understand, Plan, Solve, Look back.


Representing your solution

There are 2 ways to represent

 Pseudo code
 An English‐like representation of logical steps to solve a problem.

 Flowchart
 Pictorial representation of the same thing.
Pseudo Code

BEGIN
GET number
IF number less than 30 THEN
Say “Too Young”
ELSE
Say “Too Old”
ENDIF
END
Corrected Pseudo Code

BEGIN
GET number
IF number greater or equals 1 AND number less or equals 70 THEN
IF number less than 30 THEN
Say “Too Young”
ELSE
Say “Too Old”
ENDIF
ELSE
Say Invalid Input
ENDIF
END
Pseudo Code

 Pseudo Code can be generic or language specific

 Works as a planning tool

 Clarifies the algorithm flow of information

 Makes it easier to generate language syntax


Flow Chart

 Same as a pseudo code but graphical

 Easier to read and understand

 Specific symbols to represent different programming constructs


Flow Chart Symbols

 Flow charts are used in many domain, hence have numerous


symbols
 Some basic are:
Flow Chart Symbols
Flow Chart Example
Program design
START Convert START
STOP Centigrade to
Fahrenheit
PSEUDOCODE:
PROCESS inputCent
Display “Enter Centigrade: " centigrade

Input INPUT
centigrade
OUTPUT calcFah
fahrenheit = 1.8 * centigrade + 32= (1.8*centigrade) + 32
fahrenheit

Display “Centigrade to Fahrenheit = " fahrenheit


CONNECTOR
outputFah
fahrenheit
FLOW LINES

STOP
• Write pseudo code and draw a flowchart that
will read the two sides of a rectangle (length
and width) and display its area on screen after
calculation. [Area formula: A = L x W ]

You might also like