Fundamentals of Programming: Lecture No. 1
Fundamentals of Programming: Lecture No. 1
Programming
Lecture No. 1
1
Course Objectives
Objectives of this course are three fold
1. To appreciate the need for a programming
language
2. To introduce the concept and usability of
the structured programming methodology
3. To develop a useful program for the
processes that are used in computers
2
Course Contents
To achieve our first two objectives we
will be discussing
• Basic Programming constructs and
building blocks
• Structured programming
• OOP concepts
3
Course Contents
• Introduction to C++
• Variables and expressions
• Control structures
–Decision Making
–Looping
• User Defined Functions
4
Course
• Arrays and Pointers
Contents
• Dynamic memory Allocation
• File handling
• Structures and Unions
• Object oriented programming Concepts
5
Resources
• Books:
– C++ How to Program by Deitel & Deitel
– Let Us C++ by Yashavant Kanetkar
6
Course Policy
Policy for the distribution of marks and
examination is as follows
• Assignments/Quiz 20%
• Midterm 30 %
• Final 50 %
7
Definition
“A computer is a device capable of performing computation and making logical
decisions at speeds millions (even billions) of times faster than a human being can.”
• Example:
Many of today's personal computers can perform a billion additions per
second.
Human vs Computer:
o Speed is the obvious difference but
o How would you know whether the person added the numbers correctly?
o How would you know whether the computer added the numbers correctly?
• Today's fastest supercomputers can perform trillions of additions per second!
8
Components of Computer
There are basically two components of the computer
1. Hardware
The parts of computer that we can touch. In other words
hardware constitute the physical parts like keyboard,
mouse, hard desk, memory, processing units etc. In our
course we will not go into much details about hardware.
2. Software
Software on the other hand is of much interest to our
course. Lets discuss this component in a little detail
9
1. Software
It interacts and controls the functionality of the hardware. It has further
been divided into two parts
► Our focus:
1. How to write programs (correct semantically & syntactically)?
2. How to write efficient programs
10
Computer Programming and Programming
Language
2. Assembly Language
Machine Language:
– Machine can only understand “Machine Language".
12
Drawback of Machine language
1. Slow development time (time consuming)
2. Tedious (making the programmer’s life hard)
3. Error prone (difficult to remember all the code)
Assembly language
► It uses English like abbreviations for codes making programmer’s life
easy
13
High level languages
►High level language instructions look like every day English and
contains commonly used mathematical notations
14
What is a Program?
15
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
16
Where to write program?
17
First Program in C++
1. #include <iostream>
3. void main()
4. {
5. cout<<"In the name of Allah"<<endl;
6. cout<<"This is my first Program in C++...";
7. cin.get();
8. }
18
Visual C++ IDE
19
Program in Execution (Output)
20
Explain the Program
(line by line)
#include <iostream>
21
Explain the Program
(line by line)
using namespace std
22
Explain the Program
(line by line)
void main()
23
Explain the Program
(line by line)
• { is used to start the main function and } is
used to end the main function. Actually it
define a block of code.
• Its mean that execution started in just below
the { and will remain alive when it it get the }
– But: A program has many blocks
24
Program with many blocks
#include <iostream>
using namespace std;
void main()
{
int F;
cout<<“Enter value for F”; cin>>F;
if(F<0)
{
cout<<“F must be positive”;
exit(0);
}
cin.get();
}
25
Explain the Program
(line by line)
cout<<"In the name of Allah"<<endl;
26
Explain the Program
(line by line)
• cin.get() stops the execution of the program
until the user press the ENTER button from
keyboard.
27
What does Semi-Colon(;) do?
• If you have noticed that there is a semi-
colon(;) at the end some of lines.
28
What does Semi-Colon(;) do?
• You can write multiple statement in a single line:
cout<<“CIIT”;
cin.get();
=
cout<<“CIIT”; cin.get();
29
Summary
• Course Introduction
• Programming Language
• What is a Program?
• Writing a simple Program and Line-by-Line
Explanation
30