Lec 1-1
Lec 1-1
Lecture 1 – Introduction
ENGR. Muhammad Talha Jahangir,
MS(Computer Engineering) NUST, Pakistan
[email protected]
Understand the given problem and provide the solution in the form of
program
Chapter 1: Introduction
1.1 Introduction
1.2 Computers: Hardware and Software
1.3 Von Neumann Architecture
1.4 Computer Organization
1.5 What is Programming, Skills for programming & its Importance
1.6 Programming Skill Techniques
1.7 Program development process
1.8 Types of Programming Language
1.9 Use of Different programming Language
1.10 Characteristics of High level Language
1.11 Structure & Unstructured Programming Language
1.12 Different Programming Styles
1.13 Getting Starting with C Programming
1.14 History of C
1.15 IDE & Compiler
1.16 Debugging & Program Errors
1.17 Visual Studio Code & MinGW-w64
1.18 Difference between source code and object code
1.19 Steps to prepare C program for execution
1.20 Pons and Cons of C
1.21 Applications of C Programming
Introduction
As this course is titled “Introduction to programming”,
therefore it is most essential and appropriate to understand
what programming really means.
When we say that we have a program, it actually mean that we
know about a complete set activities to be performed in a
particular order. The purpose of these activities is to solve a
given problem.
Practically, in our day to day lives we are constantly planning,
organizing and paying attention to fine details (if we want our
plans to succeed). And it is also fun to do these activities.
For example, for a picnic trip we plan where to go, what to
wear, what to take for lunch, organize travel details and have a
good time while doing so.
We also think logically such as, after picnic if we will not tired
than we will go some other place for more enjoy.
Computers: Hardware and Software
A computer is a versatile electronic device that can perform
computations and make logical decisions billions of times
faster than human beings can.
Computer is Fast but it is dumb it cannot do any task our
instruction.
Computers process data under the control of sets of
instructions called computer programs.
These programs guide the computer through orderly sets
of actions specified by people called computer
programmers.
A computer consists of various devices referred to as
hardware (e.g., the keyboard, screen, mouse, hard disk,
memory, DVDs and processing units).
The programs that run on a computer are referred to as
software.
Von Neumann Architecture
The Von Neumann architecture, also known as the Princeton
architecture, is a computer architecture based on that described
in 1945 by the mathematician and physicist John Von
Neumann.
He described an architecture for an electronic digital computer
with parts consisting of a processing unit containing an
arithmetic logic unit (ALU) and processor registers, a control
unit containing an instruction register and program counter
(PC), a memory to store both data and instructions, external
mass storage, and input and output mechanisms.
Von Neumann architecture is composed of three distinct
components (or sub-systems): a central processing unit
(CPU), memory, and input/output (I/O) interfaces.
Von Neumann Architecture Diagram
Computer Organization
Even now modren Computer Organization based on Von
Neumann Architecture.
Every computer may be envisioned as divided into six
logical units or sections:
1. Input Unit
2. Output Unit
3. Memory Unit
4. Arithmetic and Logical Unit
5. Central Processing Unit
6. Secondary Storage Unit
Computer Organization Explanation
1. Input Unit: An input device or unit(read information) sends
information to a computer system for processing. It is the
input unit for processor. Humans typically enter information
into computers through keyboards and mouse devices.
Information also can be entered in many other ways, including
by speaking to your computer, scanning images and barcodes,
reading from secondary storage devices (like hard drives, CD
drives, DVD drives and USB drives—also called “thumb
drives”).
2. Output Unit: As we know, an input device or unit sends
information to a computer system for processing. while
output device(write information) or unit reproduces or
displays the results of that processing. Most information that is
output from computers today is displayed on screens, printed
on paper, played on audio players (such as Apple’s popular
iPods), or used to control other devices. Computers also can
output their information to networks, such as the Internet.
Computer Organization Explanation
3. Memory Unit: The computer memory is a temporary storage
area. It holds the data and instructions that the Central
Processing Unit (CPU) needs. The memory unit also retains
processed information until it can be placed on output devices
by the output unit.
Information in the memory unit is volatile—it’s typically lost
when the computer’s power is turned off.
The memory unit is often called either memory or primary
memory.
4. Arithmetic and logic unit (ALU): This “manufacturing”
section performs calculations, such as addition, subtraction,
multiplication and division.
It also contains the decision mechanisms (Logical Unit) that
allow the computer, for example, to compare two items from
the memory unit to determine whether they’re equal.
In today’s systems, the ALU is usually implemented as part of
the next logical unit, the CPU.
Computer Organization Explanation
5. Central processing unit (CPU): CPU (pronounced as separate letters) is the
abbreviation for central processing unit. Sometimes referred to simply as the central
processor, but more commonly called a processor, the CPU is the brains of the computer
where most calculations take place.
The CPU tells the input unit when to read information into the memory unit, tells the ALU
when information from the memory unit should be used in calculations and tells the output
unit when to send information from the memory unit to certain output devices.
Many of today’s computers have multiple CPUs and, hence, can perform many operations
simultaneously—such computers are called multiprocessors.
A multi-core processor implements multiprocessing on a single integrated circuit chip—for
example a dual-core processor has two CPUs and a quad-core processor has four CPUs.
6. Secondary storage unit: Programs or data not actively being used by the other
units normally are placed on secondary storage devices (e.g., your hard drive) until they’re
again needed, possibly hours, days, months or even years later.
Therefore, information on secondary storage devices is said to be persistent—it is
preserved even when the computer’s power is turned off.
Secondary storage information takes much longer to access than information in primary
memory, but the cost per unit of secondary storage is much less than that of primary
memory.
Examples of secondary storage devices include CDs, DVDs and flash drives (sometimes
called memory sticks), which can hold hundreds of millions to billions of characters.
Programming
Programming is the process of creating a set of instructions that tell a
computer how to perform a task. Programming can be done using a variety of
computer "languages," such as SQL, Java, Python, and C++.
"A program is a precise sequence of steps to solve a particular problem.”
Programming is an art of creativity.
The only source to become a programmer is practice because programming
learn from doing rather than just knowing conceptual knowledge.
By designing programs, we learn many skills that are important for all
professions.
These skills can be summarized as:
o Critical reading (Critical reading involves: carefully considering and
evaluating the reading. identifying the reading's strengths and implications.
identifying
the reading's weaknesses and flaws.(Attention to details))
o Analytical thinking (It involves a methodical step-by-step approach
to thinking that allows you to break down complex problems into single and
manageable components.)
o Creative synthesis (synthesis mean a combination of tow or more entities
that together form something new. Creative synthesis the combination of
several
ideas, images, or associations into a new way which is more clear and able easy
to
7 STEPS TO IMPROVE YOUR ANALYTICAL THINKING
SKILLS
1. Be Observant: Take a walk outside or observe people in your office. Use as many of
your senses, see what’s happening around you. Is there anything that interests you?
2. Read Books: Once again, the key to improving your analytical thinking skill is to
keep your mind active and running.
3. Learn How Things Work: Don’t just find the solution but know how exactly certain
things work.
4. Ask Questions: The more curious we are about a subject, the more it engages our
cognitive functions, such as attention and memory.” With that said, asking more
questions can help develop better problem-solving skills, retention, and memory of a
subject. So don’t be shy to ask questions, especially if your query is valid.
5. Play Brain Games: If you want to improve your analytical thinking skills, it may be
time to play Sudoku or other brain games like puzzles, chess, or crosswords. It helps
to make your brain creative and thinkable.
6. Practice Your Problem Solving Skills: Keep in mind that for every problem, there is
a solution. Visualize and be articulate in the presentation of a particular concept.
Prepare two, three or even more solutions to a problem. And, if possible, do test runs
on those solutions. See which one is the best and the most logical.
7. Think About Your Decisions: Making important decisions at work is very common.
Thus, think hard and rationalize your decisions. What are the pros and cons of your
decision?
What Specifications are needed for program
Programming is an important activity as people life and
living depends on the programs one make.
Hence while programming one should:
1. Machine Independence
2. Can be implemented on a variety of machines
3. Problem Oriented Language
4. Easier to Understand
5. Well defined Syntax and standard
6. Easy to debug
Note: Each high level language has standard Syntax. The standard
is published by several international organizations. An important
organization that publishes the computer programming language
standard is ANSI (American National Standard Institute). The
compilers are written according to the standard syntax of the
language.
Structure & Unstructured Programming Language
A programming language in which entire program is written as a
single continuous block is called unstructured programming
language.
Program written in an unstructured language is very difficult to read
and debug.
Examples of unstructured programming language are JOSS,
FOCAL, MUMPS, TELCOMP, COBOL.
A programming language in which a program is written by dividing
it into smaller sections or module is called structure
programming language.
Each module of the program performs a specific function.
Program written in structure programming language are easy to
write and debug.
Examples of Structured programming language are C, C+, C++,
C#, Java, PERL, Ruby, PHP, ALGOL, Pascal, PL/I and Ada etc.
Explanation
Object-oriented programming: Object-Oriented
Programming is a methodology or paradigm to design a
program using classes and objects. Object means a real-
world entity such as a pen, chair, table, computer, watch,
etc. It simplifies software development and maintenance
by providing some concepts:
1. Object
2. Class
3. Abstraction
4. Encapsulation
5. Inheritance
6. Polymorphism
1. Syntax Error
2. Logical Error
3. Runtime Error
Types of errors in Program
The rule for writing statements in a computer programming language is
called syntax of the language.
Syntax Error: A single mistake in these rules causes an error. This error
is called the syntax error.
The Compiler detects syntax error. It doses not compile a program, that
contains a syntax error. Compiler generally specifies the location and type
of syntax error in a source program. These error are, therefore easy to
locate and remove.
Example of syntax error include:
1. a missing statement terminator;
2. a misspelled keyword, for example typing mane() instead of main().
Logical error: The errors in the logic of a program is called logical error.
The compiler cannot detect these error. Debugger is used to remove
logical errors. A program runs with logical error on the computer but
produce wrong results.
The logical error may occur due to the following reason:
1. Data input is incorrect because the output of the program depend
upon its input data.
2. The sequence of operations in a program may be incorrect.
3. A mathematical formula in a program may be incorrect.
Types of errors in Program
Runtime error: are the error because they are occur
during the execution of a program.
Runtime error occur when a program tries to:
1. divided by zero
2. call a function that do not exist.
The computer stops executing the program when a runtime
error occurs and display the nature of the runtime error.
Difference between Source code and object code
A computer program written in a high level
language is called the source program. It is also
called source code.
Computer does not understand the source program.
Source program cannot run directly on the
computers.
A computer program in a machine language is
called the object program. It is also called object
code.
Compiler task to convert source code into object
code.
Steps to prepare C program for execution
Linker Disk
Linker links the object code with the
libraries. Linker is used to make
Primary Memory executable file because program need
executable file
Loader
CPU
CPU takes each
instruction and executes it, possibly
storing new data values as the program
..
..
..
executes.
Some Facts About C Programming
In 1988, the American National Standards Institute
(ANSI) had formalized the C language.
C was invented to write UNIX operating system.
C is a successor of 'Basic Combined Programming
Language' (BCPL) called B language.
Linux OS, PHP, and MySQL are written in C.
C has been written in assembly language.
Still, the best programming language to learn
quickly.
Pros and Cons C
Advantages of C
C is the building block for many other programming languages.
Programs written in C are highly portable.
Several standard functions are there (like in-built) that can be used to
develop programs.
C programs are collections of C library functions, and it's also easy to
add functions to the C library.
The modular structure makes code debugging, maintenance, and
testing easier.
C is a fast language.
Pros and Cons C
Disadvantages of C
C does not provide Object Oriented Programming (OOP)
concepts.
There are no concepts of Namespace in C.
C does not provide binding or wrapping up of data in a
single unit.
C does not provide Constructor and Destructor.
Operating Systems
Language Compilers
Assemblers
Text Editors
Print Spoolers
Network Drivers
Modern Programs
Databases
Language Interpreters
Utilities