11/10/2016CS150 Introduction to Computer Science 1 Last Time  We covered “for” loops.

Slides:



Advertisements
Similar presentations
CS107 Introduction to Computer Science Lecture 3, 4 An Introduction to Algorithms: Loops.
Advertisements

Chapter 3. Expressions and Interactivity CSC125 Introduction to C++
Computer Science 1620 Loops.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
1 9/24/07CS150 Introduction to Computer Science 1 Relational Operators and the If Statement.
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
1 CS150 Introduction to Computer Science 1 Arithmetic Operators.
CS 1400 Chapter 5, section 2. Loops! while (rel-expression)while (rel-expression) {statements statement } if the relational-expression is true, execute.
1 9/08/06CS150 Introduction to Computer Science 1 Arithmetic Operators.
1 10/9/06CS150 Introduction to Computer Science 1 for Loops.
1 CS150 Introduction to Computer Science 1 Relational Operators and the If Statement 9/22/08.
1 CS150 Introduction to Computer Science 1 Exponents & Output page & Section 3.8.
The If/Else Statement, Boolean Flags, and Menus Page 180
1 9/26/07CS150 Introduction to Computer Science 1 Exponents & Output page & Section 3.8.
Computer Arithmetic Programming in C++ Computer Science Dept Va Tech August, 2000 © Barnette ND, McQuain WD, Keenan MA 1 Independent Representation.
 For Loops › for (variable set; condition; incremental or decrement){ // loop beginning › } // loop end  While loops › while (condition) { // beginning.
 Wednesday, 9/18/02, Slide #1 CS106 Introduction to CS1 Wednesday, 9/18/02  QUESTIONS?? HW #1 due today at 5!!  Today: Loops, and two new data types.
First steps Jordi Cortadella Department of Computer Science.
1 09/20/04CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
1 Three C++ Looping Statements Chapter 7 CSIS 10A.
I/O and Data Formatting Introduction to Class Concepts INFSY 307 Spring 2003 Lecture 3.
111/15/2015CS150 Introduction to Computer Science 1 Summary  Exam: Friday, October 17,  Assignment: Wednesday, October 15, 2003  We have completed.
1 10/18/04CS150 Introduction to Computer Science 1 Functions Divide and Conquer.
Control Structures RepetitionorIterationorLooping Part I.
1 CS161 Introduction to Computer Science Topic #8.
1 09/27/04CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
1 10/3/05CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
1 CS 1430: Programming in C++. 2 Find Max, Min, Average of m Sections Max, Min and Average of each section Max, Min and Average of all sections together.
1 Manipulators manipulators are used only in input and output statements endl, fixed, showpoint, setw, and setprecision are manipulators that can be used.
REPETITION STATEMENTS - Part1  Also called LOOP STATEMENTS OR LOOP STRUCTURES 1 C++ Statements that repeat one or more actions while some condition is.
Think First, Code Second Understand the problem Work out step by step procedure for solving the problem (algorithm) top down design and stepwise refinement.
C++ Programming Lecture 14 Arrays – Part I The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
Chapter 05 (Part II) Control Statements: Part II.
13/15/2016CS150 Introduction to Computer Science 1 Summary  Assignment due on Wednesday, October 29,  Tutor will be in the lab on Tuesday evening,
Computer Skills2 / Scientific Colleges 1 Arrays Topics to cover: Arrays Data Types One-dimensional Arrays Two-dimensional Arrays.
C++ CODES PART#04 1 COPY ENGR.SABA MUGHAL FROM COMPUTER SYSTEMS DEPARTMENT.
CSCI 125 & 161 / ENGR 144 Lecture 6 Martin van Bommel.
Zhen Jiang Dept. of Computer Science West Chester University West Chester, PA CSC530 Data Structures - LOOP 7/9/20161.
Repetition Control Structure in C++ Program
for Repetition Structures
CS150 Introduction to Computer Science 1
Lecture 4B More Repetition Richard Gesick
CS 2308 Exam I Review.
CS 2308 Exam I Review.
Unary Operators ++ and --
CS 1430: Programming in C++ No time to cover HiC.
CS 2308 Exam I Review.
Counting Loops.
CS150 Introduction to Computer Science 1
CS150 Introduction to Computer Science 1
Formatting the Output The C++ standard library supplies many manipulators: endl, setw, fixed, showpoint, setprecesion. If we want to use endl, fixed, or.
CS150 Introduction to Computer Science 1
CS150 Introduction to Computer Science 1
Let’s all Repeat Together
switch Selection Structure
CS150 Introduction to Computer Science 1
CS150 Introduction to Computer Science 1
Functions Divide and Conquer
Let’s all Repeat Together
CS150 Introduction to Computer Science 1
do/while Selection Structure
CS150 Introduction to Computer Science 1
CS150 Introduction to Computer Science 1
Functions Divide and Conquer
Types of loops definite loop: A loop that executes a known number of times. Examples: Repeat these statements 10 times. Repeat these statements k times.
CS150 Introduction to Computer Science 1
Presentation transcript:

11/10/2016CS150 Introduction to Computer Science 1 Last Time  We covered “for” loops

21/10/2016CS150 Introduction to Computer Science 1 Localized Declarations for (int i = 0; i < n; i++) cout << i << endl; i is declared ONLY in the loop

31/10/2016CS150 Introduction to Computer Science 1 Rewrite using a while loop for (i = 5; i < 10; i+= 2) cout << i; What does this output?

41/10/2016CS150 Introduction to Computer Science 1 Formatting Output  How can we generate this output? Fahrenheit Celsius

51/10/2016CS150 Introduction to Computer Science 1 The Program float F,C; F = 32.0; cout << fixed << setprecision(3); cout << "Fahrenheit"; cout << "Celsius" << endl; while (F <= 212.0) { C = (5.0/9.0)*(F - 32); cout << setw(10) << F << setw(12) << C << endl; F += 1; }  You must have #include

61/10/2016CS150 Introduction to Computer Science 1 Programs  Write a program that will print the sum of the odd integers between 1 and 50 inclusive. Write one program using a while and the other using a for loop.

71/10/2016CS150 Introduction to Computer Science 1 Program  Write a program that inputs 50 numbers and outputs the largest and the smallest number

81/10/2016CS150 Introduction to Computer Science 1 Conditional Loops  Loops that execute until some condition is met  Includes more than counting  Use while loops

91/10/2016CS150 Introduction to Computer Science 1 Program  Write a flag controlled loop that continues to read pairs of integers until it reads a pair with the property that the first integer is evenly divisible by the second