UEE1302 (1102) F10 Introduction to Computers and Programming
|
|
|
- Warren Douglas
- 9 years ago
- Views:
Transcription
1 Computational Intelligence on Automation NCTU UEE1302 (1102) F10 Introduction to Computers and Programming Programming Lecture 03 Flow of Control (Part II): Repetition while,for & do..while Learning Objectives In this chapter you will: Learn about repetition (looping) control structures, i.e. while, for and dowhile Explore how to construct and use (1) countcontrolled, (2) sentinel-controlled, (3) flagcontrolled, and (4) EOF-controlled repetition structures Examine break and continue statements Discover how to form and use nested control structures PRO_03 PROF. HUNG-PIN(CHARLES) WEN 2 Flow of Execution statement 1 false true bool_expr statement 2 statement N stmt_no stmt_yes false loop_cond true stmt_loop (A) sequence (B) selection (C) repetition PRO_03 PROF. HUNG-PIN(CHARLES) WEN 3 Why Is Repetition Needed? Repetition (a.k.a. Loop) allow you to efficiently use variables can input, add, and average multiple numbers using a limited number of variables For example, to add five numbers: declare a variable for each number, input the numbers and add the variables together create a loop that reads a number into a variable and adds it to a variable that contains the sum of the numbers PRO_03 PROF. HUNG-PIN(CHARLES) WEN 4
2 A First Look of Loops 3 types of loop structures in C++ 1.while most flexible no restrictions 2.do-while least flexible always execute loop body at least once 3.for natural counting loop while Loop Example count = 0; // Initialization while (count < 3) // Loop Condition cout << "Hi "; // Loop Body count++; // Update expression Loop body executes how many times? PRO_03 PROF. HUNG-PIN(CHARLES) WEN 5 PRO_03 PROF. HUNG-PIN(CHARLES) WEN 6 do-while Loop Example count = 0; do // Initialization cout << "Hi "; // Loop Body count++; // Update expression while (count < 3); // Loop Condition Loop body executes how many times? do-while loops always execute body at least once! PRO_03 PROF. HUNG-PIN(CHARLES) WEN 7 for Loop Example for (count=0; count<3; count++) cout << "Hi "; // Loop Body How many times does loop body execute? Initialization, loop condition and update are all built into the for-loop structure! A natural "counting" loop PRO_03 PROF. HUNG-PIN(CHARLES) WEN 8
3 false entry_cond true stmt_while The while Loop (1/2) Syntax of the while statement is: while (entry_cond) statement_while; Statement statement_while can be either simple or compound body of the loop Expression entry_cond acts as a decision maker and is usually a Boolean expression The parentheses () are part of the syntax PRO_03 PROF. HUNG-PIN(CHARLES) WEN 9 The while Loop (2/2) Expression entry_cond provides an entry condition Statement statement_while executes if the expression initially evaluates to true Loop condition entry_cond is then reevaluated Statement continues to execute until the expression entry_cond is no longer true Infinite loop: continues to execute endlessly can be avoided by including statements in the loop body that assure exit condition will eventually be true PRO_03 PROF. HUNG-PIN(CHARLES) WEN 10 while Loop Example (1/2) idx = 0; while (idx < 10) cout << 2*idx << ; idx += 2; // idx= idx + 2 cout << endl; Sample Run: >./a.out PRO_03 PROF. HUNG-PIN(CHARLES) WEN 11 while Loop Example (2/2) idx = 20; while (idx < 20) //never satisfy entry_cond cout << idx << ; idx += 5; cout << endl; Sample Run: >./a.out _ PRO_03 PROF. HUNG-PIN(CHARLES) WEN 12
4 while (1): Counter-ControlledControlled If you know exactly how many pieces of data need to be read, the while loop becomes a counter-controlled loop Example of counter-controlled loop: counter = 0; // initialize loop control while (counter < Limit) // test loop control statements; counter++; // update loop control while (2): Sentinel-Controlled Sentinel variable is tested in the condition and loop ends when sentinel is encountered Example of sentinel-controlled loop: cin >> target; // initialize loop control while (target!= sentinel) //test loop control statements; cin >> target; // update loop control PRO_03 PROF. HUNG-PIN(CHARLES) WEN 13 PRO_03 PROF. HUNG-PIN(CHARLES) WEN 14 while (3): Flag-Controlled A flag-controlled while loop uses a bool variable to control the loop Example of flag-controlled loop: loop_stop = false; // initialize loop control while (!loop_stop) // test loop control if (expression) // update loop control loop_stop = true; while (4): EOF-Controlled A EOF-controlled while loop uses a EOF (End-of-File) to control the loop The logical value returned by cin can determine if the program has ended input Example of EOF-controlled loop: cin >> var; // initialize loop control while (cin) // cintest does loop not reach control EOF cin >> var; // update loop control Or use while (!cin.eof()) PRO_03 PROF. HUNG-PIN(CHARLES) WEN 15 PRO_03 PROF. HUNG-PIN(CHARLES) WEN 16
5 The eof Function When a program is reading from a disk file, eof can determine the end of file status When reading from input devices like keyboard, use ctrl+z or ctrl+d denotes eof eof is a member of data type istream iostream includes header files ofistream, ostream and others Syntax for the function eof is: istreamobj.eof() istreamobj is an input stream variable, such as cin. EX:cin.eof() cin.clear();to reset eof and restart reading from input devices PRO_03 PROF. HUNG-PIN(CHARLES) WEN 17 while Pitfalls: Misplaced ; Watch the misplaced ; (semicolon) Example: while (response!= 0); cout << "Enter val: "; cin >> response; Notice the ";" after the while condition! Result here: INFINITE LOOP! PRO_03 PROF. HUNG-PIN(CHARLES) WEN 18 while Pitfalls: Infinite Loops Loop condition must evaluate to false at some iteration through loop If not infinite loop while (1) cout << "Hello "; a perfectly legal C++ loop always infinite! Sometimes, infinite loops can be desirable e.g., "Embedded Systems" PRO_03 PROF. HUNG-PIN(CHARLES) WEN 19 false init_stmt loop_cond true stmt_for update_stmt The for Loop Syntax of for statement: for (init_stmt;lp_cond;update_stmt) statement_for; init_stmt: initialize ctrl variable lp_cond: compare ctrl variable update_stmt : update ctrl variable Action statement stmt_for can be a compound statement much more typical PRO_03 PROF. HUNG-PIN(CHARLES) WEN 20
6 for versus while (1/2) Rewrite for statement in while loop: init_stmt; while (lp_cond) stmt_for; update_stmt; Rewrite while statement in for loop: for ( ; entry_cond; ) stmt_while; PRO_03 PROF. HUNG-PIN(CHARLES) WEN 21 for versus while (2/2) Components of for statement are optional but semicolons ; must always be present omissions doing nothing in init_stmt and update_stmt or being true in lp_cond EX: for ( ; ; ) statements; is valid Differentiate for from while: initialization statements grouped as first set of items init_stmt within the for s () loop condition and loop statements are fixed: no change in for update statements as the last set of items update_stmt within the for s () PRO_03 PROF. HUNG-PIN(CHARLES) WEN 22 for Loop Example 1 (1/3) Example 1: for (count=2; count<=20; count+=2) cout << count << ; Modified Example 1a: count = 2; for ( ; count<=20; count+=2) cout << count << ; Sample Run: >./a.out PRO_03 PROF. HUNG-PIN(CHARLES) WEN 23 for Loop Example 1 (2/3) Example 1: for (count=2; count<=20; count+=2) cout << count << ; Modified Example 1b: count = 2; for ( ; count<=20; ) cout << count << ; count +=2; PRO_03 PROF. HUNG-PIN(CHARLES) WEN 24
7 for Loop Example 1 (3/3) Example 1: for (count=2; count<=20; count+=2) cout << count << ; Modified Example 1c: count = 2; for (count=2; count<=20; cout << count <<, count+=2) ; for Loop Example 2 (1/2) Example 2: for (idx=1; idx<=5; idx++) cout << Hello! << endl; cout << * << endl; What will happen? Example 2a: for (idx=1; idx<=5; idx++) cout << Hello! << endl; cout << * << endl; What will happen? PRO_03 PROF. HUNG-PIN(CHARLES) WEN 25 PRO_03 PROF. HUNG-PIN(CHARLES) WEN 26 Example 2: for Loop Example 2 (2/2) for (idx=1; idx<=5; idx++) cout << Hello! << endl; cout << * << endl; Example 2b: for (idx=1; idx<=5; idx++) ; cout << Hello! << endl; cout << * << endl; What will happen? PRO_03 PROF. HUNG-PIN(CHARLES) WEN 27 Comments on for loop If loop condition lp_cond is initially false do nothing Ex: for (idx=0; idx > 0; idx++) Update statement update_stmt eventually sets the value of lp_cond to false otherwise, this for loop will run forever. Ex: for (idx=0; idx<100; idx--) If ctrl variable is float/double, then different computers may yield different results on ctrl variable should avoid using such variable. Ex: for (double idx=0.1; idx<1.2; idx+=0.05) PRO_03 PROF. HUNG-PIN(CHARLES) WEN 28
8 The dowhile Loop (1/2) The dowhile Loop (2/2) stmt_dowhile rep_cond false true Syntax of dowhile statement: do stmt_dowhile; while (rep_cond); Statement stmt_dowhile executes first, and then rep_cond is evaluated If rep_cond evaluates to true,, the statement stmt_dowhile runs again As long as rep_cond in a dowhile statement is true, the statement stmt_dowhile executes To avoid an infinite loop, the loop body stmt_dowhile must contain a update statement that makes rep_cond to be false The statement stmt_dowhile can be simple or compound If compound, it must be in braces dowhile loop typically has an exit condition and iterates at least once (unlike for and while) PRO_03 PROF. HUNG-PIN(CHARLES) WEN 29 PRO_03 PROF. HUNG-PIN(CHARLES) WEN 30 Example 1: dowhile Loop Example idx = 1; do cout << idx << ; idx *= 2; while (idx <= 20); What will be displayed on screen? Answer: dowhile Loop vs while Loop Example 2a: idx = 15; do idx %= 8; while (idx > 15); cout << idx << endl; Example 2b: idx = 15; while (idx > 15) idx %= 8; cout << idx << ; What will be displayed on screen? Answer: 7 Answer: 15 PRO_03 PROF. HUNG-PIN(CHARLES) WEN 31 PRO_03 PROF. HUNG-PIN(CHARLES) WEN 32
9 break & continue in Repetition Flow of Control Recall how loops provide "graceful" and clear flow of control in and out In RARE instances, can alter natural flow break force the loop to exit immediately. continue skip the rest of loop body These statements violate natural flow only used when absolutely necessary! PRO_03 PROF. HUNG-PIN(CHARLES) WEN 33 break in Loop break: forces immediate exits from structures: in switch statements: the desired case is detected/processed in while, for and dowhile statements: an unusual condition is detected for (idx=10; idx<=50; idx+=2) if (idx%9 == 0) break; cout << idx << ; What will be displayed on screen? PRO_03 PROF. HUNG-PIN(CHARLES) WEN 34 continue in Loop continue: cause the next iteration of the loop to begin immediately execution transferred to the top of the loop apply only to while, for and dowhile statements idx = 0; while (idx < 100) idx++; if (idx == 50) continue; cout << idx << endl; What will be displayed on screen? PRO_03 PROF. HUNG-PIN(CHARLES) WEN 35 Nested Loops (1/2) A loop contained within another loop Print 9x9 multiples for (idx=1; idx<=9; idx++) //outer loop cout << idx << -multiples: << endl; for (jdx=1; jdx<=9; jdx++) //inner loop cout << idx*jdx << ; // end of inner loop // end of outer loop PRO_03 PROF. HUNG-PIN(CHARLES) WEN 36
10 Outer (first) Loop: Nested Loops (2/2) controlled by value of idx Inner (second) Loop: controlled by value of jdx Rules: For each single trip through outer loop, inner loop runs through its entire sequence Different variables to control each loop Inner loop statements contained within outer loop Summary (1/3) C++ has three looping (repetition) structures: while, for and dowhile while, for and dowhile are reserved words while and for loops are called pre-test loops dowhile loop is called a post-test loop while and for may not execute at all, but dowhile always executes at least once PRO_03 PROF. HUNG-PIN(CHARLES) WEN 37 PRO_03 PROF. HUNG-PIN(CHARLES) WEN 38 Summary (2/3) while: expression is the decision maker, and the statement is the body of the loop In a counter-controlled while loop, Initialize counter before loop Body must contain a statement that changes the value of the counter variable A sentinel-controlled while loop uses a sentinel to control the while loop An EOF-controlled while loop executes until the program detects the end-of-file marker Summary (3/3) for: simplifies the writing of a countcontrolled while loop Executing a break statement in the body of a loop immediately terminates the loop Executing a continue statement in the body of a loop skips to the next iteration After a continue statement executes in a for loop, the update statement is the next statement executed PRO_03 PROF. HUNG-PIN(CHARLES) WEN 39 PRO_03 PROF. HUNG-PIN(CHARLES) WEN 40
QUIZ-II QUIZ-II. Chapter 5: Control Structures II (Repetition) Objectives. Objectives (cont d.) 20/11/2015. EEE 117 Computer Programming Fall-2015 1
QUIZ-II Write a program that mimics a calculator. The program should take as input two integers and the operation to be performed. It should then output the numbers, the operator, and the result. (For
What is a Loop? Pretest Loops in C++ Types of Loop Testing. Count-controlled loops. Loops can be...
What is a Loop? CSC Intermediate Programming Looping A loop is a repetition control structure It causes a single statement or a group of statements to be executed repeatedly It uses a condition to control
9 Control Statements. 9.1 Introduction. 9.2 Objectives. 9.3 Statements
9 Control Statements 9.1 Introduction The normal flow of execution in a high level language is sequential, i.e., each statement is executed in the order of its appearance in the program. However, depending
While Loop. 6. Iteration
While Loop 1 Loop - a control structure that causes a set of statements to be executed repeatedly, (reiterated). While statement - most versatile type of loop in C++ false while boolean expression true
6. Control Structures
- 35 - Control Structures: 6. Control Structures A program is usually not limited to a linear sequence of instructions. During its process it may bifurcate, repeat code or take decisions. For that purpose,
The C++ Language. Loops. ! Recall that a loop is another of the four basic programming language structures
The C++ Language Loops Loops! Recall that a loop is another of the four basic programming language structures Repeat statements until some condition is false. Condition False True Statement1 2 1 Loops
Lecture 2 Notes: Flow of Control
6.096 Introduction to C++ January, 2011 Massachusetts Institute of Technology John Marrero Lecture 2 Notes: Flow of Control 1 Motivation Normally, a program executes statements from first to last. The
Basics of I/O Streams and File I/O
Basics of This is like a cheat sheet for file I/O in C++. It summarizes the steps you must take to do basic I/O to and from files, with only a tiny bit of explanation. It is not a replacement for reading
Two-way selection. Branching and Looping
Control Structures: are those statements that decide the order in which individual statements or instructions of a program are executed or evaluated. Control Structures are broadly classified into: 1.
Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.
Name: Class: Date: Exam #1 - Prep True/False Indicate whether the statement is true or false. 1. Programming is the process of writing a computer program in a language that the computer can respond to
5.2 Q2 The control variable of a counter-controlled loop should be declared as: a.int. b.float. c.double. d.any of the above. ANS: a. int.
Java How to Program, 5/e Test Item File 1 of 5 Chapter 5 Section 5.2 5.2 Q1 Counter-controlled repetition requires a.a control variable and initial value. b.a control variable increment (or decrement).
Chapter 5. Selection 5-1
Chapter 5 Selection 5-1 Selection (Decision) The second control logic structure is selection: Selection Choosing between two or more alternative actions. Selection statements alter the sequential flow
Chapter One Introduction to Programming
Chapter One Introduction to Programming 1-1 Algorithm and Flowchart Algorithm is a step-by-step procedure for calculation. More precisely, algorithm is an effective method expressed as a finite list of
MS Visual C++ Introduction. Quick Introduction. A1 Visual C++
MS Visual C++ Introduction 1 Quick Introduction The following pages provide a quick tutorial on using Microsoft Visual C++ 6.0 to produce a small project. There should be no major differences if you are
Moving from C++ to VBA
Introduction College of Engineering and Computer Science Mechanical Engineering Department Mechanical Engineering 309 Numerical Analysis of Engineering Systems Fall 2014 Number: 15237 Instructor: Larry
Introduction to Programming (in C++) Loops. Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC
Introduction to Programming (in C++) Loops Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC Example Assume the following specification: Input: read a number N > 0 Output:
Example. Introduction to Programming (in C++) Loops. The while statement. Write the numbers 1 N. Assume the following specification:
Example Introduction to Programming (in C++) Loops Assume the following specification: Input: read a number N > 0 Output: write the sequence 1 2 3 N (one number per line) Jordi Cortadella, Ricard Gavaldà,
C++ Input/Output: Streams
C++ Input/Output: Streams 1 The basic data type for I/O in C++ is the stream. C++ incorporates a complex hierarchy of stream types. The most basic stream types are the standard input/output streams: istream
Passing 1D arrays to functions.
Passing 1D arrays to functions. In C++ arrays can only be reference parameters. It is not possible to pass an array by value. Therefore, the ampersand (&) is omitted. What is actually passed to the function,
JavaScript: Control Statements I
1 7 JavaScript: Control Statements I 7.1 Introduction 2 The techniques you will learn here are applicable to most high-level languages, including JavaScript 1 7.2 Algorithms 3 Any computable problem can
Common Beginner C++ Programming Mistakes
Common Beginner C++ Programming Mistakes This documents some common C++ mistakes that beginning programmers make. These errors are two types: Syntax errors these are detected at compile time and you won't
ALGORITHMS AND FLOWCHARTS
ALGORITHMS AND FLOWCHARTS A typical programming task can be divided into two phases: Problem solving phase produce an ordered sequence of steps that describe solution of problem this sequence of steps
The While Loop. Objectives. Textbook. WHILE Loops
Objectives The While Loop 1E3 Topic 6 To recognise when a WHILE loop is needed. To be able to predict what a given WHILE loop will do. To be able to write a correct WHILE loop. To be able to use a WHILE
LOOPS CHAPTER CHAPTER GOALS
jfe_ch04_7.fm Page 139 Friday, May 8, 2009 2:45 PM LOOPS CHAPTER 4 CHAPTER GOALS To learn about while, for, and do loops To become familiar with common loop algorithms To understand nested loops To implement
Chapter 8 Selection 8-1
Chapter 8 Selection 8-1 Selection (Decision) The second control logic structure is selection: Selection Choosing between two or more alternative actions. Selection statements alter the sequential flow
This loop prints out the numbers from 1 through 10 on separate lines. How does it work? Output: 1 2 3 4 5 6 7 8 9 10
Java Loops & Methods The while loop Syntax: while ( condition is true ) { do these statements Just as it says, the statements execute while the condition is true. Once the condition becomes false, execution
Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)
Boolean Expressions, Conditions, Loops, and Enumerations Relational Operators == // true if two values are equivalent!= // true if two values are not equivalent < // true if left value is less than the
Appendix K Introduction to Microsoft Visual C++ 6.0
Appendix K Introduction to Microsoft Visual C++ 6.0 This appendix serves as a quick reference for performing the following operations using the Microsoft Visual C++ integrated development environment (IDE):
Chapter 2: Algorithm Discovery and Design. Invitation to Computer Science, C++ Version, Third Edition
Chapter 2: Algorithm Discovery and Design Invitation to Computer Science, C++ Version, Third Edition Objectives In this chapter, you will learn about: Representing algorithms Examples of algorithmic problem
IS0020 Program Design and Software Tools Midterm, Feb 24, 2004. Instruction
IS0020 Program Design and Software Tools Midterm, Feb 24, 2004 Name: Instruction There are two parts in this test. The first part contains 50 questions worth 80 points. The second part constitutes 20 points
PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?
1. Distinguish & and && operators. PART-A Questions 2. How does an enumerated statement differ from a typedef statement? 3. What are the various members of a class? 4. Who can access the protected members
VB.NET Programming Fundamentals
Chapter 3 Objectives Programming Fundamentals In this chapter, you will: Learn about the programming language Write a module definition Use variables and data types Compute with Write decision-making statements
Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void
1. Explain C tokens Tokens are basic building blocks of a C program. A token is the smallest element of a C program that is meaningful to the compiler. The C compiler recognizes the following kinds of
Sequential Program Execution
Sequential Program Execution Quick Start Compile step once always g++ -o Realtor1 Realtor1.cpp mkdir labs cd labs Execute step mkdir 1 Realtor1 cd 1 cp../0/realtor.cpp Realtor1.cpp Submit step cp /samples/csc/155/labs/1/*.
Simple C++ Programs. Engineering Problem Solving with C++, Etter/Ingber. Dev-C++ Dev-C++ Windows Friendly Exit. The C++ Programming Language
Simple C++ Programs Engineering Problem Solving with C++, Etter/Ingber Chapter 2 Simple C++ Programs Program Structure Constants and Variables C++ Operators Standard Input and Output Basic Functions from
C++ Programming: From Problem Analysis to Program Design, Fifth Edition. Chapter 3: Input/Output
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 3: Input/Output Objectives In this chapter, you will: Learn what a stream is and examine input and output streams Explore
Operator Overloading. Lecture 8. Operator Overloading. Running Example: Complex Numbers. Syntax. What can be overloaded. Syntax -- First Example
Operator Overloading Lecture 8 Operator Overloading C++ feature that allows implementer-defined classes to specify class-specific function for operators Benefits allows classes to provide natural semantics
13 Classes & Objects with Constructors/Destructors
13 Classes & Objects with Constructors/Destructors 13.1 Introduction In object oriented programming, the emphasis is on data rather than function. Class is a way that binds the data & function together.
TIP: To access the WinRunner help system at any time, press the F1 key.
CHAPTER 11 TEST SCRIPT LANGUAGE We will now look at the TSL language. You have already been exposed to this language at various points of this book. All the recorded scripts that WinRunner creates when
Conditions & Boolean Expressions
Conditions & Boolean Expressions 1 In C++, in order to ask a question, a program makes an assertion which is evaluated to either true (nonzero) or false (zero) by the computer at run time. Example: In
Member Functions of the istream Class
Member Functions of the istream Class The extraction operator is of limited use because it always uses whitespace to delimit its reads of the input stream. It cannot be used to read those whitespace characters,
PIC 10A. Lecture 7: Graphics II and intro to the if statement
PIC 10A Lecture 7: Graphics II and intro to the if statement Setting up a coordinate system By default the viewing window has a coordinate system already set up for you 10-10 10-10 The origin is in the
Curriculum Map. Discipline: Computer Science Course: C++
Curriculum Map Discipline: Computer Science Course: C++ August/September: How can computer programs make problem solving easier and more efficient? In what order does a computer execute the lines of code
Iteration CHAPTER 6. Topic Summary
CHAPTER 6 Iteration TOPIC OUTLINE 6.1 while Loops 6.2 for Loops 6.3 Nested Loops 6.4 Off-by-1 Errors 6.5 Random Numbers and Simulations 6.6 Loop Invariants (AB only) Topic Summary 6.1 while Loops Many
Visual Logic Instructions and Assignments
Visual Logic Instructions and Assignments Visual Logic can be installed from the CD that accompanies our textbook. It is a nifty tool for creating program flowcharts, but that is only half of the story.
Using C++ File Streams
Using C++ File Streams David Kieras, EECS Dept., Univ. of Michigan Revised for EECS 381, 9/20/2012 File streams are a lot like cin and cout In Standard C++, you can do I/O to and from disk files very much
Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas
CS 110B - Rule Storage Classes Page 18-1 Attributes are distinctive features of a variable. Data type, int or double for example, is an attribute. Storage class is another attribute. There are four storage
Lecture 3. Arrays. Name of array. c[0] c[1] c[2] c[3] c[4] c[5] c[6] c[7] c[8] c[9] c[10] c[11] Position number of the element within array c
Lecture 3 Data structures arrays structs C strings: array of chars Arrays as parameters to functions Multiple subscripted arrays Structs as parameters to functions Default arguments Inline functions Redirection
Writing Control Structures
Writing Control Structures Copyright 2006, Oracle. All rights reserved. Oracle Database 10g: PL/SQL Fundamentals 5-1 Objectives After completing this lesson, you should be able to do the following: Identify
Moving from CS 61A Scheme to CS 61B Java
Moving from CS 61A Scheme to CS 61B Java Introduction Java is an object-oriented language. This document describes some of the differences between object-oriented programming in Scheme (which we hope you
Object Oriented Software Design
Object Oriented Software Design Introduction to Java - II Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa September 14, 2011 G. Lipari (Scuola Superiore Sant Anna) Introduction
CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013
Oct 4, 2013, p 1 Name: CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 1. (max 18) 4. (max 16) 2. (max 12) 5. (max 12) 3. (max 24) 6. (max 18) Total: (max 100)
Statements and Control Flow
Contents 1. Introduction 2. Types and Variables 3. Statements and Control Flow 4. Reading Input 5. Classes and Objects 6. Arrays 7. Methods 8. Scope and Lifetime 9. Utility classes 10. Introduction to
Selection Statements
Chapter 5 Selection Statements 1 Statements So far, we ve used return statements and expression ess statements. e ts. Most of C s remaining statements fall into three categories: Selection statements:
Calling the Function. Two Function Declarations Here is a function declared as pass by value. Why use Pass By Reference?
Functions in C++ Let s take a look at an example declaration: Lecture 2 long factorial(int n) Functions The declaration above has the following meaning: The return type is long That means the function
JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system.
http://www.tutorialspoint.com/java/java_quick_guide.htm JAVA - QUICK GUIDE Copyright tutorialspoint.com What is Java? Java is: Object Oriented Platform independent: Simple Secure Architectural- neutral
Senem Kumova Metin & Ilker Korkmaz 1
Senem Kumova Metin & Ilker Korkmaz 1 A loop is a block of code that can be performed repeatedly. A loop is controlled by a condition that is checked each time through the loop. C supports two categories
What is the consequences of no break statement in a case.
REVIEW DID YOU THINK ABOUT THE SUBTLE ISSUES HERE The Example using the switch statement. PLAY COMPUTER in class show in a table the values of the variables for the given input!!!! char ch; int ecount=0,
Comp151. Definitions & Declarations
Comp151 Definitions & Declarations Example: Definition /* reverse_printcpp */ #include #include using namespace std; int global_var = 23; // global variable definition void reverse_print(const
F ahrenheit = 9 Celsius + 32
Problem 1 Write a complete C++ program that does the following. 1. It asks the user to enter a temperature in degrees celsius. 2. If the temperature is greater than 40, the program should once ask the
Compiler Construction
Compiler Construction Lecture 1 - An Overview 2003 Robert M. Siegfried All rights reserved A few basic definitions Translate - v, a.to turn into one s own language or another. b. to transform or turn from
Informatica e Sistemi in Tempo Reale
Informatica e Sistemi in Tempo Reale Introduction to C programming Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 25, 2010 G. Lipari (Scuola Superiore Sant Anna)
Computer Programming C++ Classes and Objects 15 th Lecture
Computer Programming C++ Classes and Objects 15 th Lecture 엄현상 (Eom, Hyeonsang) School of Computer Science and Engineering Seoul National University Copyrights 2013 Eom, Hyeonsang All Rights Reserved Outline
1.3 Conditionals and Loops
A Foundation for Programming 1.3 Conditionals and Loops any program you might want to write objects functions and modules graphics, sound, and image I/O arrays conditionals and loops Math primitive data
Ch 7-1. Object-Oriented Programming and Classes
2014-1 Ch 7-1. Object-Oriented Programming and Classes May 10, 2014 Advanced Networking Technology Lab. (YU-ANTL) Dept. of Information & Comm. Eng, Graduate School, Yeungnam University, KOREA (Tel : +82-53-810-2497;
Answers to Review Questions Chapter 7
Answers to Review Questions Chapter 7 1. The size declarator is used in a definition of an array to indicate the number of elements the array will have. A subscript is used to access a specific element
C++ INTERVIEW QUESTIONS
C++ INTERVIEW QUESTIONS http://www.tutorialspoint.com/cplusplus/cpp_interview_questions.htm Copyright tutorialspoint.com Dear readers, these C++ Interview Questions have been designed specially to get
if and if-else: Part 1
if and if-else: Part 1 Objectives Write if statements (including blocks) Write if-else statements (including blocks) Write nested if-else statements We will now talk about writing statements that make
Introduction to Java
Introduction to Java The HelloWorld program Primitive data types Assignment and arithmetic operations User input Conditional statements Looping Arrays CSA0011 Matthew Xuereb 2008 1 Java Overview A high
Shell Scripts (1) For example: #!/bin/sh If they do not, the user's current shell will be used. Any Unix command can go in a shell script
Shell Programming Shell Scripts (1) Basically, a shell script is a text file with Unix commands in it. Shell scripts usually begin with a #! and a shell name For example: #!/bin/sh If they do not, the
Perl in a nutshell. First CGI Script and Perl. Creating a Link to a Script. print Function. Parsing Data 4/27/2009. First CGI Script and Perl
First CGI Script and Perl Perl in a nutshell Prof. Rasley shebang line tells the operating system where the Perl interpreter is located necessary on UNIX comment line ignored by the Perl interpreter End
Sources: On the Web: Slides will be available on:
C programming Introduction The basics of algorithms Structure of a C code, compilation step Constant, variable type, variable scope Expression and operators: assignment, arithmetic operators, comparison,
[Refer Slide Time: 05:10]
Principles of Programming Languages Prof: S. Arun Kumar Department of Computer Science and Engineering Indian Institute of Technology Delhi Lecture no 7 Lecture Title: Syntactic Classes Welcome to lecture
CpSc212 Goddard Notes Chapter 6. Yet More on Classes. We discuss the problems of comparing, copying, passing, outputting, and destructing
CpSc212 Goddard Notes Chapter 6 Yet More on Classes We discuss the problems of comparing, copying, passing, outputting, and destructing objects. 6.1 Object Storage, Allocation and Destructors Some objects
Arrays. number: Motivation. Prof. Stewart Weiss. Software Design Lecture Notes Arrays
Motivation Suppose that we want a program that can read in a list of numbers and sort that list, or nd the largest value in that list. To be concrete about it, suppose we have 15 numbers to read in from
C# programming. Introduction. By Per Laursen
C# programming Introduction By Per Laursen Indhold The Programming Process... 3 Environment... 5 Statements... 7 Programming Fundamentals... 9 Types and Variables... 10 Simple data output on the screen...
Syllabus OBJECT ORIENTED PROGRAMMING C++
1 Syllabus OBJECT ORIENTED PROGRAMMING C++ 1. Introduction : What is object oriented programming? Why do we need objectoriented. Programming characteristics of object-oriented languages. C and C++. 2.
Introduction to Computers and Programming. Testing
Introduction to Computers and Programming Prof. I. K. Lundqvist Lecture 13 April 16 2004 Testing Goals of Testing Classification Test Coverage Test Technique Blackbox vs Whitebox Real bugs and software
PYTHON Basics http://hetland.org/writing/instant-hacking.html
CWCS Workshop May 2009 PYTHON Basics http://hetland.org/writing/instant-hacking.html Python is an easy to learn, modern, interpreted, object-oriented programming language. It was designed to be as simple
Lab 2: Swat ATM (Machine (Machine))
Lab 2: Swat ATM (Machine (Machine)) Due: February 19th at 11:59pm Overview The goal of this lab is to continue your familiarization with the C++ programming with Classes, as well as preview some data structures.
Python Evaluation Rules
Python Evaluation Rules UW CSE 160 http://tinyurl.com/dataprogramming Michael Ernst and Isaac Reynolds [email protected] August 2, 2016 Contents 1 Introduction 2 1.1 The Structure of a Python Program................................
C++FA 5.1 PRACTICE MID-TERM EXAM
C++FA 5.1 PRACTICE MID-TERM EXAM This practicemid-term exam covers sections C++FA 1.1 through C++FA 1.4 of C++ with Financial Applications by Ben Van Vliet, available at www.benvanvliet.net. 1.) A pointer
The if Statement and Practice Problems
The if Statement and Practice Problems The Simple if Statement Use To specify the conditions under which a statement or group of statements should be executed. Form if (boolean-expression) statement; where
CS 101 Computer Programming and Utilization
CS 101 Computer Programming and Utilization Lecture 14 Functions, Procedures and Classes. primitive and objects. Files. Mar 4, 2011 Prof. R K Joshi Computer Science and Engineering IIT Bombay Email: [email protected]
Computer Programming I
Computer Programming I Levels: 10-12 Units of Credit: 1.0 CIP Code: 11.0201 Core Code: 35-02-00-00-030 Prerequisites: Secondary Math I, Keyboarding Proficiency, Computer Literacy requirement (e.g. Exploring
AP Computer Science Java Subset
APPENDIX A AP Computer Science Java Subset The AP Java subset is intended to outline the features of Java that may appear on the AP Computer Science A Exam. The AP Java subset is NOT intended as an overall
El Dorado Union High School District Educational Services
El Dorado Union High School District Course of Study Information Page Course Title: ACE Computer Programming II (#495) Rationale: A continuum of courses, including advanced classes in technology is needed.
While and Do-While Loops. 15-110 Summer 2010 Margaret Reid-Miller
While and Do-While Loops 15-110 Margaret Reid-Miller Loops Within a method, we can alter the flow of control using either conditionals or loops. The loop statements while, do-while, and for allow us execute
C++ Language Tutorial
cplusplus.com C++ Language Tutorial Written by: Juan Soulié Last revision: June, 2007 Available online at: http://www.cplusplus.com/doc/tutorial/ The online version is constantly revised and may contain
Computers. An Introduction to Programming with Python. Programming Languages. Programs and Programming. CCHSG Visit June 2014. Dr.-Ing.
Computers An Introduction to Programming with Python CCHSG Visit June 2014 Dr.-Ing. Norbert Völker Many computing devices are embedded Can you think of computers/ computing devices you may have in your
Flowchart Techniques
C H A P T E R 1 Flowchart Techniques 1.1 Programming Aids Programmers use different kinds of tools or aids which help them in developing programs faster and better. Such aids are studied in the following
CISC 181 Project 3 Designing Classes for Bank Accounts
CISC 181 Project 3 Designing Classes for Bank Accounts Code Due: On or before 12 Midnight, Monday, Dec 8; hardcopy due at beginning of lecture, Tues, Dec 9 What You Need to Know This project is based on
7.7 Case Study: Calculating Depreciation
7.7 Case Study: Calculating Depreciation 1 7.7 Case Study: Calculating Depreciation PROBLEM Depreciation is a decrease in the value over time of some asset due to wear and tear, decay, declining price,
Solving Problems Recursively
Solving Problems Recursively Recursion is an indispensable tool in a programmer s toolkit Allows many complex problems to be solved simply Elegance and understanding in code often leads to better programs:
PHP Tutorial From beginner to master
PHP Tutorial From beginner to master PHP is a powerful tool for making dynamic and interactive Web pages. PHP is the widely-used, free, and efficient alternative to competitors such as Microsoft's ASP.
Chapter 9 Text Files User Defined Data Types User Defined Header Files
Chapter 9 Text Files User Defined Data Types User Defined Header Files 9-1 Using Text Files in Your C++ Programs 1. A text file is a file containing data you wish to use in your program. A text file does
