100% found this document useful (1 vote)
163 views

Fundamentals of Programming: Lecture No. 1

The document outlines a fundamentals of programming course, including its objectives to introduce programming languages and structured programming methodology. It describes the course contents which cover basic programming constructs, control structures, object-oriented programming concepts, and resources. The grading policy splits marks between assignments, midterm, and final exam. An example first program in C++ prints text to the screen and uses semicolons, comments, and functions like main() and cout.

Uploaded by

Khizar Abdullah
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
163 views

Fundamentals of Programming: Lecture No. 1

The document outlines a fundamentals of programming course, including its objectives to introduce programming languages and structured programming methodology. It describes the course contents which cover basic programming constructs, control structures, object-oriented programming concepts, and resources. The grading policy splits marks between assignments, midterm, and final exam. An example first program in C++ prints text to the screen and uses semicolons, comments, and functions like main() and cout.

Uploaded by

Khizar Abdullah
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 30

Fundamentals of

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

• Slides, Materials from Internet etc.

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

a) System software: For example Operating systems, device drivers


b) Application software: MS word, internet explorer, Games etc.

► Our focus:
1. How to write programs (correct semantically & syntactically)?
2. How to write efficient programs

10
Computer Programming and Programming
Language

• Writing a code in computer language


which run again and again to do a specific
task.

• The term computer language includes a


wide variety of languages used to
communicate with computers (i.e. C++,
Java)
11
Language hierarchy
Computer languages are basically emerged in three levels
1. Machine Language

2. Assembly Language

3. High Level Languages

Machine Language:
– Machine can only understand “Machine Language".

– Machine languages are always machine dependent

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

► These abbreviations led to the development of “Assembly Language”

► An interpreter program “Assembler” is used to convert the assembly


language code to machine language code.

13
High level languages

►Assembly language caused rapid increase in computer usage but


the development time was still slow compared to the usage

►To remedy this problem high level programming languages were


introduced

►High level language instructions look like every day English and
contains commonly used mathematical notations

►Compiler are used to convert the high level language programs


to machine language.

14
What is a Program?

“A precise sequence of steps to


solve a particular problem”

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?

• C++ is a compiler and compile your written


program for
– Checking Errors
– Ready to execute on computer
• User should be provided a Environment (IDE)
to write, compile and test the program
– i.e: Borland C++, Dev C++, Visual C++ etc

17
First Program in C++

1. #include <iostream>

2. using namespace std;

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>

• ‘#’ uses for preprocessor directive


• Here #include is used include the library
function defined in iostream file

21
Explain the Program
(line by line)
using namespace std

• Basically, what using namespace std does is to


inject all the names of entities that exist in
the std namespace into the global namespace
– i.e cout and endl

22
Explain the Program
(line by line)
void main()

• main() is the basic function telling the


computer to where the executed should be
started.
• void tells the computer that main() function
does not return any value.

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;

• cout<< is used for output a line


– It may be a STRING directly given or may a
variable.
• endl is used to end the line (as we used ENTER
button in MSWord)

26
Explain the Program
(line by line)
• cin.get() stops the execution of the program
until the user press the ENTER button from
keyboard.

• getch() may also be used which is used to


press any key.

27
What does Semi-Colon(;) do?
• If you have noticed that there is a semi-
colon(;) at the end some of lines.

• Remember it is a rule that every statement


must be end with a semi-colon.

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

You might also like