CMPUT 101 Lab #6 October 29, 2007 14:00 – 17:00. Array in C/C++ Array is a structure type variable. One dimension of array int: int num[3]; There are.

Slides:



Advertisements
Similar presentations
Chapter 9 – One-Dimensional Numeric Arrays. Array u Data structure u Grouping of like-type data u Indicated with brackets containing positive integer.
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.
C Language.
This Time Whitespace and Input/Output revisited The Programming cycle Boolean Operators The “if” control structure LAB –Write a program that takes an integer.
C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
CMPUT 101 Lab # 5 October 22, :00 – 17:00.
Introduction to Application Programming IST 256 Application Programming for Information Systems Xiaozhong Liu
Arrays Programming COMP102 Prog. Fundamentals I: Arrays / Slide 2 Arrays l An array is a collection of data elements that are of the same type (e.g.,
Objective Revision of data structures and their implementation.
©2004 Brooks/Cole Chapter 8 Arrays. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Sometimes we have lists of data values that all need to be.
Chapter 8. 2 Objectives You should be able to describe: One-Dimensional Arrays Array Initialization Arrays as Arguments Two-Dimensional Arrays Common.
Chapter 9: Arrays and Strings
CSE202: Lecture 14The Ohio State University1 Arrays.
Arrays.
Multi-Dimensional Arrays in Java "If debugging is the process of removing software bugs, then programming must be the process of putting them in." -- Edsger.
One Dimensional Arrays. Declaring references to array objects How would you declare a variable somearray that is an array of ints? int[] somearray;
CPS120: Introduction to Computer Science Arrays. Arrays: A Definition A list of variables accessed using a single identifier May be of any data type Can.
Arrays (Part 1) Computer Science Erwin High School Fall 2014.
STREAMS AND FILES OVERVIEW.  Many programs are "data processing" applications  Read the input data  Perform sequence of operations on this data  Write.
Chapter 8 Arrays and Strings
Crypto Project Sample Encrypted Data: –Turing: CS Public\CryptoProjectData Crypto_Short_Keys_P_U.out Crypto_Long_Keys_O_R.out Bonus +10 points on.
Chapter 8: Collections: Arrays. 2 Objectives One-Dimensional Arrays Array Initialization The Arrays Class: Searching and Sorting Arrays as Arguments The.
Two dimensional arrays in Java Computer Science 3 Gerb Objective: Use matrices in Java.
Array Cs212: DataStructures Lab 2. Array Group of contiguous memory locations Each memory location has same name Each memory location has same type a.
CHAPTER: 12. Array is a collection of variables of the same data type that are referenced by a common name. An Array of 10 Elements of type double.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Arrays.
© Copyright 2013 by Pearson Education, Inc. All Rights Reserved. 1 Chapter 8 Multidimensional Arrays.
Lecture 4 Looping. Building on the foundation Now that we know a little about  cout  cin  math operators  boolean operators  making decisions using.
CHAPTER 7 arrays I NTRODUCTION T O C OMPUTER P ROGRAMMING (CSC425)
Scope When we create variables and functions, they are limited in where they are visible and where they can be referenced For the most part, the identifiers.
Array, Structure and Union
Count and add list of numbers From user input and from file.
Chapter 13 – C++ String Class. String objects u Do not need to specify size of string object –C++ keeps track of size of text –C++ expands memory region.
CPS120: Introduction to Computer Science Lecture 15 Arrays.
A First Book of C++: From Here To There, Third Edition2 Objectives You should be able to describe: One-Dimensional Arrays Array Initialization Arrays.
Arrays.
Arrays. Related data items Collection of the same types of data. Static entity – Same size throughout program.
Introduction to Loops Iteration Repetition Counting Loops Also known as.
REPETITION STATEMENTS - Part2 Structuring Input Loops Counter-Controlled Repetition Structure Sentinel-Controlled Repetition Structure eof()-Controlled.
Copyright © 2002 W. A. Tucker1 Chapter 9 Lecture Notes Bill Tucker Austin Community College COSC 1315.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
CHAPTER 6 ARRAYS IN C++ 2 nd Semester King Saud University College of Applied studies and Community Service CSC 1101 By: Fatimah Alakeel Edited.
Arrays. The array data structure Array is a collection of elements, that have the same data type Integers (int) Floating point numbers (float, double)
Get Longest Run Index (FR) public int getLongestRunIndex(int []values) { int maxRunStart = -1, maxRunLength = 1; int runStart = 0, runLength = 1; for(int.
CS201 – Introduction to Computing – Sabancı University 1 Built-in Arrays l C++ native array type (not the class version) l Two versions ä fixed size arrays.
EGR 115 Introduction to Computing for Engineers MATLAB Basics 1: Variables & Arrays Wednesday 03 Sept 2014 EGR 115 Introduction to Computing for Engineers.
FP201 - PROGRAMMING FUNDAMENTALS Unit Understand the use of array PREPARED BY: MAZNAH AHMAD, JTMK PSIS.
Arrays.
DCT1063 Programming 2 CHAPTER 3 STRINGS Mohd Nazri Bin Ibrahim Faculty of Computer, Media & Technology TATi University College
Arrays Declaring arrays Passing arrays to functions Searching arrays with linear search Sorting arrays with insertion sort Multidimensional arrays Programming.
Computer Programming Arrays 1. Question #1 2 Question Choose the correct answer..
Arrays. Arrays are objects that help us organize large amounts of information.
Introduction to Programming Lecture 12. Today’s Lecture Includes Strings ( character arrays ) Strings ( character arrays ) Algorithms using arrays Algorithms.
C++ Arrays SarMag Trimester 31 C++ Arrays. C++ Arrays SarMag Trimester 32 C++ Arrays An array is a consecutive group of memory locations. Each group is.
Beginning C for Engineers Fall 2005 Arrays, 2-D arrays, character strings Bettina Schimanski Lecture 5: Section 2 (9/28/05) Section 4 (9/29/05)
Arrays An array is a sequence of objects all of which have the same type. The objects are called the elements of the array and are numbered consecutively.
Data Storage So far variables have been able to store only one value at a time. What do you do if you have many similar values that all need to be stored?
A FIRST BOOK OF C++ CHAPTER 7 ARRAYS. OBJECTIVES In this chapter, you will learn about: One-Dimensional Arrays Array Initialization Arrays as Arguments.
Loops Review. How to generate random numbers Math.random() will return a random decimal value in the form of a double. double num1 = Math.random(); num1.
Chapter 6 Arrays in C++ 2nd Semester King Saud University
Computer Programming BCT 1113
Two Dimensional Array Mr. Jacobs.
The Ohio State University
More Loops.
Arrays An array is a collection of variables that all have the same name and the same data type. Each member of the array is known as an element of the.
Multidimensional Arrays
INC 161 , CPE 100 Computer Programming
Functions continued.
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
Presentation transcript:

CMPUT 101 Lab #6 October 29, :00 – 17:00

Array in C/C++ Array is a structure type variable. One dimension of array int: int num[3]; There are three integer variables in it: num[0], num[1] and num[2]. You can declare array of int, double, and char. Remember, the index of array starts from zero.

Working with array Using while loop to travel all members in an array: int num[3], i; i = 0; while (i < 3) { // do something with num[i] ; i = i + 1; }

Working with array Using for loop: int i, num[3]; for (i=0; i<3; i++) { // do something with num[i] ; }

Example: input 10 integers int List [10], i; for (i=0; i > List [i]; }

Example: output 10 integers that are greater than zero int List [10], i; for (i=0; i 0) cout >> List [i]; }

Q1: notes print the numbers all on the same line separated by at least one space. Ex: print the values of num1 and num2 separated by 1 space: cout << num1 << " " << num2; See example runs.

Q2: use the file, encrypt.cpp that is provided; add the modification to check for a character entered that is not in the array. Show a sample run, and briefly go through encrypt.cpp

Q3: Two dimensional array, matrix[3][4] for (i=0; i<3; i++) { for (j=0; j<4; j++) { // set all of the array entries to zero matrix[i][j]=0; } }

Q3: In addition to stopping the robot when 'x' is entered, you also need to stop the robot when it tries to move past the array boundaries--row 0, row 9, col 0, col 9 The robot is positioned in the centre of the map at the start, row 5 and col 5 Show sample run