Program Design Phase. Algorithm Design - Mathematical. Algorithm Design - Sequence. Verify Algorithm Y = MX + B

Similar documents
People = End Users & Programmers. The Web Browser Application. Program Design Phase. Algorithm Design -Mathematical Y = MX + B

CSC Web Programming. Introduction to JavaScript

Flow of Control. Relational Operators. Operators Review. Order of Operations

Chapter 8 JavaScript/JScript: Introduction to Scripting 201

JavaScript: Introduction to Scripting

Introduction to C# Applications

A.A. 2008/09. Why introduce JavaScript. G. Cecchetti Internet Software Technologies

CHAPTER 5: JavaScript Basics 99

JavaScript: Introductionto Scripting

COMS 469: Interactive Media II

Exercise 1: Basic HTML and JavaScript

C: How to Program. Week /Mar/05

BASIC ELEMENTS OF A COMPUTER PROGRAM

JavaScript: Control Statements I Pearson Education, Inc. All rights reserved.

Chapter 2 Working with Data Types and Operators

Java Identifiers. Java Language Essentials. Java Keywords. Java Applications have Class. Slide Set 2: Java Essentials. Copyright 2012 R.M.

Chapter 2: Using Data

Variables and Typing

Chapter 2 - Introduction to C Programming

3 The Building Blocks: Data Types, Literals, and Variables

Full file at C How to Program, 6/e Multiple Choice Test Bank

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.

JME Language Reference Manual

introjs.notebook March 02, 2014

GridLang: Grid Based Game Development Language Language Reference Manual. Programming Language and Translators - Spring 2017 Prof.

MATVEC: MATRIX-VECTOR COMPUTATION LANGUAGE REFERENCE MANUAL. John C. Murphy jcm2105 Programming Languages and Translators Professor Stephen Edwards

Introduction to C Programming. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan

c122mar413.notebook March 06, 2013

DEPARTMENT OF MATHS, MJ COLLEGE

CHAPTER-6 GETTING STARTED WITH C++

Chapter 2: Overview of C++

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

Full file at

Programming Lecture 3

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

CGS 3066: Spring 2015 JavaScript Reference

Visual C# Instructor s Manual Table of Contents

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

Chapter 2. Lexical Elements & Operators

3. Java - Language Constructs I

Contents. Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual

Chapter 2: Using Data

Java Notes. 10th ICSE. Saravanan Ganesh

VLC : Language Reference Manual

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.

6.096 Introduction to C++ January (IAP) 2009

age = 23 age = age + 1 data types Integers Floating-point numbers Strings Booleans loosely typed age = In my 20s

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

Working with JavaScript

Chapter Overview. C++ Basics. Variables and Assignments. Variables and Assignments. Keywords. Identifiers. 2.1 Variables and Assignments

A complex expression to evaluate we need to reduce it to a series of simple expressions. E.g * 7 =>2+ 35 => 37. E.g.

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Chapter 2. C++ Basics

COMP 202 Java in one week

Unit-II Programming and Problem Solving (BE1/4 CSE-2)

UNIT- 3 Introduction to C++

Chapter 2 Elementary Programming

Chapter 17. Fundamental Concepts Expressed in JavaScript

EDIABAS BEST/2 LANGUAGE DESCRIPTION. VERSION 6b. Electronic Diagnostic Basic System EDIABAS - BEST/2 LANGUAGE DESCRIPTION

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

Programming Languages & Translators. XML Document Manipulation Language (XDML) Language Reference Manual

COMP519 Web Programming Lecture 11: JavaScript (Part 2) Handouts

Programming in C++ 4. The lexical basis of C++

Creating a C++ Program

Typescript on LLVM Language Reference Manual

The MaSH Programming Language At the Statements Level

! A program is a set of instructions that the. ! It must be translated. ! Variable: portion of memory that stores a value. char

C Language, Token, Keywords, Constant, variable

Variable and Data Type I

Chapter 1 & 2 Introduction to C Language

C OVERVIEW BASIC C PROGRAM STRUCTURE. C Overview. Basic C Program Structure

Lecture Set 2: Starting Java

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

CHIL CSS HTML Integrated Language

Introduction to Programming

Operators in C. Staff Incharge: S.Sasirekha

Lecture Set 2: Starting Java

C OVERVIEW. C Overview. Goals speed portability allow access to features of the architecture speed

Chapter 2: Data and Expressions

Lecture 3. More About C

Introduction to C# Applications Pearson Education, Inc. All rights reserved.

COSC 122 Computer Fluency. Programming Basics. Dr. Ramon Lawrence University of British Columbia Okanagan

IT 374 C# and Applications/ IT695 C# Data Structures

Chapter 2: Using Data

Language Reference Manual simplicity

Università degli Studi di Bologna Facoltà di Ingegneria. Principles, Models, and Applications for Distributed Systems M

Language Fundamentals Summary

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

Variable and Data Type I

Chapter 2: Data and Expressions

Starting with a great calculator... Variables. Comments. Topic 5: Introduction to Programming in Matlab CSSE, UWA

The Warhol Language Reference Manual

CSC 1214: Object-Oriented Programming

Fundamental of Programming (C)

JavaScript: Control Statements I

Programming for Engineers Introduction to C

Basic Elements of C. Staff Incharge: S.Sasirekha

Transcription:

Program Design Phase Write Program Specifications Analysis of requirements Program specifications description Describe what the goals of the program Describe appearance of input and output Algorithm Design Mathematical Analysis and Algorithm Flow Chart to describe event sequencing Verify algorithm Test with known data Solve manually 1 Algorithm Design - Mathematical Mathematical Description Boiling point F =212 C = 100 Freezing point F = 32 C = 0 Y = MX + B F = (180 / 100) C + 32 = (9/5) C + 32 = 1.8 C + 32 2 Algorithm Design - Sequence Flowcharts are an excellent way to plan the sequence of operations for the program to run Terminator Input/Output Process Connector Start Display Introduction Prompt and Input Celsius Temperature Convert to Fahrenheit Temperature Display both Celsius Temperature And Fahrenheit Temperature End Verify Algorithm Testing with known data Boiling point F =212 C = 100 Freezing point F = 32 C = 0 Collect Data Bank thermometer Radio weather report Solve manually by hand using calculator 3 4

Implementation Phase Translate Algorithm into Code Create HTML source code file embedding JavaScript code Run to detect syntax errors Test Program Test with known data Detects program logic errors Often requires several iterations May require re-evaluation of specifications and algorithms Coding First Is No Shortcut? Shortcut? CODE DEBUG REVISE REVISE DEBUG DEBUG REVISE GOAL TEST THINKING CODE 5 6 JavaScript Programming Language All Web browsers support the JavaScript client-side scripting language and contain the JavaScript Interpreter, which processes JavaScript commands. JavaScript code usually appears in the section of the HTML document. The browser interprets the contents of the section first, before the of the HTML document is rendered. JavaScript is Case Sensitive and all Keywords must be lower case JavaScript is an object based language Whitespace is ignored = space, tabs, new lines 7 HTML Element element indicates to browser that text that follows is part of a script. Most browser use JavaScript as the default scripting language type attribute specifies type of scripting language and is optional for HTML5 <script type="text/javascript"> script code statements; 8

JavaScript Comments and Statements Text contained within a JavaScript comment is not executed by the JavaScript interpreter Single-line comments // This is a comment Multi-line comments /* This is a comment */ Browser that does not support scripts, ignores the element and the script code All JavaScript statements end with a semicolon ; JavaScript can output HTML code to the browser which then displays the contents. document.write ( "<h3>hello World!</h3>" ); 9 JavaScript Output document.write() Object is document Method is write = sends string to body <title>a First Program in JavaScript</title> <script type="text/javascript"> document.write( "<h3>hello World!</h3>" ); </body> </html> 10 Strings and Escape Characters Character Strings are denoted by enclosing text in either 'single' or "double quotes" Escape Characters must use a backslash preceding the specification Text string escape character specifications: \n = new line \\ = backslash \" = double quote \' = single quote \t = tab \r = carriage return 11 String Concatenation and Escape Characters String Concatenation Operator + Connects two strings together Special Character \" <title>using String Concatenation</title> <script type="text/javascript"> document.write("<h2>"); document.write("welcome to string" + " \"concatenation\"!</h2>"); </body> </html> 12

JavaScript Output: Alert Window window.alert() Object Method <title>alert Window</title> window.alert("welcome to\njavascript\nprogramming!"); <h2>click Refresh (or Reload)<br> to run this script again.</h2> </body> JavaScript Variables A Variable is a container of data Variables declared with var statement var ni; // Single variable declaration var sentry1, sentry2, nj, nm; // Multiple variables var ni=0, nj=0; // Variables can be initialized to value Declaration statements end with semicolon (;) Multiple variable declaration comma separated Variable name can be any valid identifier. An identifier is a name for a variable of function Consisting of letters, digits, "_" and "$" Can NOT begin with a digit Can NOT have spaces or symbols other then _ and $ Can NOT be a JavaScript keyword </html> 13 14 JavaScript Keywords JavaScript has only 22 keywords that can NOT be used for an identifier name. break case continue delete do else false for function if in new null return switch this true typeof var void while with Twelve other keywords also can not be used for identifiers catch class const debugger default enum export extends finally import JavaScript Prompt for Input Data window.prompt(prompt, default) Return the string entered to assigned variable <title>what is your name?</title> var sfirstname; // String of characters input variable sfirstname = window.prompt( "What is your name?", "" ); window.alert(sfirstname + "\'s mother\nwears army boots!"); document.write("<h2>" + sfirstname + " she really does...</h2>"); <p>click Refresh (or Reload) to run the script again</p> </body> super 15 16 <html>

JavaScript Data Types and Values JavaScript is "loosely" typed language Simple Data Types String of text var sfirstname, sentry; Symbolized using "abc123" or 'abc123' Special Characters may be used \n \t \b \" \' Numbers var ni = 0, farea, ftotal = 0; 8 byte (64 bit) floating point format +1.8 x 10 +308 int parseint( string ) Converts string to integer (whole number) Drops all fractional part to right of decimal point float parsefloat( string ) Converts string to floating point (real number) Keeps fractional part to right of decimal point 17 JavaScript Arithmetic Operators Used to perform arithmetic operations on numbers and data contained in variables, with the result usually assigned to variable Order of precedence determines which order the operations will be performed Note that the assignment operator = is defined last and precedence is last For readability insert parenthesis if order of operation not apparent in code 18 Arithmetic Operators Precedence (Highest to Lowest) ( ) Defines order of operation - Negative (unary) * / % Multiply, Division, Remainder + - Addition (concatenation), Subtraction = Assignment 19 3 Exams Average Example <title>average Test Score</title> var favgscore, fscore, ftotalscore = 0; var sentry = window.prompt( "Enter Exam 1 Score", "0" ); fscore = parsefloat(sentry); ftotalscore = ftotalscore + fscore; sentry = window.prompt("enter Exam 2 Score", "0" ); fscore = parsefloat(sentry); ftotalscore = ftotalscore + fscore; sentry = window.prompt("enter Exam 3 Score", "0" ); fscore = parsefloat(sentry ); ftotalscore = ftotalscore + fscore; document.write("average Score = " + ftotalscore/3.0); </body> </html> 20

<title>double Sum Program</title> var sentry1, sentry2; // Strings entered by user var nnum1, nnum2, nsum; //Prompt and Receive numbers sentry1 = window.prompt("enter first number", "0"); sentry2 = window.prompt("enter second number", "0"); // Convert numbers from strings to integers nnum1 = parseint(sentry1 ); nnum2 = parseint(sentry2 ); // Add the numbers nsum = nnum1 + nnum2; var ndouble = nsum * 2; // Display the results document.write("<h2>the double sum is "+ndouble+"</h2>"); <p>click Refresh (or Reload) to run the script again</p> A Shorter Double Sum Program Previous program with less code How many variables? Combine input prompt and parseint in one statement Do calculations in output <title>shorter Double Sum Program</title> var nnum1, nnum2; // Converted number entries nnum1 = parseint(window.prompt("enter first number","0")); nnum2 = parseint(window.prompt("enter second number","0")); document.write("<h2>the double sum is " +(nnum1+nnum2)*2 + "</h2>"); <p>click Refresh (or Reload) to run the script again</p> </body> </html> </body></html> 22