COP 3275 – Finishing Loops and Beginning Arrays Instructor: Diego Rivera-Gutierrez.

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

Etter/Ingber Arrays and Matrices. Etter/Ingber One-Dimensional Arrays 4 An array is an indexed data structure 4 All variables stored in an array are of.
Loops (Part 1) Computer Science Erwin High School Fall 2014.
CSE 1301 Lecture 6B More Repetition Figures from Lewis, “C# Software Solutions”, Addison Wesley Briana B. Morrison.
10-Jun-15 Fibonacci Numbers A simple example of program design.
Fibonacci Numbers A simple example of program design.
Additional control structures. The if-else statement The if-else statement chooses which of two statements to execute The if-else statement has the form:
Loops – While, Do, For Repetition Statements Introduction to Arrays
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 11P. 1Winter Quarter Arrays Lecture 11.
CS 106 Introduction to Computer Science I 09 / 28 / 2007 Instructor: Michael Eckmann.
COP 3275 COMPUTER PROGRAMMING USING C Instructor: Diego Rivera-Gutierrez
The preprocessor and the compilation process COP3275 – PROGRAMMING USING C DIEGO J. RIVERA-GUTIERREZ.
CIS3931 – Intro to JAVA Lecture Note Set 3 19-May-05.
COP 3275 COMPUTER PROGRAMMING USING C Instructor: Diego Rivera-Gutierrez
Chapter 5 Control Structures: Loops 5.1 The while Loop The while loop is probably the most frequently used loop construct. The while loop is a conditional.
Chapter 5 Repetition or loop structure. What is repetition or loop? repeat the execution of one or a group (block; instruction enclosed in a pair of braces)
C++ Loose ends from last time. Variable initialization You can do the usual things int x; x = 10; int y = 20; And you can do an unusual thing int x(10);
Previously Repetition Structures While, Do-While, For.
Chapter 8 Repetition Statements. Introduction Iteration - process of looping or the repetition of one or more statements Loop body - the statement, or.
By Chad Blankenbeker.  The for-loop is best used when you know how many times it is going to be looped  So if you know you want it to only loop 10 times,
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
For loops in programming Assumes you have seen assignment statements and print statements.
COP Structures Instructor: Diego Rivera-Gutierrez I’m back baby!
COP 3275 COMPUTER PROGRAMMING USING C Instructor: Diego Rivera-Gutierrez
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
1-Dec-15 Additional control structures. 2 The if-else statement The if-else statement chooses which of two statements to execute The if-else statement.
COP 3275 – Iteration and loops Instructor: Diego Rivera-Gutierrez.
Agenda Perform Quiz #1 (20 minutes) Loops –Introduction / Purpose –while loops Structure / Examples involving a while loop –do/while loops Structure /
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
Arrays. The array data structure Array is a collection of elements, that have the same data type Integers (int) Floating point numbers (float, double)
Arrays as pointers and other stuff COP3275 – PROGRAMMING USING C DIEGO J. RIVERA-GUTIERREZ.
COP 3275 – Character Strings Instructor: Diego Rivera-Gutierrez.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 11P. 1Winter Quarter Arrays Lecture 11.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
COMP Loop Statements Yi Hong May 21, 2015.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
CS 106 Introduction to Computer Science I 02 / 15 / 2008 Instructor: Michael Eckmann.
PHP using MySQL Database for Web Development (part II)
REPETITION CONTROL STRUCTURE
Week of 12/12/16 Test Review.
ECE Application Programming
Introduction to Computer Science / Procedural – 67130
Controlling execution - iteration
Programming Fundamentals
Lecture 07 More Repetition Richard Gesick.
Repetition and Loop Statements
Chapter 4 LOOPS © Bobby Hoggard, Department of Computer Science, East Carolina University / These slides may not be used or duplicated without permission.
A simple example of program design
One-Dimensional Array Introduction Lesson xx
7 Arrays.
MATLAB – Basic For Loops
Sridhar Narayan Java Basics Sridhar Narayan
Multidimensional array
CS150 Introduction to Computer Science 1
Topics Introduction to Value-returning Functions: Generating Random Numbers Writing Your Own Value-Returning Functions The math Module Storing Functions.
EECE.2160 ECE Application Programming
CprE 185: Intro to Problem Solving (using C)
Arrays in Java.
do/while Selection Structure
Fundamental OOP Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Loops.
Fundamental Programming
EECE.2160 ECE Application Programming
In this class, we will cover:
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.
EECE.2160 ECE Application Programming
CprE 185: Intro to Problem Solving (using C)
Arrays.
Intro to Programming (in JavaScript)
Arrays as pointers and other stuff
Presentation transcript:

COP 3275 – Finishing Loops and Beginning Arrays Instructor: Diego Rivera-Gutierrez

Administrative stuff Third Quiz on Friday (6/5) 5 questions. 1) Follow a piece of code including a for and switch statement. Provide output and variable values at the end. 2) Theory on arrays (things we will cover today) 3) Follow a piece of code with repeated print statements and provide output (doesn’t use loops or ifs or anything) 4) Take the piece of code in problem 3 and remove repetition using a loop. 5) Create a for loop to compute the powers of a number.

Administrative stuff Homework #3 is assigned. Minesweeper! Check the specification. You will need arrays which we are covering today. Our board size will be static for this homework 9x9 (the beginner board). We will receive a seed value for the random generator. THIS IS EXTREMELY IMPORTANT. Follow the specific process for assigning mines precisely! We will print only the solution to the output (no user interactivity yet)

While loops General structure while( ) { }

while( ) { } Remember! Order of execution of a for : if( ){ if( ){ … }

while( ) { } Order of execution of a while if( ){ if( ){ … }

Do-while loops General structure do { } while( ) ; In my opinion the MOST forgotten semicolon in all of C

do { } while( ) ; Remember! Order of execution of a while if( ){ if( ){ … }

do { } while( ) ; Order of execution of a do-while if( ){ if( ){ … }

Let’s do some catching of user errors using while loops! Let’s add a loop to our simple calculator to do some user error checking

Modulus % (again) 2%3… from the quiz.

Modulus (again) 2%3… from the quiz. Because of that 3! We have 3 positions 0 12

Modulus (again) 2%3… from the quiz. Because of that 3! We have 3 positions 0 12

Arrays

Groups of Data Sometimes we want to deal with groups of data that are related. Examples? Vectors Sets of numbers Lists of people Lists of objects

Declaring one-dimensional arrays Similar to declaring variables! [ ]; needs to be a constant in most C implementations. (not a variable) Examples: int vector[3]; float vectorf[3]; char name[100];

Accessing elements in an array float f; float vectorf[3]; How do I access each element one individually? f vectorf elements

Accessing elements in an array Very easy! If is an array [ ] refers to the element at

Accessing elements in an array [ ] has to be: An integer (not necessarily a constant, can be a variable) Between 0 (first element) and size-1 (last element)

Accessing elements in an array float vectorf[3]; vectorf 0 1 2

Initializing an array float vectorf[3]; Option 1: (avoid this one on the quiz!) vectorf[0] = 0.0f; vectorf[1] = 0.0f; vectorf[2] = 0.0f; vectorf 0 1 2

Initializing an array Option 2: (using loops) for (i = 0; i < 3; i++) { vectorf[i] = 0.0f; } Option 3: (literal value) float vectorf[3] = {0.0f, 0.0f, 0.0f};

Groups of Data Examples? Vectors Sets of numbers Lists of people Lists of objects More dimensions? Matrices Images/Photos Tables Minesweeper boards…

Multidimensional arrays [ ][ ]; [ ][ ][ ]; [ ][ ][ ][ ]; char board[9][9]; or int board[9][9];