cs1102 lec06 – programming languages & program development

24
CS1102 Lec06 – Programming Languages & Program Development Semester B, 2012-13 Computer Science Department City University of Hong Kong

Upload: istas

Post on 25-Feb-2016

54 views

Category:

Documents


0 download

DESCRIPTION

CS1102 Lec06 – Programming Languages & Program Development. Semester B, 2012-13 Computer Science Department City University of Hong Kong. Objectives. Differentiate between machine and assembly languages Differentiate between markup languages and general-purpose programming languages - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: CS1102 Lec06 – Programming Languages & Program Development

CS1102 Lec06 – Programming Languages & Program Development

Semester B, 2012-13Computer Science Department

City University of Hong Kong

Page 2: CS1102 Lec06 – Programming Languages & Program Development

Objectives

Differentiate between machine and assembly languages

Differentiate between markup languages and general-purpose programming languages

Differentiate between scripting languages and general-purpose programming languages

Identify the steps in a typical program development cycle

Explain the basic control structures in structural design

Use the basic control structures (sequence, selection, repetition) to design solutions for simple problems

2 Jean Wang / CS1102 – Lec06

Page 3: CS1102 Lec06 – Programming Languages & Program Development

Programming Languages

Computer program – a series of instructions that that directs a computer to perform tasks The instructions that make up a computer program are sometimes referred to

as code

Programming language - a set of keywords and grammar rules for creating program code E.g., BASIC, C, C++, Pascal, FORTRAN, Java, COBOL Low-level languages typically include commands specific to a

particular CPU or microprocessor family High-level languages use command words and grammar more similar

to human languages

Programming - the process of writing/coding a program in a specific programming language to solve some problem

3 Jean Wang / CS1102 – Lec06

Page 4: CS1102 Lec06 – Programming Languages & Program Development

Program Code

Program code contains Keyword: a reserved word that carries a pre-defined meaning

E.g., var function if else for return Data types: data of a certain type

E.g, int float string Variables: a name refers to the memory space allocated to store a

value E.g., var i = 2; var h = “Hello!”; var f = 6.95;

Statements: one action that the CPU will take E.g., i = i + 1; f = Math.floor(6.95);

Program code needs to follow certain Syntax: grammar rules that dictate how code is written

4 Jean Wang / CS1102 – Lec06

Page 5: CS1102 Lec06 – Programming Languages & Program Development

Low-Level Programming Language

Machine language The first generation of

programming language The ONLY language CPU

directly recognizes Instructions, memory

addresses, numbers, characters and all other data are represented by 0s and 1s

Assembly language The second generation of

programming language Represent machine

instructions in symbolic form(usually are meaningful abbreviations)

Need an assembler to translate each assembly instruction into a corresponding machine instruction

5 Jean Wang / CS1102 – Lec06

Machine code Assembly code0 001 1 000010 LOAD #21 010 0 001101 STORE 132 001 1 000101 LOAD #53 010 0 001110 STORE 144 001 0 001101 LOAD 135 011 0 001110 ADD 146 010 0 001111 STORE 157 111 0 000000 HALT

Page 6: CS1102 Lec06 – Programming Languages & Program Development

High-Level Programming Language

Types of high-level programming languages Structural / procedural: the program is a collection of step-by-step

instructions Most widely used examples include: BASIC, COBOL, and C

Object-oriented: the program is a collection of objects which contain both data and instructions and the program is event-driven

Most widely used examples include: Visual Basic, C++, Java, C#

From high-level to low-level Compiler

translates a program from high-level language (source code) into low-level instructions (object code)

Interpreter translates program codes one-by-one for immediate execution

6 Jean Wang / CS1102 – Lec06

Page 7: CS1102 Lec06 – Programming Languages & Program Development

7

Scripting and Markup Languages

HTML - markup language composed of special tags that instruct the web browsers to format and display the Web page content

XML - method for putting structured data into a text file Extensible: developers can create their own meaningful tags Mostly used for data sharing across networks and different systems

Scripting language - a programming language that is used to manipulate, customize, and automate the operations of an existing system Not intended for writing applications from scratch; they are intended

primarily for plugging components Always embedded in the application with which they are associated E.g., client-side scripts (such as JavaScript) are executed by the browser

Most widely examples : JavaScript, Perl, PHP, Unix Shell Script

Jean Wang / CS1102 – Lec06

Page 8: CS1102 Lec06 – Programming Languages & Program Development

Software Development Cycle

Programming is a specialized form of problem solving by programmers or software engineers or software designers

A typical software development cycle looks like this:

8 Jean Wang / CS1102 – Lec06

Page 9: CS1102 Lec06 – Programming Languages & Program Development

Software Development Cycle

1. Program specification Meet with customers to review the requirements, identify input,

output, processing and data

2. Program design Devise the solution algorithm, i.e., a set of step-by-step procedures

for solving the problem Such as top-down design

Programmer may need to check the correctness of the logic and attempts to uncover logic errors (design flaw that causes inaccurate results)

Programmers may use test data to verify solution through logic

3. Program code Programmers write the code that translate the design into the actual

program9 Jean Wang / CS1102 – Lec06

Page 10: CS1102 Lec06 – Programming Languages & Program Development

Software Development Cycle

4. Program test By running the program with testing data, programmers ensure that

the program runs correctly and is error-free Debugging - locating and correcting the errors (also called bugs)

found in the programs Program errors include syntax error, logic error, runtime error

5. Program documentation Programmers write down the description, reference manual, and user

help files of the program

6. Program maintenance Completed programs are periodically reviewed to evaluate their

accuracy, efficiency, and east of use. Updates will be made to the program code when needed.

10 Jean Wang / CS1102 – Lec06

Page 11: CS1102 Lec06 – Programming Languages & Program Development

Step 1 – Analyze Requirements

A number-guessing game

11 Jean Wang / CS1102 – Lec06

An elementary-school teacher needs a program that is a number-guessing game so students can learn to develop logical strategies and practice their arithmetic. In this game, the computer picks a number between 1 and 100 and gives the player 7 turns to guess the number. After each incorrect try, the computer tells the player whether the guess is too high or too low.

Page 12: CS1102 Lec06 – Programming Languages & Program Development

Step2 - Design Solution Divide & Conquer approach to devise an algorithm (i.e., a step-by-step

procedure) Initially, the original problem is divided into several smaller parts Each of these parts represents a smaller programming problem to solve The next refinement fills in a few details for each part

1. Begin the game

2. Repeat guessing process until the number is guessed Or seven turns are completed

1.1 display instructions1.2 generate a number between 1 and 100

2.1 input guess from user2.2 respond to the guess2.3 if seven turns are used up, then end the game

2.2.1 if guess == number, then output “win” & end the game; else-if guess < number, then output guess-small-msg; else output guess-big-msg

12 Jean Wang / CS1102 – Lec06

Page 13: CS1102 Lec06 – Programming Languages & Program Development

Step 2 – Design Solution

Programmers may perform a Desk Check to verify the algorithm logic by using real test data to step through Test data: sample data that the program will process once it is in

production

Develop various sets of

test data

Determine the expected

result

Step through the algorithm

Compare the results

Repeat steps for each set of test data

13 Jean Wang / CS1102 – Lec06

Page 14: CS1102 Lec06 – Programming Languages & Program Development

Step 3 – Programming

Implementation or coding of the design includes using a program development tool that assists the programmer by: Generating or providing some or all code Writing the code that translates the design into a computer program Creating the user interface

14

A Notepad-like text editor allows programmers to enter lines of code

Or

an IDE (Integrated Development Environment) tool provides programmers with tools to build the program (interface + code)

14 Jean Wang / CS1102 – Lec06

Page 15: CS1102 Lec06 – Programming Languages & Program Development

Step 4 & 5 – Test and Documentation

The goal of program testing is to ensure the completed program runs correctly and is error free Errors include syntax errors, logic errors, runtime errors

Syntax error: occurs when the code violates the grammar requirements of the programming language

Logic error: a flaw in the algorithm design that causes inaccurate result Runtime error: an error that causes the program to stop running

Debugging the program involves removing the errors (bugs)

Documentation is the accompanying text either explains how the program operates or how to use it Important for people who may be involved with the program in the

future May include a user manual, all charts, solution algorithm, test data,

etc.15 Jean Wang / CS1102 – Lec06

Page 16: CS1102 Lec06 – Programming Languages & Program Development

16

Structural Design

Structural design - conceptualizes the solution as a sequence of steps

Any computer program can be built from these three control structures: Sequence

Tells computer to take actions in sequential order Selection

Tells computer which action to take, based on a certain condition Repetition

Tells computer to perform one or more actions repeatedly, until a certain condition is satisfied or dissatisfied

Jean Wang / CS1102 – Lec06

Page 17: CS1102 Lec06 – Programming Languages & Program Development

17

Flowchart

Flowchart - a graphical representation of an algorithm/a program

Do-Until Control StructureWhile-Do Control StructureSelection Control Structure

Jean Wang / CS1102 – Lec06

Page 18: CS1102 Lec06 – Programming Languages & Program Development

Flowchart Example: Number-Guessing game

The program runs to “END” for each repetition, waiting for user’s input to “Begin” again.

18 Jean Wang / CS1102 – Lec06

Page 19: CS1102 Lec06 – Programming Languages & Program Development

Another Example: Run-Length Encoding Decompression

Run-length encoding (RLE) is a simple form of data compression in which sequences of the same data value occurs consecutively are stored as a single data value and count, rather than as the original data sequence. Sample Input: W5B1W2B3W4Sample output: WWWWWBWWBBBWWWW Sample Input: R1B1G1W8B7Sample output: RBGWWWWWWWWBBBBBBB

Draw the flowchart for the RLE decompression algorithm, which reads in a RLE-compressed sequence and outputs the original long character sequence.

19 Jean Wang / CS1102 – Lec06

Page 20: CS1102 Lec06 – Programming Languages & Program Development

Flowchart for RLE Decompression

20 Jean Wang / CS1102 – Lec06

Page 21: CS1102 Lec06 – Programming Languages & Program Development

21

Lesson Summary Programmers(or software designers) write programs in programming

languages to instruct the computer to perform some task Computer programming is a specialized form of problem solving that

involves devising an algorithm

Early generation of programming languages are low-level ones that are different for programmers to write and read; while newer generation of programming languages are high-level ones that are more close to human natural languages To convert programs written in high-level languages to low-level computer

instructions, a compiler or interpreter is needed

Markup language and scripting language are distinct from general-purpose programming languages

Jean Wang / CS1102 – Lec06

Page 22: CS1102 Lec06 – Programming Languages & Program Development

22

Lesson Summary (cont'd) All programs follow the similar basic structure, but may use

different design methods and languages

Six steps in the program development life cycle used to make this process efficient and systematic

Three basic control structures (sequence, selection and repetition) are used in structural design and any complex program can be built from these three control structures Structural programmer often use flowchart to plan the sequence of an

algorithm

Jean Wang / CS1102 – Lec06

Page 23: CS1102 Lec06 – Programming Languages & Program Development

23

Careers in the Computer Industry An information technology (IT) department is

Department in business or government agency that employs people in computer-related jobs, responsible for keeping all computer operations and networks operating smoothly

Jobs available in an IT department include…

Management

Chief Information Officer / VP of IT

Chief Security Officer

E-commerce administrator

Network administrator

Application programmerSoftware engineer

Systems analystComputer scientist

Systems programmerDatabase analyst

Technical writer

Web page author

Computer operator Data communications analyst

Corporate trainer Help desk specialist

Computer forensics specialist

Computer technician Graphic designer / illustrator

Network security specialistDatabase administrator

Quality assurance specialistDesktop publisher

Security administrator

System development and programming

Technical services

Operations

Training

Project leader / manager

Web administrator / Webmaster

Page 24: CS1102 Lec06 – Programming Languages & Program Development

24

Preparing for a Career in the Computer or IT Industry

Computer Science (CS) includes… Programs that stress the technical and theoretical side of

programming and operating systems Courses cover almost every aspect of the computer system

Computer Core

Problem Solving and Programming

Object-oriented Programming

Software Design

Database System

Computer Organization

Operating Systems

Information Security

Topics on Computer Security

Information Security and Management

Internet Security and E-commerce Protocols

Internet Application Development

Multimedia Computing

Computer Graphics

Multimedia Technologies & Applications

Multi-modal Interface Design

Computer Games Design

Computer Vision & Image Processing

Software Engineering

Object-oriented Methodology

Software Testing and Maintenance

Software Quality Management

Performance Evaluation

Web Usability Design and Engineering

Formal Methods in Software Engineering

Systems and Networks

Computer Architecture

Distributed Systems

Software Testing and Maintenance

Mobile Computing

Internet and Distributed Systems Programming

Pervasive Computing

High Speed Multimedia Network