Example Problems for Exam#2 (covers chapters 5, 6, 7, 8, 9)

Slides:



Advertisements
Similar presentations
Repetition Statements Perform the same task repeatedly Allow the computer to do the tedious, boring things.
Advertisements

Programming In C++ Spring Semester 2013 Lecture 3 Programming In C++, Lecture 3 By Umer Rana.
Repetition Chapter 4: Control structures. Introduction to OOPDr. S. GANNOUNI & Dr. A. TOUIRPage 2 Loop Statements After reading and studying this Section,
True or false A variable of type char can hold the value 301. ( F )
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 4 – C Program Control Outline 4.1Introduction.
COMP 14 Introduction to Programming Mr. Joshua Stough February 16, 2005 Monday/Wednesday 11:00-12:15 Peabody Hall 218.
Introduction to Computers and Programming Lecture 9: For Loops New York University.
1 Parts of a Loop (reminder) Every loop will always contain three main elements: –Priming: initialize your variables. –Testing: test against some known.
1 CSE1301 Computer Programming Lecture 10: Iteration (Part 1)
4 Control Statements.
Chapter 6 - Repetition. Introduction u Many applications require certain operations to be carried out more than once. Such situations require repetition.
Introduction to Computers and Programming for Loops  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to.
FIT Objectives By the end of this lecture, students should: understand iteration statements understand the differences of for and while understand.
 2007 Pearson Education, Inc. All rights reserved C Program Control.
Loops Repetition Statements. Repetition statements allow us to execute a statement multiple times Often they are referred to as loops Like conditional.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
Chapter 5: Control Structures II (Repetition)
Exception Error handling. Exception 4 n An unusual occurrence during program execution that requires immediate handling n Errors are the most common type.
ספטמבר 04Copyright Meir Kalech1 C programming Language Chapter 2: Control Flow.
C How to Program, 6/e Summary © by Pearson Education, Inc. All Rights Reserved.
Chapter 5: Control Structures II (Repetition)
Lecture 4 C Program Control Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
CSCI 3328 Object Oriented Programming in C# Chapter 5: C# Control Statement – Part II UTPA – Fall
Control Structures Week Introduction -Representation of the theory and principles of structured programming. Demonstration of for, while,do…whil.
Chapter 4 C Program Control. Objectives In this chapter, you will learn: –To be able to use the for and do … while repetition statements. –To understand.
Repetition Statements.  Often it is necessary to repeat statements many times  Java has two ways of doing this  while statements  for statements.
Chapter 7 LOOPING OPERATIONS: ITERATION. Chapter 7 The Flow of the while Loop.
Chapter 5 Control Structure (Repetition). Objectives In this chapter, you will: Learn about repetition (looping) control structures Explore how to construct.
Chapter 5: Control Structures II (Repetition). Objectives In this chapter, you will: – Learn about repetition (looping) control structures – Learn how.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Flow Control (for) Outline 4.1Introduction 4.2The.
Looping Construct or Statements. Introduction of looping constructs In looping,a sequence of statements are executed until some condition for termination.
+ Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy Walters, and Godfrey Muganda Chapter 5: Looping.
Fundamental Programming Fundamental Programming for Loops.
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE Lecture 9 & 10 Repetition Statements.
Repetition Control Structure. Introduction Many applications require certain operations to be carried out more than once. Such situations require repetition.
1 Chapter 3: Loops and Logic. 2 Control Statements If statement Example NumberCheck.java Relational operators (, >=, ==, !=) Using code blocks with If.
Chapter 6 - Repetition. while Loop u Simplest loop u Two parts: test expression and loop body u Pre-tested loop –Execute loop body if test true –Bypass.
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
LECTURE # 8 : REPETITION STATEMENTS By Mr. Ali Edan.
Loops Tonga Institute of Higher Education. Introduction Programs need to be able to execute tasks repeatedly. Use loops to repeat actions  For Loop 
C Program Control September 15, OBJECTIVES The essentials of counter-controlled repetition. To use the for and do...while repetition statements.
Computer Programming -1-
Nested Loops, Break/Continue. Nested Loops Nested loops : loop inside a loop – Loop through rows and columns – Loop through every word in every file –
Chapter 9 Repetition.
Chapter 4 – C Program Control
UMBC CMSC 104 – Section 01, Fall 2016
Chapter 4 Repetition Statements (loops)
Chapter 4 C Program Control Part I
Lecture 7: Repeating a Known Number of Times
Review If you want to display a floating-point number in a particular format use The DecimalFormat Class printf A loop is… a control structure that causes.
Chapter 5: Looping Starting Out with C++ Early Objects Seventh Edition
JavaScript: Control Statements.
ITM 352 Flow-Control: Loops
MATLAB: Structures and File I/O
CSI 121 Structure Programming Language Lecture 10: Iteration (Part 1)
Chapter 5 Repetition.
Arrays, For loop While loop Do while loop
Programming Fundamentals Lecture #6 Program Control
MSIS 655 Advanced Business Applications Programming
Outline Altering flow of control Boolean expressions
Chapter 9 Control Structures.
Structured Program Development in C
Lab5 PROGRAMMING 1 Loop chapter4.
CHAPTER 21 LOOPS 1.
EPSII 59:006 Spring 2004.
1-6 Midterm Review.
Chapter 4 - Program Control
Chap 7. Advanced Control Statements in Java
Looping and Repetition
Presentation transcript:

Example Problems for Exam#2 (covers chapters 5, 6, 7, 8, 9) 1. What is the final value of ? after performing the following operations int x = 24; float y = 6.0; float z = 3.0; y = x / z; ? = 2.0 * y; (a) 12 (b) 12.0 (c) 16 (d) 16.0 ANS: (d)

2. What is the lowest value of the loop counter in a for statement with the following header? for ( i = 10; i >= 1; i -=1) a) 10 b) 9 c) 1 d) 0 ANS: (d)

3. An array containing 3 columns and 4 rows is typically referred to as a ________. a) 12-element array b) 3-by-4 array c) 13-element array, because of the zero element d) 4-by-3 array ANS: (d)

4. An incorrect final value in a loop counter (increment or decrement) or an incorrect relational operator in the conditional expression of a while or for loop statement frequently causes an __________error. off-by-one 5. The function body, is represented by _____ in the following function definition: W X(Y) {Z} (a) W (b) X (c) Y (d) Z ANS: (d)

6. The following array definition int n[4] = {51, 36, 22, 45, 17}; a) is correct b) causes a syntax error because there are only four initializers and five array elements. c) causes a logic error because there are only four elements but there are five initializers. d) causes a syntax error because there are five initializers but only four array elements. ANS: (d)

7. When exit is called with EXIT_SUCCESS exit(EXIT_SUCCESS); (a) the program quits immediately without returning anything (b) the program prints an exit_success message and quits the current function (c) the implementation defined value for normal termination is returned (d) the program breaks out of a loop ANS: (c)

8. Which statement of the following is correct? (a) #define X = 3 (b) #define X 3; (c) #define X 3 (d) #define X:3 ANS: (c)