0% found this document useful (0 votes)
6 views

Chapter 1 Introduction to Computers and Programming

The document is an introductory lecture on computers and programming, presented by Mr. Waqar Ashiq, detailing the essential components of computer systems, programming languages, and the process of program development. It covers the roles of hardware and software, the structure of programming languages, and the steps involved in processing a program in C++. Additionally, it provides examples of C++ programming and the fundamental concepts of input, processing, and output.

Uploaded by

iqraghouri440
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Chapter 1 Introduction to Computers and Programming

The document is an introductory lecture on computers and programming, presented by Mr. Waqar Ashiq, detailing the essential components of computer systems, programming languages, and the process of program development. It covers the roles of hardware and software, the structure of programming languages, and the steps involved in processing a program in C++. Additionally, it provides examples of C++ programming and the fundamental concepts of input, processing, and output.

Uploaded by

iqraghouri440
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 57

Introduction to Computers and

Programming

Lecture 01 –

Instructor: Mr. Waqar Ashiq


Introduction to Instructor
and Course
Mr. Waqar Ashiq – About Me

Lecturer Software Engineering


University of Management and Technology (UMT), (Nov 2022 – Conti)

Lecturer Computer Science


University of Lahore (UOL), (Sep 2021 – Nov 2022)

Lecturer Computer Science


COMSATS University Islamabad (CUI), (Feb 2021 – Aug 2021)

MS / M.Phil. Computer Sciences


COMSATS University Islamabad (CUI),(Feb 2019 – Jan 2021)

BS Computer Sciences
COMSATS University Islamabad (CUI), (Sep 2014 – July 2018)
Chapter 1:
Introduction
to
Computers
and
Programming
1.1
Why Program?
Why Program?
Computer – programmable machine designed
to follow instructions
Program – instructions in computer memory to
make it do something
Programmer – person who writes instructions
(programs) to make computer perform a task

SO, without programmers, no programs;


without programs, a computer cannot do
anything
1.2
Elements of a Computer System
Elements of a Computer System
1. Hardware
Central Processing Unit (CPU)
Main Memory
Secondary Storage
Input/ Output Devices
2. Software

8
Central Processing Unit (CPU)
The main components of the CPU are:
1. Control unit (CU)
2. Arithmetic and logic unit (ALU).
3. Registers.

9
Central Processing Unit (CPU)

1. CU (Control Unit):
Fetches and decodes instructions

Controls flow of information in and out of MM

Controls operation of internal CPU components

2. ALU (arithmetic logic unit): carries out all arithmetic


and logical operations

10
Central Processing Unit (CPU)

3. Registers.

1. PC (program counter): points to next


instruction to be executed

2. IR (instruction register): holds instruction


currently being executed

11
Main Memory
Directly connected to the CPU

All programs must be loaded into main


memory before they can be executed

All data must be brought into main


memory before it can be manipulated

When computer power is turned off,


everything in main memory is lost
13
Secondary Storage
Secondary storage: Device that stores
information permanently
Examples of secondary storage:
Hard disks
Floppy disks
Zip disks
CD-ROMs
Tapes
Flash drives 15
Input/output Devices
Input devices feed data and programs
into computers. They include:
Keyboard
Mouse
Secondary storage
Output devices display results. They
include:
Monitor
Printer
Secondary storage
16
Software
Software: Programs that do specific tasks
1. System programs take control of the
computer, such as an operating system
Operating System monitors the overall activity
of the computer and provides services.
2. Application programs perform a specific
task
Word processors
Spreadsheets
Games
17
1.3
Programs and Programming
Languages
Programs and Programming
Languages
A program is a set of instructions that the
computer follows to perform a task

We start with an algorithm, which is a set


of well-defined steps.
Example Algorithm for Calculating
Gross Pay
Machine Language
Although the previous algorithm defines
the steps for calculating the gross pay, it is
not ready to be executed on the computer.
The computer only executes machine
language instructions
Programming Languages
• Programming languages allow programmers to code
software.

• The three major families of languages are:


Machine languages
Assembly languages
High-Level languages
Machine Language
Machine language instructions are binary
numbers, such as

1011010000000101

Rather than writing programs in machine


language, programmers use programming
languages.
Computer Languages
Machine language
Generally consist of strings of numbers - Ultimately 0s and 1s -
Machine-dependent
Example: +1300042774
+1400593419
Assembly language
English-like abbreviations for elementary operations
Incomprehensible to computers - Convert to machine language
Example: LOAD BASEPAY
ADD OVERPAY
STORE GROSSPAY
High-level languages
Similar to everyday English, use common mathematical notations
Compiler/Interpreter
Example:
grossPay = basePay + overTimePay 24
Programs and Programming
Languages
Types of languages:

Low-level: used for


communication with computer
hardware directly. Often written
in binary machine code (0’s/1’s)
directly.

High-level: closer to human


language
Some Well-Known Programming
Languages

C++
BASIC Ruby
FORTRAN
Java
Visual Basic
COBOL
C#
JavaScript
C Python
1.1
Processing a Program
Processing a Program
The following steps are necessary
to process a program in C++:

Step 1: Use text editor to


create a C++ program. This
program is called source code
or source program.
Processing a Program
Step 2: In a C++ program,
statements that begin with
the symbol # are called
preprocessor directives. These
statements are processed by a
program called preprocessor.
Processing a Program
Step 3: Compiler is used to:
1. verifies that the program
obeys the rules of the
programming language and
checks the source program
for syntax errors.
2. Translate the program into
equivalent machine
language (object program).
Processing a Program
Step 4: Programs in high level
languages are developed using
a software development kit
(SDK).
• SDK contains programs that
are useful in creating your
program such as mathematical
functions.
• The prewritten code resides
in a library.
• Linker combines the object
code with the program from
libraries.
Processing a Program
Step 5: You must load the
executable program into main
memory for execution.

Loader: a program that loads


an executable program into
main memory.
Processing a Program
Step 6: The final step is to
execute the program.
Integrated Development
Environments (IDEs)
An integrated development environment,
or IDE, combine all the tools needed to
write, compile, and debug a program into a
single software application.
Examples are Microsoft Visual C++, Turbo
C++ Explorer, CodeWarrior, etc.
Integrated Development
Environments (IDEs)
2.
What is a Program Made of?
What is a Program Made of?
Common elements in programming
languages:
Key Words
Programmer-Defined Identifiers
Operators
Punctuation
Syntax
Program 1-1
Key Words
Also known as reserved words
Have a special meaning in C++
Can not be used for any other purpose
Key words in the Program 1-1: using,
namespace, int, double, and return
Key Words
Programmer-Defined Identifiers
Names made up by the programmer
Not part of the C++ language
Used to represent various things: variables
(memory locations), functions, etc.
In Program 1-1: hours, rate, and pay.
Operators
Used to perform operations on data
Many types of operators:
Arithmetic - ex: +,-,*,/
Assignment – ex: =

Some operators in Program1-1:


<< >> = *
• Stream insertion ( << ) operator
• extraction operator ( >> )
Operators
Punctuation
Characters that mark the end of a
statement, or that separate items in a list
In Program 1-1: , and ;
Punctuation
Syntax
The rules of grammar that must be
followed when writing a program
Controls the use of key words, operators,
programmer-defined symbols, and
punctuation
Variables
A variable is a named storage location in
the computer’s memory for holding a piece
of data.
In Program 1-1 we used three variables:
The hours variable was used to hold the
hours worked
The rate variable was used to hold the pay
rate
The pay variable was used to hold the gross
pay
Variable Definitions
To create a variable in a program you
must write a variable definition (also called
a variable declaration)

Here is the statement from Program 1-1


that defines the variables:

double hours, rate, pay;


Variable Definitions
There are many different types of data,
which you will learn about in this course.

A variable holds a specific type of data.

The variable definition specifies the type of


data a variable can hold, and the variable
name.
Variable Definitions
Once again, line 7 from Program 1-1:

double hours, rate, pay;

The word double specifies that the


variables can hold double-precision
floating point numbers. (You will learn
more about that in Chapter 2)
3.
Input, Processing, and Output
Input, Processing, and Output
Three steps that a program typically
performs:
1) Gather input data:
from keyboard
from files on disk drives
2) Process the input data
3) Display the results as output:
send it to the screen
write to a file
A C++ Program
#include <iostream>
using namespace std;
int main()
{
cout << "My first C++ program." << endl;
cout << "The sum of 2 and 3 = " << 5 << endl;
cout << "7 + 8 = " << 7 + 8 << endl;
return 0;
}

Sample Run:
My first C++ program.
The sum of 2 and 3 = 5
7 + 8 = 15

C++ Programming: From Problem Analysis to Program Design, Third Edition 53


A C++ Program
cout << "My first C++ program." << endl;

This is a C++ output statement.


It causes the computer to endl causes the insertion point
evaluate the expression after the pair to move to the beginning of the
of symbols << and next line.
display the result in the screen.

C++ contain various types of


Expressions such as arithmetic and
strings. For example: 7+8 is arithmetic
expression. Anything in double quotes
is a string “7+8” is a string

54
A C++ Program
cout << "My first C++ program." << endl;

Sample Run:
My first C++ program.

C++ Programming: From Problem Analysis to Program Design, Third Edition 55


A C++ Program
cout << "The sum of 2 and 3 = " << 5 << endl;

The first expression The second expression consists of


“The sum f 2 and 3 = “ is Number 5 and evaluates to itself.
a string and evaluates to
itself .

Sample Run:
The sum of 2 and 3 = 5

C++ Programming: From Problem Analysis to Program Design, Third Edition 56


A C++ Program
cout << "7 + 8 = " << 7 + 8 << endl;

The first expression


“7 + 8 = “ is a string and The second expression consists of
evaluates to itself. number 7 and 8, and the C++ arithmetic
operator +. Therefore the result of the
expression is the sum of 7 and 8 which
Sample Run: is 15.
7 + 8 = 15

C++ Programming: From Problem Analysis to Program Design, Third Edition 57

You might also like