cs102 introduction to computer programming week 1 introduction and chapter 1

24
CS102 Introduction to Computer Programming Week 1 Introduction and Chapter 1

Upload: constance-chambers

Post on 25-Dec-2015

229 views

Category:

Documents


1 download

TRANSCRIPT

CS102Introduction to

Computer ProgrammingWeek 1

Introduction and Chapter 1

Chapter 1Intro to Programming and Program Design

• Why Program?

• Computer Systems : Hardware and Software

• Programs and Programming Languages

• What is a Program Made of?

• Input, Processing and Output

• The Programming Process

• Procedural and Object-Oriented Programming

Concept - Computers can do many different jobs because

they are programmable.

Concept - Computers can do many different jobs because they are programmable.

Why Program?

• Computers perform a wide variety of tasks.

• Computer programmers provide the software for computers.

• Software transforms a general purpose computer into a specialized tool.

Concept - A program is a set of instructions that a

computer follows in order to perform a task.

Concept - A program is a set of instructions that a computer follows in order to perform a task.

What is Programming?

• Computers are designed to execute a set of instructions.

• Programming is the act of creating a set of instructions for a computer to execute.

• A set of instructions that performs a specific task is called an algorithm.

What a programmer does

• A programmer creates the following things:– The logical flow of the instructions– The mathematical procedures– The appearance of the screens

• The way information is presented to the user

• The program's user friendliness

– Manuals and other forms of written documentation

Concept – Make a general purpose machine perform a specific task.

Concept – Make a general purpose machine perform a specific task.

Computer

Computer Systems : Hardware and Software

• Central Processing Unit• Main Memory• Secondary Storage• Input Devices• Output Devices• Software :

– loaded from a secondary storage device into main memory

InputDevice

MainMemory

CPUOutputDevice

SecondaryStorage

Central Processing Unit

The CPU consists of two parts

Concept - The CPU is the heart of the computer.Concept - The CPU is the heart of the computer.

Arithmetic & Logic UnitPerforms math operations

• Add

• Shift

• And

• Or

Control Unit Performs three functions

• Fetch

• Decode

• Execute

Main Memory

• Referred to as: – Random Access Memory (RAM)

• Static or dynamic

• Volatile

– Read Only Memory (ROM)• Non-volatile

• Holds the program during execution

• Divided into equal sections called cells– Each cell has a unique address

• Used to store programs and data for long periods of time:– Hard Drives – Floppy– Zip Drives

• Categorized by speed and capacity

Secondary Storage

– Digital Tape– CD ROMS– Flash Memory Cards

Input Devices

• Provide data to the CPU to be processed:– Keyboards– Touch sensitive screens– Secondary storage devices

• Provide information in a variety of formats:– Some conform to standards.– Some are application unique.

– Microphones– Cameras– Scanners

Output Devices

• Displays or stores data for the user:– Monitors– Printers– Speakers

• Consider the complexity of multimedia output.

– Disk Drives– Modems– Servers

Software

• The instructions that tell the computer and all of its devices what to do.– When and what data to get – What and how to manipulate the data– When and how to provide it to the user

Concept – Software connects the user to the machineConcept – Software connects the user to the machine

Concept - A program language is a special language used

to write computer instructions.

Concept - A program language is a special language used to write computer instructions.

Programming Languages

• Computers use machine language consisting of numbers only.

• Humans have difficulty communicating purely in numbers.

• A programming language provides a way for humans to communicate with a computer

Some Popular Programming Languages

BASIC Beginners All-purpose Symbolic Instruction Code. A general programming language originally designed to be simple enough for beginners to learn.

FORTRAN Formula Translator. A language designed for programming complex mathematical algorithms.

COBOL Common Business-Oriented Language. A language designed for business applications.

Pascal A structured, general purpose language designed primarily for teaching programming.

C A structured, general purpose language developed at Bell Labs. C offers both high-level and low-level features.

C++ Based on the C language, C++ offers object-oriented features not found in C. Also invented at Bell Laboratories.

Java An object-oriented language invented at Sun Microsystems. Java may be used to develop programs that run over the Internet, in a web browser.

The Importance of C++

• C++ is based on the C programming language.

• C++ is a midlevel language containing both high level and low level instructions.

• C++ is portable meaning that a C++ program can run a wide range of computers.

Concept - The popularity of C++ makes it an important language to learn.

Concept - The popularity of C++ makes it an important language to learn.

Code• Source Code

– Text written by the programmer.

• Modified Source code– Expanded text produced

by the Pre-processor.

• Object Code– Machine level code generated

by the compiler.

• Executable Code– Machine level code generated

by the linker.

Source Code

Pre-processor

Modified Source Code

Compiler

Object Code

Linker

Executable Code

What is a Program Made of?Language DescriptionElement

Key Words Words that have a special meaning. Key words may only be used for their intended purpose.

Programmer Words or names defined by the programmer. They areDefined symbolic names that refer to variables or programmingSymbols routines.

Operators Operators perform operations on one or more operands. An operand is usually a piece of data, like a number.

Punctuation Punctuation characters mark the beginning or ending of a statement, or separate items in a list.

Syntax Rules followed when constructing a program. Syntax dictates how key words and operators may be used, and where punctuation symbols must appear.

Concept - There are certain elements common to all computer programming languages.

Concept - There are certain elements common to all computer programming languages.

Lines and Statements

• A line is one single line of program text

• A statement is:– A complete instruction that causes the computer

to perform some action– May consist of more than one line

• A C++ statement must end in a semicolon (;)

Concept - Programs are made of a complete statements.Concept - Programs are made of a complete statements.

Variables

• Symbolic names that represent locations in the computer’s Random Access M

• Used to reference information that may change throughout the execution of a program

• The name of a variable should reflect the purpose of the data it references

Concept - A program stores information in variables.Concept - A program stores information in variables.

Variable Declarations

• Variables are either numbers or characters• A variable declaration statement informs the

compiler:– the name that will be assigned to the variable– how it should be stored in memory– it's initial value (optional)

• A variable definition statement causes a variable to be created in memory.

Concept - Variables must be defined before they are used.Concept - Variables must be defined before they are used.

Input, Process, and Output

• A program takes data as input, processes it and returns new data as output:– Input usually comes from some external source

but can be the output of another process.– Output is usually sent to an external device but

could be input to another process.

• A process determines the content of the output.

Concept - The three primary activities of a program are input, processing, and output.

Concept - The three primary activities of a program are input, processing, and output.

The Programming Process1. Clearly define what the program is

to do.

2. Visualize the program running on the computer.

3. Design a flow or Hierarchy chart.

4. Check the chart for logical errors.

5. Write a pseudocode version of the program.

6. Check the pseudocode for errors.

Concept - There are a number of steps involved in successfully creating a program.

Concept - There are a number of steps involved in successfully creating a program.

7. Write the actual program on paper.

8. Desk check the program for syntax or logical errors.

9. Enter the code and compile it.

10 . Correct any errors found during compilation.

11. Run the test data for input .

12. Correct any logical errors found while running the program.

What is Software Engineering?

Concept - Software engineering encompasses the whole process of crafting computer software.

Concept - Software engineering encompasses the whole process of crafting computer software.

Design Code Test

DebugMaintain

ModifyDocument

UsersNeeds

Analyze

Specify

Deliver

Procedural and Object-Oriented Programming

• Procedural programming organizes code into functional subroutines that perform specific types of tasks.

• Object oriented programming addresses the relationships between program features.

Concept - Procedural programming and object-oriented programming are two ways of thinking about software

development and program design

Concept - Procedural programming and object-oriented programming are two ways of thinking about software

development and program design