Smoking is prohibited 1 CS 101 Second Exam Review Prepared by Dr. Amer Al-Badarneh 

Slides:



Advertisements
Similar presentations
Programming In C++ Spring Semester 2013 Lecture 3 Programming In C++, Lecture 3 By Umer Rana.
Advertisements

Do-while Loops Programming. COMP102 Prog Fundamentals I: do-while Loops /Slide 2 The do-while Statement l Syntax do action while (condition) l How it.
Dr. Yang, Qingxiong (with slides borrowed from Dr. Yuen, Joe) LT4: Control Flow - Loop CS2311 Computer Programming.
Basic Control Structures Control order of execution of statements sequential selection iteration - Repeat some action while a certain condition is true.
Branching Constructs Review l what are branching constructs? what type of branching constructs have we studied? l what is nested if? l what is multiway.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
A loop is a repetition control structure. it causes a single statement or block to be executed repeatedly What is a loop?
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
1 9/28/07CS150 Introduction to Computer Science 1 Loops section 5.2, 5.4, 5.7.
1 10/20/08CS150 Introduction to Computer Science 1 do/while and Nested Loops Section 5.5 & 5.11.
1 10/11/06CS150 Introduction to Computer Science 1 do/while and Nested Loops.
CS150 Introduction to Computer Science 1
Chapter 6 - Repetition. Introduction u Many applications require certain operations to be carried out more than once. Such situations require repetition.
Switch structure Switch structure selects one from several alternatives depending on the value of the controlling expression. The controlling expression.
1 10/9/06CS150 Introduction to Computer Science 1 for Loops.
1 CS 192 Lecture 9 Winter 2003 December 19, 2003 Dr. Shafay Shamail.
Section 3 - Selection and Repetition Constructs. Control Structures 1. Sequence 2. Selection 3. Repetition.
For Repetition Structures (L13) * General Form of the for Statement * Components of a Typical for Header * Pre/Postincrement of the Counter * Stream Manipulator.
Chapter 4: Looping. Resource: Starting Out with C++, Third Edition, Tony Gaddis 5.1 The Increment and Decrement Operators ++ and -- are operators that.
Lecture 4 Introduction to Programming. if ( grade ==‘A’ ) cout
Quiz Answers 1. Show the output from the following code fragment: int a = 5, b = 2, c = 3; cout
Mr. Dave Clausen1 La Cañada High School Chapter 6: Repetition Statements.
Copyright © Nancy Acemian 2004 For Loops-Break-Continue COMP For loop is a counter controlled loop. For loop is a pretest loop. Used when number.
Visual Basic.net Loops. Used to do multiple executions of the same block of code Do while loops Do until loops For next loops.
Previously Repetition Structures While, Do-While, For.
1 Chapter 9 Additional Control Structures Dale/Weems.
1 Additional Control Structures. 2 Chapter 9 Topics  Switch Statement for Multi-way Branching  Do-While Statement for Looping  For Statement for Looping.
Chapter 4 Loops Write code that prints out the numbers Very often, we want to repeat a (group of) statement(s). In C++, we have 3 major ways of.
Current Assignments Homework 2 is available and is due in three days (June 19th). Project 1 due in 6 days (June 23 rd ) Write a binomial root solver using.
Chapter 7 Additional Control Structures. 2 2 void GetYesOrNo (/* out */ char& response) // Inputs a character from the user // Postcondition: response.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 7 Clicker Questions September 22, 2009.
Lecture 4 Looping. Building on the foundation Now that we know a little about  cout  cin  math operators  boolean operators  making decisions using.
1 09/20/04CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
GAME102 - INTRO WHILE LOOPS G. MacKay. Fundamental Control Structures  STRAIGHT LINE  CONDITIONAL  LOOPS.
Looping Construct or Statements. Introduction of looping constructs In looping,a sequence of statements are executed until some condition for termination.
Overview Go over parts of quiz? Another iteration structure for loop.
Introduction to Loops Iteration Repetition Counting Loops Also known as.
CPS120 Introduction to Computer Science Iteration (Looping)
Repetition Statements (Loops) The do while Loop The last iteration structure in C++ is the do while loop. A do while loop repeats a statement or.
11/10/2016CS150 Introduction to Computer Science 1 Last Time  We covered “for” loops.
1 For Loops l From Chapter 9 l A shorthand way of coding count loops.
1 Programming in C++ Dale/Weems/Headington Chapter 9 Additional Control Structures (Switch, Do..While, For statements)
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.
Repetition Statements (Loops). 2 Introduction to Loops We all know that much of the work a computer does is repeated many times. When a program repeats.
LECTURE # 8 : REPETITION STATEMENTS By Mr. Ali Edan.
Copyright 2006 Addison-Wesley Brief Version of Starting Out with C++ Chapter 5 Looping.
Chapter 4 Repetition Statements Program Development and Design Using C++, Third Edition.
CONTENTS Loop Statements Parts of a loop Types of Loops Nested Loops
Loop Design What goes into coding a loop. Considerations for Loop Design ● There are basically two kinds of loops: ● Those that form some accumulated.
Computer Programming -1-
T/F  The following code will compile without error. int x = 3, y = 4, z = 5; double k = 3.4; cout
Slides by Evan Gallagher
Slides by Evan Gallagher
Chapter 9 Repetition.
Programming Loops (continued).
REPETITION CONTROL STRUCTURE
Chapter 4 – Control Structures Part 1
Programming Fundamentals
For Loops October 12, 2017.
Looping and Repetition
For & do/while Loops.
Chapter 9 Control Structures.
Counting Loops.
3 Control Statements:.
Let’s all Repeat Together
2.6 The if/else Selection Structure
do/while Selection Structure
Repetition Statements (Loops) - 2
CS 101 First Exam Review.
Programming Fundamental
Presentation transcript:

Smoking is prohibited 1 CS 101 Second Exam Review Prepared by Dr. Amer Al-Badarneh 

Smoking is prohibited 2MC-1  What is the output of the following code? int j = 1; while (j < 10) { cout << j << " "; j = j + j%3; }  a  b  c  d

Smoking is prohibited 3MC-2  What is the output of the following code? int count = 7; while ( count >= 4 ) cout << count--; cout << ”0”;  a  b  c  d

Smoking is prohibited 4MC-3  What is the output of the following code? int k = 4; while (k >= 1) cout << k--;  a.432  b.4321  c  d.infinity

Smoking is prohibited 5MC-4  What is the output of the following code? int i = 1; while ( i = 5 ) { ++i; cout << i << endl; }  a  b.1234  c.123  d.66666… for infinity

Smoking is prohibited 6MC-5  What is the output of the following code? int i = 1, s = 0; while ( i < 5 ) { s = s + i; i = i + 1; } cout << i << s;  a.610  b.611  c.511  d.510

Smoking is prohibited 7MC-6  What is the output of the following code? int j; for (j = 0; j < 5; ) { cout << j; j++ ; }  a  b.Nothing  c  d … for infinity.

Smoking is prohibited 8MC-7  What is the output of the following code? for(int j = 10; j > 5; j--) cout << j << " ";  a  b  c  d

Smoking is prohibited 9MC-8  What will happen if you try to compile and run the following code? int a =1; for( ; ; ) { if (a > 5) break; cout << a++; }  a. Creates a syntax error  b. Nothing will print  c. Printing out  d. Infinity loop

Smoking is prohibited 10MC-9  What is the output of the following code? for (int i = 1; i <= 5; i++) { if( i > 3 )break; elsecontinue; cout << i; }  a  b.1234  c.4  d.nothing

Smoking is prohibited 11MC-10  What is the output of the following code? int x = 1; for(;;) { if(x%4 == 0) break; cout << x; x++; }  a.1234  b.123  c.1  d.infinite loop

Smoking is prohibited 12MC-11  What is the output of the following code? for int (i = 0; i < 10; i++); cout << i%2;  a  b  c.0  d.1

Smoking is prohibited 13MC-12  What is the output of the following code? int k = 1, s = 0; for( ; k <= 8; k *= 2, s += k); cout << s;  a  b.14  c.30  d.0

Smoking is prohibited 14MC-13  What is the output of the following code? int i, sum = 0; for (i = 1; i < 5; i += 1) sum = sum + i; cout << sum;  a.0  b.15  c.10  d.1

Smoking is prohibited 15MC-14  Select the for statement that is equivalent to the following for statement: for (j = 0; j < 8; j++)  a. for (k = 8; k > 1; k -= 1)  b. for (k = 8; k >= 0; k -= 1)  c. for (k = 8; k > 0; k -= 1)  d. for (k = 8; k >= 1; k -= 1)

Smoking is prohibited 16MC-14  The following for loop: for (int i = 4 ; i < 9 ; i++) cout << ”x”;  a.will print ‘x’ 4 times.  b.will print ‘x’ 5 times.  c.will print ‘x’ 6 times.  d.will print ‘x’ repeatedly due to an endless loop.  e.will not compile because braces are missing.

Smoking is prohibited 17MC-15  What is the output of the following code?  int i, j; for (i=0, j=8; i<8; i++, j--) cout<<i<<"+"<<j<<"="<<i+j<<endl;  0+8=8  1+7=8  2+6=8  3+5=8  4+4=8  5+3=8  6+2=8  7+1=8

Smoking is prohibited 18MC-16  What is the output of the following code? int i, j; for ( i = 0; i < 2; ++i ) for ( j = 0; j < 5; ++j ) cout << i << " " << j << endl;  0 0  0 1  0 2  0 3  0 4  1 0  1 1  1 2  1 3  1 4

Smoking is prohibited 19MC-17  What is the output of the following code? int i; for(i = 1; i <= 5; i++) cout << i << i%2 << endl;  11  20  31  40  51

Smoking is prohibited 20MC-18  Write a C++ program to display the following B BB BBB BBBB BBBBB  #include  #include  void main(){  int i, j;  for(i = 1; i <= 5; i++){  for(j = 1; j <= i; j++)  cout << ‘B’;  cout << endl;  } }}}}

Smoking is prohibited 21MC-19  What three parts of a counting loop must be coordinated in order for the loop to work properly?  a. initializing the counter, testing the counter, changing the counter  b. initializing the condition, changing the condition, terminating the loop  c. the while, the assignment, and the loop body  d. the while statement, the if statement, and sequential execution.

Smoking is prohibited 22MC-20  What makes a loop a counting loop?  a. A loop control variable is tested in the while statement, and is changed each time the loop body executes.  b. A counter is counted upwards by one until it hits a particular limit.  c. A counter is counted downwards by one until it hits zero.  d. No loop control variables are used.

Smoking is prohibited 23MC-21  What does this code print on the monitor? int count = 0; while ( count <= 6 ) { cout << count + " "; count = count + 2; }  a  b  c  d

Smoking is prohibited 24MC-22  What does this code print on the monitor? int count = 7; while ( count >= 4 ) { cout << count + " "; count = count - 1; }  a  b  c  d

Smoking is prohibited 25MC-23  What does this code print on the monitor? int count = -2 ; while ( count < 3 ) { cout << count + " "; count = count + 1; }  a  b  c  d

Smoking is prohibited 26MC-24  What does this code print on the monitor? int count = 1; while ( count < 5 ) { cout << count + " "; }  a  b  c  d

Smoking is prohibited 27MC-25  What condition should be used so that the code writes out: int count = 1; while ( ___________ ) { cout << count + " "; count = count + 1; }  a. count < 8  b. count < 9  c. count+1 <= 8  d. count != 8