Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS1102 Lec06 – Programming Languages & Program Development

Similar presentations


Presentation on theme: "CS1102 Lec06 – Programming Languages & Program Development"— Presentation transcript:

1 CS1102 Lec06 – Programming Languages & Program Development
Semester B, Computer Science Department City University of Hong Kong

2 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 Jean Wang / CS1102 – Lec06

3 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 Jean Wang / CS1102 – Lec06

4 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 Syntax error, cannot compile nor execute Jean Wang / CS1102 – Lec06

5 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 Machine code Assembly code LOAD   #2 1 STORE  13 2 LOAD   #5 3 STORE  14 4 LOAD   13 5 ADD    14 6 STORE  15 7 HALT      Machine code & assembly 1-1 mappying Jean Wang / CS1102 – Lec06

6 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 OO languages started in 1990s. Jean Wang / CS1102 – Lec06

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 Markup languages are for text formatting. XML has strong types: for data exchange HTML, XML are NOT programming language; what qualified to be a programming language: you’ve control statement (if then) and loop. Jean Wang / CS1102 – Lec06

8 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: Program design is more important and most difficult part; coding is only a translation of your solution into programming language Maintenance: fix bugs, function extension, move to new platform, etc Jean Wang / CS1102 – Lec06

9 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 program Program design = problem solving Jean Wang / CS1102 – Lec06

10 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. Jean Wang / CS1102 – Lec06

11 Step 1 – Analyze Requirements
A number-guessing game 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. Demo: Jean Wang / CS1102 – Lec06

12 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 1.1 display instructions 1.2 generate a number between 1 and 100 2. Repeat guessing process until the number is guessed Or seven turns are completed 2.1 input guess from user 2.2 respond to the guess 2.3 if seven turns are used up, then end the game Getting into details layer by layer (2.2 -> 2.2.1) 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 Jean Wang / CS1102 – Lec06

13 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 Use your brain to test solution! Jean Wang / CS1102 – Lec06

14 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 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) Use tools to generate template if there’s any Jean Wang / CS1102 – Lec06 14

15 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. Program testing: generate testing cases: normal cases, boundary cases, illegal input cases, etc. Documentation important: a) for others to read, b) for urself to read Jean Wang / CS1102 – Lec06 15

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 Note: all programs can be constructed by using the 3 structures! A programming language can minimally define 3 types of statements. Jean Wang / CS1102 – Lec06

17 Flowchart Flowchart - a graphical representation of an algorithm/a program Selection Control Structure While-Do Control Structure Do-Until Control Structure Flowchart is an important method for program design. While-do / do-until: where to test the condition Jean Wang / CS1102 – Lec06

18 Flowchart Example: Number-Guessing game
The program runs to “END” for each repetition, waiting for user’s input to “Begin” again. Demo again: numberGuess.html Every time, when user inputs a number, it starts again: it’s a loop. See source code. Jean Wang / CS1102 – Lec06

19 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: W5B1W2B3W4 Sample output: WWWWWBWWBBBWWWW Sample Input: R1B1G1W8B7 Sample output: RBGWWWWWWWWBBBBBBB Draw the flowchart for the RLE decompression algorithm, which reads in a RLE-compressed sequence and outputs the original long character sequence. Jean Wang / CS1102 – Lec06

20 Flowchart for RLE Decompression
Jean Wang / CS1102 – Lec06

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

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

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 programmer Software engineer Systems analyst Computer scientist Systems programmer Database 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 specialist Database administrator Quality assurance specialist Desktop publisher Security administrator System development and programming Technical services Operations Training Project leader / manager Web administrator / Webmaster

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 Software Design Computer Organization Object-oriented Programming Database System Operating Systems Information Security Topics on Computer Security Internet Security and E-commerce Protocols Information Security and Management Internet Application Development Multimedia Computing Computer Graphics Multi-modal Interface Design Computer Vision & Image Processing Multimedia Technologies & Applications Computer Games Design High Speed Multimedia Network Software Engineering Object-oriented Methodology Software Quality Management Web Usability Design and Engineering Software Testing and Maintenance Performance Evaluation Formal Methods in Software Engineering Systems and Networks Computer Architecture Software Testing and Maintenance Internet and Distributed Systems Programming Distributed Systems Mobile Computing Pervasive Computing


Download ppt "CS1102 Lec06 – Programming Languages & Program Development"

Similar presentations


Ads by Google