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

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

Dec 25, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CS102 Introduction to Computer Programming Week 1 Introduction and Chapter 1.

CS102Introduction to

Computer ProgrammingWeek 1

Introduction and Chapter 1

Page 2: CS102 Introduction to Computer Programming Week 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

Page 3: CS102 Introduction to Computer Programming Week 1 Introduction and Chapter 1.

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.

Page 4: CS102 Introduction to Computer Programming Week 1 Introduction and Chapter 1.

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.

Page 5: CS102 Introduction to Computer Programming Week 1 Introduction and Chapter 1.

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.

Page 6: CS102 Introduction to Computer Programming Week 1 Introduction and Chapter 1.

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

Page 7: CS102 Introduction to Computer Programming Week 1 Introduction and Chapter 1.

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

Page 8: CS102 Introduction to Computer Programming Week 1 Introduction and Chapter 1.

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

Page 9: CS102 Introduction to Computer Programming Week 1 Introduction and Chapter 1.

• 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

Page 10: CS102 Introduction to Computer Programming Week 1 Introduction and Chapter 1.

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

Page 11: CS102 Introduction to Computer Programming Week 1 Introduction and Chapter 1.

Output Devices

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

• Consider the complexity of multimedia output.

– Disk Drives– Modems– Servers

Page 12: CS102 Introduction to Computer Programming Week 1 Introduction and Chapter 1.

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

Page 13: CS102 Introduction to Computer Programming Week 1 Introduction and Chapter 1.

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

Page 14: CS102 Introduction to Computer Programming Week 1 Introduction and Chapter 1.

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.

Page 15: CS102 Introduction to Computer Programming Week 1 Introduction and Chapter 1.

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.

Page 16: CS102 Introduction to Computer Programming Week 1 Introduction and Chapter 1.

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

Page 17: CS102 Introduction to Computer Programming Week 1 Introduction and Chapter 1.

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.

Page 18: CS102 Introduction to Computer Programming Week 1 Introduction and Chapter 1.

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.

Page 19: CS102 Introduction to Computer Programming Week 1 Introduction and Chapter 1.

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.

Page 20: CS102 Introduction to Computer Programming Week 1 Introduction and Chapter 1.

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.

Page 21: CS102 Introduction to Computer Programming Week 1 Introduction and Chapter 1.

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.

Page 22: CS102 Introduction to Computer Programming Week 1 Introduction and Chapter 1.

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.

Page 23: CS102 Introduction to Computer Programming Week 1 Introduction and Chapter 1.

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

Page 24: CS102 Introduction to Computer Programming Week 1 Introduction and Chapter 1.

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