Computer Programming CSC 102: by Muhammad Raza Ur Rehman Khan
Computer Programming CSC 102: by Muhammad Raza Ur Rehman Khan
Lecture 1
By Muhammad Raza ur Rehman Khan
[email protected]
Course Information
• Pre Requisites
– CSC -101 Introduction to Computer Science
• Text Book
– C++ How to Program
• Dietel & Dietel
• 5th or 6th edition
• Reference book
– The C++ Programming Language, Third Edition
• Bjarne Stroustrup
• IDE : Visual Studio Express Edition
Course Information
• Course Web page http://
sites.google.com/site/csc102spring11/
• Instructor’s Email [email protected]
• Office Hours : 1 hour before and after the
lecture or by appointment or if I am not busy
• Lab Hours : {To be filled in }
• TA
– Murad [email protected]
– Murad’s Office hour
Course Methodology
• Lectures
• Labs
• Programming Assignments
• Quizzes
• Project
• Presentation
Grading Policy ( Tentative)
Curved/ Relative Grading
• Class Participation (10%)
• Final Exam (15 %)
• Project (10 %) – individual
• Presentation on some advanced topic -
individual (10 %)
• Quiz(s) (15 %)
• Labs + Programming Assignments (40 %)
Collaboration Policy
• Collaboration Policy
– No collaboration allowed on assignments etc
unless explicitly specified
– A straight ‘F‘ in the case of collaboration
• Any Question so far
Computer Programming
• Why study Programming?
– A very interesting field
– If mathematics is the mother of all sciences
then
Computer Science is the facilitator of all sciences
– Google became the number one company in
employees’ satisfaction and the number one
resource of Google are Computer Scientists
Interesting Applications of
Computer Programming
• Google – Search Engine
– Used in the
exploration of MARS
– Uses software
Programs for
automatic
movement
Interesting Applications of
Computer Programming
• Cancer Treatment
• Acuros software developed in
Los Alamos National Laboratory
helps in
– Precise modeling of patient’s
anatomy
– Precise focus and control of laser
beams
Interesting Applications of
Computer Programming
• Youtube – A Video Portal
• Co-developed by Chad Hurley,
Steve Chen and Jawed Karim
• The most visited site in 2008
• Acquired by Google in 2006 for
USD 1.65 Billions
Interesting Applications of
Computer Science
• Facebook
• Created by Mark Zuckerberg
at the age of 19 when he was
a student of Harvard
University
• Current market worth
according to some resources
is $ 25 billion
Computers & Programming
Languages
• What is the basic advantage of Computers?
– Efficient Problem Solving
• Can Computers understand Urdu or English?
– What can they understand?
• Machine language
• Problems with Machine Language?
– Human beings cannot easily interpret them
– They are difficult to trouble shoot
• Higher level languages
– Assembly, C, C++, Java, Python
– History of C++
Higher level languages
• Basic Working
High level
Problem Pseudo Test
language
Formulation Code
Code
Computer Programming Cycle
Example 0
• Problem Statement
– Print a hello world
• Problem Formulation
– Decide about which algo to use
– Simple in this case
– We should know how to display some thing on the
output ( on the console)
• Pseudo Code ( Informal description of the code)
– Simple in this case
• Code ?
Source Code Example 0
Computer Programming Cycle
Example 1
• Problem Statement
– Calculate the average salary of a group of 4 people
• It can be used in the calculation of Average and Std
Deviation
– Problem Formulation
• Simple in this case
• Sum = Salary1 + Salary 2+ Salary 3 +Salary4
• Average = Sum / 4
Computer Programming Cycle
Example 1
• PseudoCode ?
– Data
• Input
• Output
– Computations ( Change in input to produce output)
• Every computer program has some variables
that store the data
• Data can be related to entity described in the
program or entity not described in the program
• Data is stored in “variables” in prog. languages
Computer Programming Cycle
Example 1
• Programming Languages provide
– Facility to write your own computation units ( or
code blocks)
– Provides facilities to access hardware resources
like memory, display terminals
• Source Code ?
Computer Programming Cycle
Example 1
Computer Programming Cycle
Example 2
• Problem
– Calculate the average salary of 2 groups of 4
people each
• Problem Formulation
– Calculate Sum of salaries
• Sum = Salary1 + Salary 2 + Salary 3 + Salary4
– Calculate Average?
• Average=Sum/4
Computer Programming Cycle
Example 2
• Pseudo Code ( First version)
– Data Input
– Computation
– Data Output
– Source Code
Source Code
• On the board
Computer Programming Cycle
Example 2
• PseudoCode ( Second version)
– Data input
– Computation(in reusable components called
functions)
– Result output
– Source Code?
Computer Programming Cycle
Example 2
• Pseudo Code ( Third version)
– Data Input
– Computation
– Data Output
– Source Code?
Example 2 v 3 Source Code
Computer Programming Cycle
Example 3
• Problem
– Calculate the average salary of 2 groups of 4 people
each but Print an error message if the salary entered
by the user is less than zero
• Problem Formulation
– Calculate Sum of salaries
• Sum = Salary1 + Salary 2 + Salary 3 +Salary4
• Check that each of the salaries should not be less than zero
– Calculate Average?
• Average=Sum/4
Computer Programming Cycle
Example 3
• Pseudo Code
– Data Input
– Computation
– Data Output
– Source Code
Source Code
Compilation and Linking
Library Object
Executable Linker code
Program
Modern
Compiler Suites
Compilers as Software
• Compilation + Linking
1) Compilation : conversion of your own code into
object code ( object code and machine code are
the same)
2) Linking : Linking the library object code into 1 to
form the executable
Data Types
• Purpose of variables?
– Storage of Information
• Different types of information that we may
have to store ?
– Integer Data, Floating point Data, Character (s),
true/false
– Collection of these
• Different representation of these data types
with in computer
• Different storage with in computers
Data Types
• What is declaration?
• General Syntax of data type Declarations in C++
• <optional specifier> <type> <name> <optional
initialization> ;
– Example of declaration of int, float, double, char,
string in coming slides
Example 1
• Caesar Cipher
– Shift every letter by some fixed place say 3
• Development Cycle
– Problem Formulation
– Pseudo Code
– Actual Source code
Example 1 Source Code
Comments on Example 1
• Difference between ‘0’ and 0
• Declaration of different types
• Remember that we can have an optional
initialization for every variable
• If the optional initialization is not there than
the object is initialized to the 0 value of the
corresponding type ( but don’t rely on it)
– 0 for integer , 0.0 for float
• namespace
Names of variables
• Keywords cannot be used as integer names
• Variable names should
– Start with letter (s)
– They can contain digits except for the first letter
– They can have underscore (only)
– Good naming convention
Example 2
• Problem Statement
– Write a program that takes in first and second
names of a person and concatenates them
• Problem Formulation
– We have to find the way of concatenating two
strings
• Pseudo Code
– simple
Example2 Source Code
Integers vs Strings
• Strings
• Integer
• cin reads untill whitespaces
• Cin>>reads a number
• cout writes
• Cout << writes
• + concatenates
• + adds