Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

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

2 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.

3 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; }

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

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

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

7 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.

8 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

9 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; } }

10 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


Download ppt "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."

Similar presentations


Ads by Google