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

Lec1 - Introduction To Computers, Programs, and C++

This document provides an introduction to computers, programming languages, and the C++ programming language. It discusses what computers and programs are, as well as low-level and high-level programming languages. It also covers the basic hardware components of a computer and introduces a simple C++ program development cycle.

Uploaded by

wasifnaseer255
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Lec1 - Introduction To Computers, Programs, and C++

This document provides an introduction to computers, programming languages, and the C++ programming language. It discusses what computers and programs are, as well as low-level and high-level programming languages. It also covers the basic hardware components of a computer and introduces a simple C++ program development cycle.

Uploaded by

wasifnaseer255
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 26

Fundamentals of Programming

Introduction to Computers, Programs, and C++


Computers and Computer Languages
• Computers are everywhere
• how many computers do you own?
• Computers are useful because they run programs
• program is simply a set of instructions to complete some task
• how many different programs do you use in a day?

Fundamentals of Programming – 1 2
Definitions
• program: A set of instructions that are to be carried
out by a computer.

• program execution: The act of carrying out the


instructions contained in a program.
• this is done by feeding the instructions to the CPU

• programming language: A systematic set of rules


used to describe computations, generally in a
format that is readable and editable by humans.
• in this class we use Java

Fundamentals of Programming – 1 3
High Level Languages
• Computers are fast
• Intel® Core™ i7-8086K Processor on
the order of 2 billion transistors
(a switch that is on or off)
• performs tens of billions of operations
per second
• Computers are simple
• They can only carry out a very limited set of
instructions
• on the order of 100 or so depending on
the computer's processor
• machine language instructions, aka
instruction set architecture (ISA)
• Add, Branch, Jump, Get Data, Get
Instruction, Store, (CS429)

Fundamentals of Programming – 1 4
Machine Code

• John von Neumann - co-author of paper in 1946 with Arthur


W. Burks and Hermann H. Goldstine,
• "Preliminary Discussion of the Logical Design of an Electronic
Computing Instrument"
• One of the key points
• program commands and data stored as sequences of bits in the
computer's memory
• A program: 1110001100000000
0101011011100000
0110100001000000
0000100000001000
0001011011000100
0001001001100001
0110100001000000
0000111000000011

Fundamentals of Programming – 1 5
Say What?

• Programming with Strings of bits (1s or 0s) is not the easiest


thing to do.
• Assembly language
• mnemonics for machine language instructions
.ORIG x3001
LD R1, x3100
AND R3, R3 #0
LD R4, R1

BRn x3008
ADD R3, R3, R4
ADD R1, R1, #1
LD R4, R1
BRnzp x3003
Fundamentals of Programming – 1 6
High Level Languages

• Assembly language, still not so easy, and lots of commands to


accomplish things
• High Level Computer Languages provide the ability to accomplish a lot
with fewer commands than machine or assembly language in a way
that is hopefully easier to understand

int sum = 0;
int count = 0;
while (list[count] != -1) {
sum += list[count];
count = count + 1;
}

Fundamentals of Programming – 1 7
Computer
• What is?
‒ A computer is an electronic device that stores and processes data

• Computer Consists of
‒ Hardware
‒ Software

Fundamentals of Programming – 1 8
Hardware Components
• Central processing unit
• Memory
• Storage devices
• Input devices
• Output devices
• Communication devices

Fundamentals of Programming – 1 9
Central Processing Unit
• Retrieves instructions from memory and executes them
• Two components
‒ Control unit
‒ Arithmetic / Logic unit
• Built from millions of transistors
• Internal Clock
‒ Used to control and synchronize the pace of operations
‒ Clock Speed Unit (hertz)
• Number of Cores

Fundamentals of Programming – 1 10
Central Processing Unit

Fundamentals of Programming – 1 11
Storage Devices
• RAM is volatile
‒ Data is lost when power is off
• Permanent storage elements?
‒ Hard disk
‒ CD / DVD
‒ Flash drive
• Programs and Data are store in permanent storage
‒ Moved to memory for processing

Fundamentals of Programming – 1 12
An Important Realization
• Computers are stupid.

• Computers can’t read minds.

• Computers seldom make mistakes.

• If the computer is not doing what we want, it’s because WE


made a mistake.
• Users are not always very intelligent

Fundamentals of Programming – 1 1
A Simple C++ Program
• Preprocess directives
are not statements
(no semi-colon ;)

• Extra space in < >

• Case Sensitive
‒ Main vs main

Fundamentals of Programming – 1 14
Listing 1.2

• Output?

Fundamentals of Programming – 1 15
Listing 1.3

• Output?

Fundamentals of Programming – 1 16
Output?

Fundamentals of Programming – 1 17
C++ Program
Development Cycle

Fundamentals of Programming – 1 18
Programming Style and Documentation
• Appropriate Comments
• Comment Styles
• Proper Indentation and Spacing

Fundamentals of Programming – 1 19
Errors?

Fundamentals of Programming – 1 20
Programming Errors
• Syntax Errors

• Runtime Errors

• Logic Errors

Fundamentals of Programming – 1 21
Programming Errors
• Syntax Errors

Fundamentals of Programming – 1 22
Programming Errors
• Syntax Errors

• Runtime Errors

Fundamentals of Programming – 1 23
Programming Errors
• Syntax Errors

• Runtime Errors

• Logic Errors

Fundamentals of Programming – 1 24
Common Errors

Missing Braces, Semicolons, Quotation Marks and Misspelling Names


Fundamentals of Programming – 1 25
Work…

Fundamentals of Programming – 1 26

You might also like