CSCI 3328 Object Oriented Programming in C# Chapter 7: Arrays – Exercises UTPA – Fall 2012 This set of slides is revised from lecture slides of Prof.

Slides:



Advertisements
Similar presentations
 2006 Pearson Education, Inc. All rights reserved Arrays.
Advertisements

Chapter 8 Arrays and Strings
CSCI/CMPE 4341 Topic: Programming in Python Chapter 3: Control Structures (Part 1) – Exercises 1 Xiang Lian The University of Texas – Pan American Edinburg,
1 CSCE 1030 Computer Science 1 Arrays Chapter 7 in Small Java.
CSCI/CMPE 4341 Topic: Programming in Python Chapter 6: Lists, Tuples, and Dictionaries – Exercises Xiang Lian The University of Texas – Pan American Edinburg,
The University of Texas – Pan American
 2006 Pearson Education, Inc. All rights reserved Arrays.
Chapter 8 Arrays and Strings
CSCI 3328 Object Oriented Programming in C# Chapter 5: C# Control Statement – Part II UTPA – Fall
Arrays Chapter 7. 2 "All students to receive arrays!" reports Dr. Austin. Declaring arrays scores : Inspecting.
CSCI 3328 Object Oriented Programming in C# Chapter 5: C# Control Statement – Part II – Exercises 1 Xiang Lian The University of Texas Rio Grande Valley.
CSCI 3328 Object Oriented Programming in C# Chapter 7: Arrays 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX 78539
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
CSCI 3328 Object Oriented Programming in C# Chapter 8: LINQ and Generic Collections – Exercises 1 Xiang Lian The University of Texas – Pan American Edinburg,
Arrays Chapter 7. 2 Declaring and Creating Arrays Recall that an array is a collection of elements all of the _____________ Array objects in Java must.
Arrays Declaring arrays Passing arrays to functions Searching arrays with linear search Sorting arrays with insertion sort Multidimensional arrays Programming.
SEQUENTIAL AND OBJECT ORIENTED PROGRAMMING Arrays.
CSCI 3328 Object Oriented Programming in C# Chapter 6: Methods – Exercises 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX 78539
 2005 Pearson Education, Inc. All rights reserved Arrays.
Arrays Chapter 7.
Chapter 6: Using Arrays.
Computer Programming BCT 1113
CSCI 3327 Visual Basic Chapter 4: Control Statements in Visual Basic (Part 2B) UTPA – Fall 2011 Part of the slides is from Dr. John Abraham’s previous.
CSCI 3328 Object Oriented Programming in C# Review: Final Exam
The University of Texas – Pan American
CSCI 3327 Visual Basic Chapter 7: Data Manipulation in Arrays
Advanced Programming Chapter 8: Arrays
Arrays, For loop While loop Do while loop
Java How to Program, Late Objects Version, 10/e
CSCI 3328 Object Oriented Programming in C# Chapter 7: Arrays
The University of Texas Rio Grande Valley
CSCI 3328 Object Oriented Programming in C# Chapter 4: C# Control Statement – Part I UTPA – Fall 2012 This set of slides is revised from lecture slides.
Array Data Structure Chapter 6
The University of Texas – Pan American
7 Arrays.
The University of Texas – Pan American
7 Arrays.
CSCI 3327 Visual Basic Chapter 8: Introduction to LINQ and Collections
CSCI 3328 Object Oriented Programming in C# Chapter 4: C# Control Statement – Part I – Exercises UTPA – Fall 2012 This set of slides is revised from lecture.
CSCI 3328 Object Oriented Programming in C# Chapter 9: Classes and Objects: A Deeper Look – Exercises UTPA – Fall 2012 This set of slides is revised from.
The University of Texas – Pan American
Review of Arrays and Pointers
CSCI 3327 Visual Basic Review: Final Exam
The University of Texas – Pan American
Introduction To Programming Information Technology , 1’st Semester
The University of Texas Rio Grande Valley
CSCI 3328 Object Oriented Programming in C# Review: Exam II
CSCI 3328 Object Oriented Programming in C# Chapter 5: C# Control Statement – Part II – Exercises UTPA – Fall 2012 This set of slides is revised from.
JavaScript Arrays.
CSCI 3328 Object Oriented Programming in C# Review: Final Exam
The University of Texas – Pan American
CSCI 3328 Object Oriented Programming in C# Chapter 3: Introduction to Classes and Objects – Exercises UTPA – Fall 2012 This set of slides is revised.
CSCI 3328 Object Oriented Programming in C# Review: Exam II
CSCI 3328 Object Oriented Programming in C# Review: Final Exam
The University of Texas – Pan American
CS2011 Introduction to Programming I Arrays (I)
MSIS 655 Advanced Business Applications Programming
CSCI 3328 Object Oriented Programming in C# Chapter 7: Arrays
Arrays Chapter 7.
CSCI 3328 Object Oriented Programming in C# Chapter 6: Methods
Multidimensional array
Arrays Week 2.
CSCI 3328 Object Oriented Programming in C# Review: Final Exam
7 Arrays.
Object Oriented Programming
Array Data Structure Chapter 6
CS150 Introduction to Computer Science 1
CSCI 3328 Object Oriented Programming in C# Chapter 8: LINQ and Generic Collections – Exercises UTPA – Fall 2012 This set of slides is revised from lecture.
Review for Midterm 3.
CSCI 3328 Object Oriented Programming in C# Review: Exam II
Presentation transcript:

CSCI 3328 Object Oriented Programming in C# Chapter 7: Arrays – Exercises UTPA – Fall 2012 This set of slides is revised from lecture slides of Prof. John Abraham. -- Xiang Lian

Objectives In this chapter, you will do some exercises about: 1-dimenionsal or multidimensional arrays Data manipulations in arrays

Multiple Choices Lists and tables of values with the same data type can be stored in _____. A. variables B. arrays C. indexes D. keywords The _________ statement allows you to iterate through the elements in an array without using a counter. A. for B. each C. for each D. foreach The number that refers to a particular array element is called the element's _______. A. number B. data type C. index D. class An array that uses two indices is referred to as a(n) _____ array. A. 1-dimensional B. 2-dimensional C. matrix D. list Which of the following statements is true to iterate all elements in the array? A. for (int i = 0; i < array.Length; i++) B. for (int i = 1; i < array.Length; i++) C. for (int i = 1; i <= array.Length; i++) D. for (int i = 0; i <= array.Length; i++)

Multiple Choices (cont'd) Use the foreach header _____ to iterate through double array numbers. A. for each (double d=1; d<numbers.Length; d++) B. foreach (double d = 1 in numbers) C. foreach (double d in numbers) D. for each (double d = numbers[]) Command-line arguments are stored in _____. A. string [] args B. string args C. char args D. char [] args Use the expression _____ to receive the total number of arguments in a command line. A. args.length B. args.Length() C. args.GetLength() D. args.Length The indexed array name of one-dimensional array units's element 2 is _______. A. units{1} B. units(2) C. units[0, 2] D. units [1]

Multiple Choices (cont'd) Which of the following sorts array averageRainfall? A. Array(averageRainfall).Sort() B. Sort.Array(averageRainfall) C. Sort(averageRainfall) D. Array.Sort(averageRainfall)

True/False Statements A single array can store values of different types. An array index should normally be of type float. An individual array element that is passed to a method and modified in that method will contain the modified value when the called method completes execution. Command-line arguments are separated by commas.

True/False Statements (cont'd) The declaration of an array of size 11 is as follows: int arr = new int [10]; The modification of an array element is as follows: 10 = arr[0]; The declaration of a 2-dimensional array is as follows: int [ ] arr = new int [20][10]; The declaration of a 10*10 array is as follows: int [,] arr = new int [11, 11]; The linear search in arrays requires elements in a sorted order. The binary search works well for unsorted arrays

Debugging Errors const int array_size = 5; array_size = 10; int [] b = new int [5]; For (int i =0; i<=b.Length; i++) b[i]=1; int [] a = {1, 2, , 4, 5}; b=a; int [,] c={{1,2}, {3, 4}}; c[1][1] = 5;

Debugging Errors (cont'd) int [, ] array = new int [3, 3]; for (int i = 0; i<=3; i++) for (int j=0; j<=3; j++) array [i, j] = i+j;

Write a Program Write a complete program to generate random number between 1 and 99, and output the resulting number to a resultTextBox.

Write a Program (cont'd) Declare an array, numArray, to hold 100 integer numbers Assign random numbers within [1, 100] into this array Sort this array Check whether a number 50 exists in this array using the linear search and foreach statement Output the multiplication of all even integers in this array; if no even numbers exist, then output 1