a) A Computer with specifically C++ compiler installed b) Sumita arora (Text book) c) Herbert Scheldt fundamentals of c++

Size: px
Start display at page:

Download "a) A Computer with specifically C++ compiler installed b) Sumita arora (Text book) c) Herbert Scheldt fundamentals of c++"

Transcription

1 BLOOM PUBLIC SCHOOL Vasant Kunj, New Delhi Lesson Plan Class XI Subject Computer Science Month July-August No of Periods 19 Chapter (Programming methodology and Flow of control) TTT 7 WT 12 Contents Learning Objectives Resources At the end of this chapter the students will be able to Classify C++ Statements into Selection Statements, Sequential Statements, Iterative Statements Write Selection Statements with various Flow Control Structures ( if, switch ) Write Iterative Statements with various Looping Structures ( for, while, do-while ) Apply Jump Statements ( goto, break, continue, exit( )) a) A Computer with specifically C++ compiler installed b) Sumita arora (Text book) c) Herbert Scheldt fundamentals of c++ Assessment Class Test Period wise Plan Period 1 and 2 Statements The teacher explains that Statement are the instructions given to the computer to perform any kind of action, be it data movement, be it making decision or be it repeating action. The simplest statement is empty or null statement. It takes the following form // It is a null statement These are the statements where syntax requires presence but logic of the program does not. 1

2 Compound Statement ( Block ) A compound statement in C++ is a sequence of statements enclosed by a pair of braces. For instance,... Represents a compound statement. It is also called a block Period 3 and 4 Statement Flow Control In a program, statement may be executed sequentially, selectively or iteratively. Sequence The sequence constructs means the statements are executed sequentially the sequence in which they have been written. This is the default flow of statement. Statement Statement Every C++ program begins with the first statement of main ( ) and ends with the last statement of main ( ). Therefore main is called the driver function. Statement Selection The selection construct means the execution of statements depending upon a conditiontest. If the condition test evaluates to true, a course of action is followed otherwise another course of action is followed. The construct is also called decision-making construct. One course of action Condition? true Statement 1 Statement 2 false Statement 1 Period 5 and 6 Another course of action Statement 2 Iteration The Iteration construct means repetition of a set of statements depending upon a condition. Till the time the condition is true (or false depending upon loop), a set of statements is repeated. As soon as the condition becomes false ( or true), the repetition stops. The iteration construct is called looping construct. Condition? false The exit condition true Statement 1 Statement 2 The loop body 2

3 The set of statements executed again and again is called the body of the loop. The condition on which the execution or exit of the loop depends is called the exit condition or test condition In C++ non-zero value is a true value including negative numbers. A false value is 0. Period 7 and 8 Selection Statements C++ provided two types of selection statements if and switch. In addition, in certain circumstances? operator can be used as an alternative to if statement. The selection statements are also called conditional statements. The syntax is as shown below if ( expression ) statement; where a statement may consist of a single statement, a compound statement, or nothing (in case of empty statement ). The expression must be enclosed in parenthesis. If the expression evaluates to true i.e. a nonzero value, the statement is executed, otherwise ignored. For instance, the following code fragment. If ( ch == ) spaces++ ; checks whether the character variable ch stores a space or not; if it does, the number of spaces are incremented by 1. Consider another example illustrating the use of if statement char ch; cin>>ch; if ( ch == ) cout<< You entered a space << \n ; if ( ch>= 0 && ch <= 9 ) cout<< You entered a digit << \n ; The above example reads a character. If the character input is a space, it flashes a message specifying it. If the character input is a digit, it flashes a message specifying it. The following example also makes use of an if statement. int A, B, C; cin>> A >> B ; if ( A > 10 && B < 15 ) C = ( A B ) * ( A + B ) ; cout<< The result is << C<< \n ; The above statement uses a compound statement (or a block) in the body of it. All the examples allow to execute a set of statements if a condition or expression evaluates to true. What if there is another course of action to be followed if the expression evaluates to false. The other form of if is if ( expression ) if the expression is true a non zero value, the statement 1 is executed, otherwise statement 2 is executed. 3

4 Test false Test expression false body of if true body of if true body of Period 9 and 10 Nested ifs A nested if is an if that has another if in its if s body or in its s body. The nested if can have one of the following three forms 1. if (expression1) If ( expression 2) [ Statement 2;] body of ; 2. if (expression 1) body of if; if ( expression 2) [ ] 3. if (expression 1) If ( expression 2 ) Statement 1; [ Statement 2;] if (expression 3) statement3; [ statement 4;] 4

5 The nested if- statement introduces a source of potential ambiguity referred to as dangling problem. This problem arises when in a nested if statement number of ifs is more than the number of clauses. In the example below if (ch >= A ) if ( ch <= Z ) ++upcase; ++others; The indentation indicates that programmer wants the to be with the outer of. However, C++ matches an with the preceding unmatched if. In this case, the actual evaluation of the if statement will be shown below If (ch >= A ) If (ch<= Z ) ++upcase; ++others; That is, if the inner expression is false, i.e. zero then the clause gets executed. In nested if statement, a dangling statement goes with the preceding unmatched if statement. In an expression such as this If (expr 1) If ( expr 2) the last statement goes with the immediately preceding if statement does not already have an statement. Here statement 2 is executed if expr 2 evaluates to false. However, if we have a code as follows if (expr 1) if ( expr 2) statement 3; the inner goes with immediately preceding unmatched if which is the inner if. The outer goes with immediately preceding unmatched if which is now outer if as the inner if is unmatched. Thus, statement 3 gets executed if exp1 is false. What if you want to override the default dangling- matching? That is if you have a code as shown below If( expr 1) If ( expr 2) Statement 1; Statement; 5

6 And you want the to go with the outer if ( By default it will go with the inner if ) then use braces to override rge default dangling matching. If (expr 1) If( expr 2) Statement1; Statement2; ANSI standard specifies that at least 15 levels of nesting must be supported by a compiler The if--if ladder It is commonly called the if--if staircase because of its appearance. if ( expression 1 ) if ( expression 2 ) if ( expression 3 ) statement 3; statement n; The? alternative to if As studied in Chapter 6, the conditional operator? can be used to replace if- statements of the general form If ( expression 1) Statement 2; This can be alternatively written using? as follows Expression 1? statement 1 statement 2 Period 11 and 12 Comparing if and? 1. Compared to if- sequence,? offer more concise, clean and compact code, but it is obvious as compared to if. 2. Another difference is that the? operator produces an expression, hence a single value can be assigned or incorporated into larger expression, whereas, if is more flexible. 3. When? operator is used in its nested form, it becomes complex and difficult to understand 4.? has a very low precedence. The switch statement C++ provides a multiple branch selection known as switch. This selection statement successively tests the value of an expression against a list of integer or character constants. When a match if found, the statements associated with that constant are executed. switch ( expression ) case constant1 statement sequence 1; 6

7 case constant 2 statement sequence 1; case constant n-1 statement sequence 1; [ default statement sequence n;] The expression is evaluated and its values are matched against the values of the constants specified in the case statements. When a match is found, the statement sequence associated with the case is executed until the break statement or the end of switch statement is reached. The default statement gets executed when no match is found. The default statement is optional and, if it is missing, no action takes place if all matched fail. ANSI standard specifies that at a switch can have upto 257 case statements; however you must limit the number of case statements to a smaller amount for the sake of efficiency. A case statement cannot exist by itself, outside of a switch. The break statement is a jump statement ( we will discuss later in the same chapter ) The switch Vs. if- The switch and. if- both are selection statements and they both let you select an alternative out of given many alternatives by testing an expression. 1. The switch can only test for equality whereas if can evaluate a relational or logical expression i.e. multiple conditions. 2. The switch statement selects its branches by testing the value of same variable (against a set of constants) whereas the if- construction lets you use a series of expressions that may involve unrelated variables and complex expressions. 3. The if- is more versatile of the two statements. For instance, if- can handle ranges whereas switch cannot. Each switch case label must be a single value. 4. the if- statement can handle floating-point tests also apart from handling integer and character tests whereas a switch cannot handle floating-point tests. The case labels of switch must be an integer ( which includes char also ) 5. The switch label must be a constant. So, if two or more variables are to be compared, use if-. 6. The switch statement is more efficient choice in terms of code used in situation that supports the nature of witch operation. Period 11 and 12 The Nested Switch Like if statements, a switch statement can also be nested. There can be a switch as part of the statement sequence of another switch. For instance, switch ( a ) case 1 switch ( b ) case 0 cout<< Divide by zero Error!! case 1 res = a / b; breakl case 2 7

8 Some important things to know about switch 1. A switch statement can only work for equality comparisons. 2. No two case labels in the same switch can have identical values. In case of nested switch statements the case constants of the inner and outer switch can contain common values. 3. If character constants are used in the switch statement, they are automatically converted to their integers( ASCII codes ) 4. The switch statement is more efficient than if in a situation that supports the nature of switch operation. 5. Switch is more efficient than nested if- statement. Iteration Statements Every loop has four elements that have different purposes. These are a) Initialization Expression(s) Before entering a loop, its control variable( s) must be initialized. This initialization of the control variable (s) takes place under initialization expression (s). This gives variable( s) their first value(s). The initialization expression(s) is executed only once, in the beginning. b) Test Expression The test expression is an expression whose truth values decided whether the loop-body will be executed or not. If the test expression evaluates to true, i.e., 1 the loop-body gets executed otherwise the loop is terminated. The entry-controlled loop, the test expression is evaluated before entering into a loop whereas in an exit-controlled loop, the test expression is evaluated before exiting from the loop. In C++, the for loop and while loop are entry-controlled loops and do-while loop is exit-controlled loop. c) Update Expression(s) The update expression(s) change the value(s) of loop variable(s). The update expression(s) is executed; at the end of the loop after the loop-body is executed. d) The body-of-the-loop The statements that are executed repeatedly ( as long as the test expression is non-zero) form the body of the loop. In an entry-controlled loop, first the testexpression is evaluated and if it is non-zero, the body of the loop is executed, if the test-expression evaluates to zero, the loop is terminated. In an exit-controlled loop, the body of the loop is executed and then the test-expression is evaluated. If it evaluates to be zero, the loop is terminated, otherwise repeated. Period 13 and 14 The for Loop The general form (syntax) of the for loop statement is for ( initialization expression(s) ; test-expression ; update expression(s) ) body-of-the-loop; void main( ) int i; for( i =1 ; I <= 10 ; ++ i ) cout << \n << i; Working of the for loop initialization test-expression update expression(s) expression(s) for( i = 1 ; i <= i ) cout << \n << i; 1.Firstly, initialization expression is executed, i.e. i =1 which gives the first value 1 to variable i; 8

9 2.Then, the test-expression evaluated i.e. i <= 10 which results into true i.e. 1; 3. Since the test-expression is true, the body of the loop i.e. cout << \n << i is executed which prints the current value of i on the next line. 4. After executing the loop-body, the update expression i.e. ++ I is executed which increments the value of i. 5. After the update expression is expression is executed, the test-expression is again evaluated. If it is true the sequence is repeated from step 3 otherwise the loop terminates. / followed by Dry Run initialization expression(s) testexpressio False Ex Variations of for Loop True Body of the Loop 1. Multiple initialization and update Expressions 2. Optional Expressions update expression(s) 3. Infinite Loop 4. Empty Loop Scope of a variable A variable declared in a for or while loop can be accessed after the statement because the variable declaration has not taken place within the braces of the loop block, the item will be in scope when the loop terminates. That means the same variable cannot be declared in the same scope. The while Loop This is an entry-controlled loop. The syntax is while ( expression ) loop-body where the loop-body may contain a single statement, a compound statement or an empty statement. The loop iterates while the expression evaluates to true. When the expression becomes fals, the program control passes to the line after the loop-body code. In a while loop, a loop control variable should be initialised before the loop begins as an uninitialised variable can be used in an expression. The loop variable should be updated inside the body of the loop. Variations of for Loop 1.empty loop 2. infinite loop The do-while Loop This is an exit-controlled loop. It evaluates the test-expression at the bottom of the loop after executing its loop-body statements. This means that do-while loop always executes at least once. 9

10 CW Nested Loops A loop may contain another loop in its body. This form is called nested loop. But in a nested loop, the inner must terminate before the outer loop. Comparison of Loops When you know the number of times the loop has to iterate, for loop is the best choice. When you do not want the loop to be executed even once without the condition getting checked, while loop is the preferred choices. When you want that the loop can be executed at least once before the condition being checked, do-while is the preferred choice. Jump Statements These statements unconditionally transfer program control within a function. C++ has four statements that perform an unconditional branch return, goto, break, continue. The goto statement With this statement, we can transfer the program control anywhere in the program. The target destination of a goto statement is marked by a label. The syntax is goto label; label If a label appears just before a closing brace, a null statement must follow the label. A goto statement may not jump forward a variable definition. Period 15 and 16 The break Statement This enables a program o skip over part of the code. A break statement terminates the smallest enclosing while, do-while, for, or switch statement. Execution resumes at the statement immediately following the body of the terminated statement. while ( test expression ) Statement; if ( val > 2000 ) for ( int; expression ; update) Statement 1; If ( val > 2000) Statement 3; do Statement 1; If ( val > 2000) while( test expression); Statement 3; 10

11 Statement 2; Statement 3; A break used in a switch statement will affect only that switch i.e. it will terminate only the very switch it appears in. It does not affect any loop the switch happens to be in. The continue Statement The continue is another jump statement like the break statement. But the continue statement is somewhat different from break. Instead of forcing termination, it forces iteration of the loop to take place, skipping any code in between. while ( test expression ) Statement; if ( condition ) continue; Statement 2; Statement 3; for ( int; expression ; update) Statement 1; If ( condition) continue; Statement 3; do Statement 1; If ( condition) continue; while( test expression); Statement 3; Period 17 and 18 The exit ( ) Function This causes the program to terminate as soon as it is encountered, no matter where it appears in the program listing. This function does not have any return value. Its argument is returned to he operating system. This value can be tested in batch files where ERROR LEVEL gives you the return value provided by exit function. Generally the value 0 signifies a successful termination and any other number indicates some error. This function is defined in a header file process.h, which must be included in a program that uses exit( ) function. Important question covered as a concept Q1. ) what is entry control and exit control loop? Q2.) What is the result of if condition ending with ; semicolon. (Q3.) Explain the if statement? (Q4.) Give an example of a test condition comparing it with a literal using If construct? (Q5.) What is the following segment checking? if (ch=' ') Spaces ++; (Q6.) What is the syntax of the if statement? 11

12 (Q7.) What does iteration mean? (Q8.) How is a block statement written? (Q9.) When is a null or empty statement required? (Q10.) What is nested if? Part 2 Mention two differences between if and conditional operator? (Q2.) What is the Nested if structure? (Q3.) Explain the update expression in the for loop? (Q4.) How can the statements of a program be executed? (3 Marks) (Q5.) Elaborate the structure of a Switch statement? (3 Marks) (Q6.) State any three differences between switch statement and if- statement? (3 Marks) (Q7.) What is the difference between if- and switch? Part 3 (Q1.)List the variations of the While loop? (5 Marks) (Q2.) In the following segment, can the loop mentioned, be used as time delay loop? Lwait=0; while(++lwait<500000) ; ; 12

13 (Q4.) Explain S1, R and R2 in the following for loop statement? for(s1;r;r2) (Q3.) Display the output of the following program. int i=10; while(i>=6) cout << i < < endl ; i - -; i - -; (Q5.) Give examples of 3 test conditions which work with If. a) comparing a literal b) comparing 2 variables c) testing truth value of a variable (Q6.) List any 3 variations in the for loop? (3 Marks) (Q7.) Write a program to evaluate the factorial of a number? Period 19 Class Test 13

9 Control Statements. 9.1 Introduction. 9.2 Objectives. 9.3 Statements

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

More information

Two-way selection. Branching and Looping

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.

More information

6. Control Structures

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,

More information

While Loop. 6. Iteration

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

More information

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

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

More information

13 Classes & Objects with Constructors/Destructors

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.

More information

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C Embedded Systems A Review of ANSI C and Considerations for Embedded C Programming Dr. Jeff Jackson Lecture 2-1 Review of ANSI C Topics Basic features of C C fundamentals Basic data types Expressions Selection

More information

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 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

More information

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)

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

More information

Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void

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

More information

What is a Loop? Pretest Loops in C++ Types of Loop Testing. Count-controlled loops. Loops can be...

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

More information

Selection Statements

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:

More information

Chapter One Introduction to Programming

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

More information

Object Oriented Software Design

Object Oriented Software Design Object Oriented Software Design Introduction to Java - II Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 28, 2010 G. Lipari (Scuola Superiore Sant Anna) Introduction

More information

Writing Control Structures

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

More information

Object Oriented Software Design

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

More information

Lecture 2 Notes: Flow of Control

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

More information

JavaScript: Control Statements I

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

More information

Conditions & Boolean Expressions

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

More information

Java Interview Questions and Answers

Java Interview Questions and Answers 1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write and compile the java

More information

Statements and Control Flow

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

More information

C++ INTERVIEW QUESTIONS

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

More information

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON PROBLEM SOLVING WITH SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON Addison Wesley Boston San Francisco New York London

More information

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas

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

More information

Pseudo code Tutorial and Exercises Teacher s Version

Pseudo code Tutorial and Exercises Teacher s Version Pseudo code Tutorial and Exercises Teacher s Version Pseudo-code is an informal way to express the design of a computer program or an algorithm in 1.45. The aim is to get the idea quickly and also easy

More information

Conditionals (with solutions)

Conditionals (with solutions) Conditionals (with solutions) For exercises 1 to 27, indicate the output that will be produced. Assume the following declarations: final int MAX = 25, LIMIT = 100; int num1 = 12, num2 = 25, num3 = 87;

More information

Appendix K Introduction to Microsoft Visual C++ 6.0

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):

More information

Tutorial on C Language Programming

Tutorial on C Language Programming Tutorial on C Language Programming Teodor Rus rus@cs.uiowa.edu The University of Iowa, Department of Computer Science Introduction to System Software p.1/64 Tutorial on C programming C program structure:

More information

Chapter 5. Selection 5-1

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

More information

UEE1302 (1102) F10 Introduction to Computers and Programming

UEE1302 (1102) F10 Introduction to Computers and Programming Computational Intelligence on Automation Lab @ NCTU UEE1302 (1102) F10 Introduction to Computers and Programming Programming Lecture 03 Flow of Control (Part II): Repetition while,for & do..while Learning

More information

Chapter 5 Programming Statements. Chapter Table of Contents

Chapter 5 Programming Statements. Chapter Table of Contents Chapter 5 Programming Statements Chapter Table of Contents OVERVIEW... 57 IF-THEN/ELSE STATEMENTS... 57 DO GROUPS... 58 IterativeExecution... 59 JUMPING... 61 MODULES... 62 Defining and Executing a Module....

More information

VB.NET Programming Fundamentals

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

More information

Stacks. Linear data structures

Stacks. Linear data structures Stacks Linear data structures Collection of components that can be arranged as a straight line Data structure grows or shrinks as we add or remove objects ADTs provide an abstract layer for various operations

More information

Notes on Algorithms, Pseudocode, and Flowcharts

Notes on Algorithms, Pseudocode, and Flowcharts Notes on Algorithms, Pseudocode, and Flowcharts Introduction Do you like hot sauce? Here is an algorithm for how to make a good one: Volcanic Hot Sauce (from: http://recipeland.com/recipe/v/volcanic-hot-sauce-1125)

More information

Basics of I/O Streams and File I/O

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

More information

Chapter 8 Selection 8-1

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

More information

Passing 1D arrays to functions.

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,

More information

COMP 110 Prasun Dewan 1

COMP 110 Prasun Dewan 1 COMP 110 Prasun Dewan 1 12. Conditionals Real-life algorithms seldom do the same thing each time they are executed. For instance, our plan for studying this chapter may be to read it in the park, if it

More information

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. Exam Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) The JDK command to compile a class in the file Test.java is A) java Test.java B) java

More information

Flowchart Techniques

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

More information

Scoping (Readings 7.1,7.4,7.6) Parameter passing methods (7.5) Building symbol tables (7.6)

Scoping (Readings 7.1,7.4,7.6) Parameter passing methods (7.5) Building symbol tables (7.6) Semantic Analysis Scoping (Readings 7.1,7.4,7.6) Static Dynamic Parameter passing methods (7.5) Building symbol tables (7.6) How to use them to find multiply-declared and undeclared variables Type checking

More information

PL/SQL Overview. Basic Structure and Syntax of PL/SQL

PL/SQL Overview. Basic Structure and Syntax of PL/SQL PL/SQL Overview PL/SQL is Procedural Language extension to SQL. It is loosely based on Ada (a variant of Pascal developed for the US Dept of Defense). PL/SQL was first released in ١٩٩٢ as an optional extension

More information

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?

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

More information

MATLAB Programming. Problem 1: Sequential

MATLAB Programming. Problem 1: Sequential Division of Engineering Fundamentals, Copyright 1999 by J.C. Malzahn Kampe 1 / 21 MATLAB Programming When we use the phrase computer solution, it should be understood that a computer will only follow directions;

More information

The C++ Language. Loops. ! Recall that a loop is another of the four basic programming language structures

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

More information

The While Loop. Objectives. Textbook. WHILE Loops

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

More information

Informatica e Sistemi in Tempo Reale

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)

More information

The C Programming Language course syllabus associate level

The C Programming Language course syllabus associate level TECHNOLOGIES The C Programming Language course syllabus associate level Course description The course fully covers the basics of programming in the C programming language and demonstrates fundamental programming

More information

Outline. Conditional Statements. Logical Data in C. Logical Expressions. Relational Examples. Relational Operators

Outline. Conditional Statements. Logical Data in C. Logical Expressions. Relational Examples. Relational Operators Conditional Statements For computer to make decisions, must be able to test CONDITIONS IF it is raining THEN I will not go outside IF Count is not zero THEN the Average is Sum divided by Count Conditions

More information

Moving from CS 61A Scheme to CS 61B Java

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

More information

An Incomplete C++ Primer. University of Wyoming MA 5310

An Incomplete C++ Primer. University of Wyoming MA 5310 An Incomplete C++ Primer University of Wyoming MA 5310 Professor Craig C. Douglas http://www.mgnet.org/~douglas/classes/na-sc/notes/c++primer.pdf C++ is a legacy programming language, as is other languages

More information

Sources: On the Web: Slides will be available on:

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,

More information

We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.

We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share. LING115 Lecture Note Session #4 Python (1) 1. Introduction As we have seen in previous sessions, we can use Linux shell commands to do simple text processing. We now know, for example, how to count words.

More information

C++ Language Tutorial

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

More information

Introduction to Java Applications. 2005 Pearson Education, Inc. All rights reserved.

Introduction to Java Applications. 2005 Pearson Education, Inc. All rights reserved. 1 2 Introduction to Java Applications 2.2 First Program in Java: Printing a Line of Text 2 Application Executes when you use the java command to launch the Java Virtual Machine (JVM) Sample program Displays

More information

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T) Unit- I Introduction to c Language: C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating

More information

Unix Shell Scripts. Contents. 1 Introduction. Norman Matloff. July 30, 2008. 1 Introduction 1. 2 Invoking Shell Scripts 2

Unix Shell Scripts. Contents. 1 Introduction. Norman Matloff. July 30, 2008. 1 Introduction 1. 2 Invoking Shell Scripts 2 Unix Shell Scripts Norman Matloff July 30, 2008 Contents 1 Introduction 1 2 Invoking Shell Scripts 2 2.1 Direct Interpretation....................................... 2 2.2 Indirect Interpretation......................................

More information

Computer Programming I

Computer Programming I Computer Programming I COP 2210 Syllabus Spring Semester 2012 Instructor: Greg Shaw Office: ECS 313 (Engineering and Computer Science Bldg) Office Hours: Tuesday: 2:50 4:50, 7:45 8:30 Thursday: 2:50 4:50,

More information

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.

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).

More information

High-Level Programming Languages. Nell Dale & John Lewis (adaptation by Michael Goldwasser)

High-Level Programming Languages. Nell Dale & John Lewis (adaptation by Michael Goldwasser) High-Level Programming Languages Nell Dale & John Lewis (adaptation by Michael Goldwasser) Low-Level Languages What are disadvantages of low-level languages? (e.g., machine code or assembly code) Programming

More information

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. 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

More information

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

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)

More information

1 Description of The Simpletron

1 Description of The Simpletron Simulating The Simpletron Computer 50 points 1 Description of The Simpletron In this assignment you will write a program to simulate a fictional computer that we will call the Simpletron. As its name implies

More information

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand:

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand: Introduction to Programming and Algorithms Module 2 CS 146 Sam Houston State University Dr. Tim McGuire Introduction To Computers And Java Chapter Objectives To understand: the meaning and placement of

More information

Computer Programming C++ Classes and Objects 15 th Lecture

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

More information

PL / SQL Basics. Chapter 3

PL / SQL Basics. Chapter 3 PL / SQL Basics Chapter 3 PL / SQL Basics PL / SQL block Lexical units Variable declarations PL / SQL types Expressions and operators PL / SQL control structures PL / SQL style guide 2 PL / SQL Block Basic

More information

Keil C51 Cross Compiler

Keil C51 Cross Compiler Keil C51 Cross Compiler ANSI C Compiler Generates fast compact code for the 8051 and it s derivatives Advantages of C over Assembler Do not need to know the microcontroller instruction set Register allocation

More information

Module 10. Coding and Testing. Version 2 CSE IIT, Kharagpur

Module 10. Coding and Testing. Version 2 CSE IIT, Kharagpur Module 10 Coding and Testing Lesson 23 Code Review Specific Instructional Objectives At the end of this lesson the student would be able to: Identify the necessity of coding standards. Differentiate between

More information

Example of a Java program

Example of a Java program Example of a Java program class SomeNumbers static int square (int x) return x*x; public static void main (String[] args) int n=20; if (args.length > 0) // change default n = Integer.parseInt(args[0]);

More information

Command Scripts. 13.1 Running scripts: include and commands

Command Scripts. 13.1 Running scripts: include and commands 13 Command Scripts You will probably find that your most intensive use of AMPL s command environment occurs during the initial development of a model, when the results are unfamiliar and changes are frequent.

More information

JavaScript: Introduction to Scripting. 2008 Pearson Education, Inc. All rights reserved.

JavaScript: Introduction to Scripting. 2008 Pearson Education, Inc. All rights reserved. 1 6 JavaScript: Introduction to Scripting 2 Comment is free, but facts are sacred. C. P. Scott The creditor hath a better memory than the debtor. James Howell When faced with a decision, I always ask,

More information

El Dorado Union High School District Educational Services

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.

More information

First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science

First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science First Java Programs V. Paúl Pauca Department of Computer Science Wake Forest University CSC 111D Fall, 2015 Hello World revisited / 8/23/15 The f i r s t o b l i g a t o r y Java program @author Paul Pauca

More information

Data Integrator. Pervasive Software, Inc. 12365-B Riata Trace Parkway Austin, Texas 78727 USA

Data Integrator. Pervasive Software, Inc. 12365-B Riata Trace Parkway Austin, Texas 78727 USA Data Integrator Event Management Guide Pervasive Software, Inc. 12365-B Riata Trace Parkway Austin, Texas 78727 USA Telephone: 888.296.5969 or 512.231.6000 Fax: 512.231.6010 Email: info@pervasiveintegration.com

More information

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals 1 Recall From Last Time: Java Program import java.util.scanner; public class EggBasket { public static void main(string[]

More information

C Language Tutorial. Version 0.042 March, 1999

C Language Tutorial. Version 0.042 March, 1999 C Language Tutorial Version 0.042 March, 1999 Original MS-DOS tutorial by Gordon Dodrill, Coronado Enterprises. Moved to Applix by Tim Ward Typed by Karen Ward C programs converted by Tim Ward and Mark

More information

Conditional Statements. 15-110 Summer 2010 Margaret Reid-Miller

Conditional Statements. 15-110 Summer 2010 Margaret Reid-Miller Conditional Statements 15-110 Summer 2010 Margaret Reid-Miller Conditional statements Within a method, we can alter the flow of control (the order in which statements are executed) using either conditionals

More information

Member Functions of the istream Class

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,

More information

Object Oriented Software Design II

Object Oriented Software Design II Object Oriented Software Design II Introduction to C++ Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 20, 2012 G. Lipari (Scuola Superiore Sant Anna) C++ Intro February

More information

Database Programming with PL/SQL: Learning Objectives

Database Programming with PL/SQL: Learning Objectives Database Programming with PL/SQL: Learning Objectives This course covers PL/SQL, a procedural language extension to SQL. Through an innovative project-based approach, students learn procedural logic constructs

More information

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

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

More information

Answers to Review Questions Chapter 7

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

More information

C Programming. for Embedded Microcontrollers. Warwick A. Smith. Postbus 11. Elektor International Media BV. 6114ZG Susteren The Netherlands

C Programming. for Embedded Microcontrollers. Warwick A. Smith. Postbus 11. Elektor International Media BV. 6114ZG Susteren The Netherlands C Programming for Embedded Microcontrollers Warwick A. Smith Elektor International Media BV Postbus 11 6114ZG Susteren The Netherlands 3 the Table of Contents Introduction 11 Target Audience 11 What is

More information

IS0020 Program Design and Software Tools Midterm, Feb 24, 2004. Instruction

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

More information

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

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

More information

C PROGRAMMING FOR MATHEMATICAL COMPUTING

C PROGRAMMING FOR MATHEMATICAL COMPUTING UNIVERSITY OF CALICUT SCHOOL OF DISTANCE EDUCATION BSc MATHEMATICS (2011 Admission Onwards) VI Semester Elective Course C PROGRAMMING FOR MATHEMATICAL COMPUTING QUESTION BANK Multiple Choice Questions

More information

Eventia Log Parsing Editor 1.0 Administration Guide

Eventia Log Parsing Editor 1.0 Administration Guide Eventia Log Parsing Editor 1.0 Administration Guide Revised: November 28, 2007 In This Document Overview page 2 Installation and Supported Platforms page 4 Menus and Main Window page 5 Creating Parsing

More information

UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming

UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming 1 2 Foreword First of all, this book isn t really for dummies. I wrote it for myself and other kids who are on the team. Everything

More information

Exercise 4 Learning Python language fundamentals

Exercise 4 Learning Python language fundamentals Exercise 4 Learning Python language fundamentals Work with numbers Python can be used as a powerful calculator. Practicing math calculations in Python will help you not only perform these tasks, but also

More information

Calling the Function. Two Function Declarations Here is a function declared as pass by value. Why use Pass By Reference?

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

More information

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 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

More information

Iteration CHAPTER 6. Topic Summary

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

More information

The programming language C. sws1 1

The programming language C. sws1 1 The programming language C sws1 1 The programming language C invented by Dennis Ritchie in early 1970s who used it to write the first Hello World program C was used to write UNIX Standardised as K&C (Kernighan

More information

16. Recursion. COMP 110 Prasun Dewan 1. Developing a Recursive Solution

16. Recursion. COMP 110 Prasun Dewan 1. Developing a Recursive Solution 16. Recursion COMP 110 Prasun Dewan 1 Loops are one mechanism for making a program execute a statement a variable number of times. Recursion offers an alternative mechanism, considered by many to be more

More information

Paper 109-25 Merges and Joins Timothy J Harrington, Trilogy Consulting Corporation

Paper 109-25 Merges and Joins Timothy J Harrington, Trilogy Consulting Corporation Paper 109-25 Merges and Joins Timothy J Harrington, Trilogy Consulting Corporation Abstract This paper discusses methods of joining SAS data sets. The different methods and the reasons for choosing a particular

More information

Arrays. number: Motivation. Prof. Stewart Weiss. Software Design Lecture Notes Arrays

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

More information

ASCII Encoding. The char Type. Manipulating Characters. Manipulating Characters

ASCII Encoding. The char Type. Manipulating Characters. Manipulating Characters The char Type ASCII Encoding The C char type stores small integers. It is usually 8 bits. char variables guaranteed to be able to hold integers 0.. +127. char variables mostly used to store characters

More information

Lecture 5: Java Fundamentals III

Lecture 5: Java Fundamentals III Lecture 5: Java Fundamentals III School of Science and Technology The University of New England Trimester 2 2015 Lecture 5: Java Fundamentals III - Operators Reading: Finish reading Chapter 2 of the 2nd

More information