2. Each element of an array is accessed by a number known as a(n) a. a. subscript b. size declarator c. address d. specifier

Size: px
Start display at page:

Download "2. Each element of an array is accessed by a number known as a(n) a. a. subscript b. size declarator c. address d. specifier"

Transcription

1 Lesson 4 Arrays and Lists Review CSC 123 Fall 2018 Answer Sheet Short Answers 1. In an array declaration, this indicates the number of elements that the array will have. b a. subscript b. size declarator c. element sum d. reference variable 2. Each element of an array is accessed by a number known as a(n) a. a. subscript b. size declarator c. address d. specifier 3. The first subscript in an array is always b. a. 1 b. 0 c. 21 d. 1 less than the number of elements 4. The last subscript in an array is always d. a. 100 b. 0 c. 21 d. 1 less than the number of elements 5. This array field holds the number of elements that the array has c a. size b. elements c. length d. width 6. This search algorithm steps through an array, comparing each item with the search value. b_ a. binary search b. sequential search c. selection search d. iterative search 7. This search algorithm repeatedly divides the portion of an array being searched in half. _a a. binary search b. sequential search c. selection search d. iterative search 1

2 8. This is the typical number of comparisons performed by the sequential search on an array of N elements (assuming the search values are consistently found). d a. 2N b. N c. N 2 d. N/2 9. When initializing a two-dimensional array, you enclose each row s initialization list in a. a. braces b. parentheses c. brackets d. quotation marks 10. True or False: Java does not allow a statement to use a subscript that is outside the range of valid subscripts for an array. true 11. True or False: An array s size declarator can be a negative integer expression. false 12. True or False: Both of the following declarations are legal and equivalent: int[] numbers; int numbers[]; true 13. True or False: The subscript of the last element in a single-dimensional array is one less than the total number of elements in the array. true 14. True or False: The values in an initialization list are stored in the array in the order that they appear in the list. true 15. True or False: When an array reference is passed to a method, the method has access to the original array. true 16. True or False: The first size declarator in the declaration of a two-dimensional array represents the number of columns. The second size declarator represents the number of rows. false 17. What are the values stored in the array a after the following code executes? int [] a = new int[10]; for (int i = 0; i < a.length; i++) a[i] = 2*i 1; Cell Value a[0] -1 a[1] 1 a[2] 3 a[3] 5 2

3 a[4] 7 a[5] 9 a[6] 11 a[7] 13 a[8] 15 a[9] What are the values stored in the array a after the following code executes? int [] a = new int[10]; a[0] = 1; for (int i = 1; i < a.length; i++) a[i] = 2*a[i-1] 1; Cell Value a[0] 1 a[1] 1 a[2] 1 a[3] 1 a[4] 1 a[5] 1 a[6] 1 a[7] 1 a[8] 1 a[9] 1 Find the error(s) in each of the following code segments for questions char[] a = new char[10]; a[10] = s ; a[9] = 76; 10 cannot be an index. The indices run char[] a = new char[10]; char[9] = s ; Char is the type, a is the array name.. Should say a[9] 21. char[] a = new int[10]; a[0] = s ; a[1] = 80; Declaring a char array but instantiating an int. 3

4 22. int[] a; a = new int[255]; a[0] = s ; a[a[0]] = 35; a[35] = ; Only error is the integer is too large 23. int[] a; a = new int[255]; a[0] = a.length; a[0]--; a.length--; a[a[0]] = 2; Can t change the length variable 24. int[] b = new int[9]; int[][] a; a = new int[255][]; a[0] = b; a[0][3] = 9; a[3][0] = 9; a[3][0] doesn t exist. The object for this row hasn t been created yet Homework Programs Do 7 of the first 9. Number 10 is a bonus. 1. ReversePrint Write a program (all in main) Creates an int array of size 100 Reads in up to 100 elements, stopping when you read in -999 (which is not put into the array. Prints out the array elements read in in reverse order. Please enter up to 100 integer values. Enter -999 to end: RandomFill Write a program that does the following: In main: 4

5 Read in the size of an int array Create an array of that size Call randomfill with a reference to the array Print out the elements of the array In randomfill: Fill the array with random numbers from 2 to 12. (Note: you don t need to return anything) Please enter the number of cells in an integer array: Please enter the number of cells in an integer array: SumEvenOddAll Write a program that does the following: In main: Creates an int array of size 100 Calls fillarray which accepts a reference to the created array Calculates the sums of the even numbers, odd numbers and all the numbers in the arrays Prints out the three sums fillarray does the following Accepts a reference to an int array Reads numbers into the array until it reads a -999 or the array is filled up. Return the number of elements read into the array Please enter up to 100 integer values. Enter -999 to end: The sum of all the numbers is: 174 The sum of all the even numbers is: 78 The sum of all the odd numbers is: CoffeeAcid Write a program that does the following: In main: Read in the length of an array of type double. Call createarray with the length Read in the PH value as floating point number greater than 0.0 and less than 7.0 into the array created in createarray. (assume values read in are correct) Find the average of the elements in the array. Find the element in the array furthest from the average. Print out the average, and the value and index of the element furthest from the average. In createarray: 5

6 Create an array of type double with the length in the formal parameter. Return the reference to that array. Notes: If more than one value is the furthest can just list the first. Remember to use absolute value when testing the difference from the average. Please enter the number of entries of coffee acid PH: 8 Please enter 8 PH readings of type double: The average of all the PH read in is The PH furthest from the average is which is found at cell 3 5. Rainfall Write a Rainfall class that stores the total rainfall for each of 12 months into an array of doubles. The main programs requests and reads in the rainfall by month. Do not accept negative numbers for monthly rainfall figures. The main method also prints out the data returned from two separate methods that return the following: the total rainfall for the year the average monthly rainfall Please enter the monthly rainfall greater than or equal to 0.0 for month 1: -2.7 The rainfall must be greater than or equal to 0.0 Please enter the monthly rainfall greater than or equal to 0.0 for month 1: 0.0 Please enter the monthly rainfall greater than or equal to 0.0 for month 2: 7.8 Please enter the monthly rainfall greater than or equal to 0.0 for month 3: 19.4 Please enter the monthly rainfall greater than or equal to 0.0 for month 4: 44.3 Please enter the monthly rainfall greater than or equal to 0.0 for month 5: 8.2 Please enter the monthly rainfall greater than or equal to 0.0 for month 6: -7.7 The rainfall must be greater than or equal to 0.0 Please enter the monthly rainfall greater than or equal to 0.0 for month 6: 1.9 Please enter the monthly rainfall greater than or equal to 0.0 for month 7: 0.31 Please enter the monthly rainfall greater than or equal to 0.0 for month 8: 2.4 Please enter the monthly rainfall greater than or equal to 0.0 for month 9: 4.9 Please enter the monthly rainfall greater than or equal to 0.0 for month 10: 33.2 Please enter the monthly rainfall greater than or equal to 0.0 for month 11: 12.8 Please enter the monthly rainfall greater than or equal to 0.0 for month 12: 4.9 The total yearly rainfall is The average rainfall is Lottery Write a Lottery class that simulates a lottery. The class should have an array of five integers in the range of 0 through 9 for each element in the array that are generated randomly in a method called generatelotterywinner. The class should have a method called getbettorpicks that is used to request the user s five picks between 0 and 9 and return a reference to that array. 6

7 The class should also have a method comparenumbers that compares the corresponding elements in the two arrays and return the number of digits that match. Demonstrate the class in a program that asks the user to enter five numbers. The program should display the 5 lotter winners and the number of digits that match the randomly generated lottery numbers. If all of the digits match, display a message proclaiming the user a grand prize winner. Please enter a number from 0 to 9 for pick 1: -2 Please enter a number from 0 to 9 for pick 1: 4 Please enter a number from 0 to 9 for pick 2: 6 Please enter a number from 0 to 9 for pick 3: 8 Please enter a number from 0 to 9 for pick 4: 2 Please enter a number from 0 to 9 for pick 5: 2 The five winning numbers are: The number of matches is 1 Please enter a number from 0 to 9 for pick 1: 0 Please enter a number from 0 to 9 for pick 2: 1 Please enter a number from 0 to 9 for pick 3: 2 Please enter a number from 0 to 9 for pick 4: 3 Please enter a number from 0 to 9 for pick 5: 4 The five winning numbers are: The number of matches is 1 Please enter a number from 0 to 9 for pick 1: 6 Please enter a number from 0 to 9 for pick 2: 7 Please enter a number from 0 to 9 for pick 3: 4 Please enter a number from 0 to 9 for pick 4: 2 Please enter a number from 0 to 9 for pick 5: 8 The five winning numbers are: The number of matches is 2 7. TwoDAverage In main; Read in the number of rows and columns of a regular two-dimensional int array. Read in the elements row by row. Call average2d with a reference to the array read in. Print out the average returned by average2d. In average2d Calculate the average as a type double and return as a type double. Please enter the rows and columns in a dimensional integer array: 3 4 Please enter 4 integers for row 0:

8 Please enter 4 integers for row 1: Please enter 4 integers for row 2: The average of the numbers in the 2d array is Please enter the rows and columns in a dimensional integer array: 4 2 Please enter 2 integers for row 0: 4 5 Please enter 2 integers for row 1: 6 7 Please enter 2 integers for row 2: -1 9 Please enter 2 integers for row 3: 3 2 The average of the numbers in the 2d array is CountGreaterThanTen Write a class CountGreaterThanTen that does the following: The main method does the following: a. Requests from the user the dimensions for a two dimensional array. b. Calls the method createarray to create a two-dimensional integer array. c. Calls a method fullarray with a reference to the array created by createarray. d. Calls a method called greaterten with a reference to the array created by createarray. e. Prints out the final elements of the two-dimensional array row by row. f. The main method then prints out the final values in the array and a final sentence stating: It is (true/false) that there are more entries in the array greater than ten than less than or equal to ten. createarray does the following: a. Accepts the dimensions of a two dimensional int array as parameters. b. Creates a two-dimensional int array using the input parameters. c. Returns a reference to the array that was created. fullarray does the following: a. Has a two-dimensional int array as its formal parameter. b. Fills a two-dimensional int array with random integers from 1 to 20. greaterten does the following: a. Has a two-dimensional int array as its formal parameter. It then counts the number of entries greater than ten and returns true if there are more numbers greater than ten in the array. Otherwise it returns false. Please enter the rows and columns in a dimensional integer array: It is false that there are more entries in the array greater than ten than less than or equal to ten. Please enter the rows and columns in a dimensional integer array:

9 It is true that there are more entries in the array greater than ten than less than or equal to ten. 9. RaggedArrays The following code defines a ragged two-dimensional array. The term ragged indicates that the rows are not all the same length. int[][] triangle = new int[5][]; // allocate array of rows for (int i = 0; i < triangle.length; i++) triangle[i] = new int[i+1]; a. Write a method int [][] buildragged(int n) that returns a (possibly) ragged array with n rows. The method reads n + 1 lines of data from the console. The first line contains the number of rows of a ragged array. Each succeeding line specifies one row of a ragged array. The first entry of each line gives the number of items in that row. For example, the input indicates that there are 3 rows and that the first row of the ragged array has 3 entries (1, 5, and 7), the second row 6 entries (5, 6, 8, 9, 3, and 2), and the third row 2 entries (5 and 8). b. Write a method void printarray(int [][] x) that displays a (possibly) ragged array. c. Test your methods in a program using the main(...) method. Enter the number of rows in the array: 3 Please enter the number of columns for row 0: 2 Please enter 2 integers from -999 to 999 for row 0: Please enter the number of columns for row 1: 6 Please enter 6 integers from -999 to 999 for row 1: Please enter the number of columns for row 2: 1 Please enter 1 integers from -999 to 999 for row 2:

10 10. MergedArrays (Bonus) In the main program: Read in the lengths of two arrays. The arrays don t need to be of the same length Create each of the arrays as an int array. For each array call randomfill with a reference to the array. For each array, call maxsort with a reference to the array that sorts the array from least to greatest Call mergearrays with references to each of the two arrays Print out the two original arrays after they have been sorted and the merged array whose reference is returned by mergearrays randomfill: Accepts a reference to an int array. Fills the array with random integers between 1 and 100. maxsort: Accepts a reference to an int array. Sorts the array. You may copy the appropriate code from the MaxSort.java file including the maxsort and max methods mergearrays: Accepts the references from two int arrays Creates a third array that includes all the elements of the first two sorted arrays This third array create has a length equal to the sum of the lengths of two arrays, and has the elements merged from least to greatest. Returns a reference to the merged array. Please enter the number of cells in each of two integer arrays: 4 6 The sorted first array is: The sorted second array is: The sorted merged array is: Please enter the number of cells in each of two integer arrays: 6 4 The sorted first array is: The sorted second array is: The sorted merged array is: Please enter the number of cells in each of two integer arrays: 9 9 The sorted first array is: The sorted second array is: The sorted merged array is: 10

11

All answers will be posted on web site, and most will be reviewed in class.

All answers will be posted on web site, and most will be reviewed in class. Lesson 4 Arrays and Lists Review CSC 123 Fall 2018 Notes: All homework must be submitted via e-mail. All parts of assignment must be submitted in a single e-mail with multiple attachments when required.

More information

Exam 2. CSC 121 MW Class. Lecturer: Howard Rosenthal. April 26, 2017

Exam 2. CSC 121 MW Class. Lecturer: Howard Rosenthal. April 26, 2017 Your Name: Exam 2. CSC 121 MW Class Lecturer: Howard Rosenthal April 26, 2017 The following questions (or parts of questions) in numbers 1-7 are all worth 3 points each. 1. Answer the following as true

More information

Exam 2. CSC 121 MW Class. Lecturer: Howard Rosenthal. April 25, 2016

Exam 2. CSC 121 MW Class. Lecturer: Howard Rosenthal. April 25, 2016 Your Name: Exam 2. CSC 121 MW Class Lecturer: Howard Rosenthal April 25, 2016 The following questions (or parts of questions) in numbers 1-7 are all worth 3 points each. 1. Answer the following as true

More information

Exam 2. CSC 121 TTH Class. Lecturer: Howard Rosenthal. April 26, 2016

Exam 2. CSC 121 TTH Class. Lecturer: Howard Rosenthal. April 26, 2016 Your Name: Exam 2. CSC 121 TTH Class Lecturer: Howard Rosenthal April 26, 2016 The following questions (or parts of questions) in numbers 1-7 are all worth 3 points each. 1. Answer the following as true

More information

Review Chapter 6 in Bravaco. Short Answers 1. This type of method does not return a value. a. null b. void c. empty d. anonymous

Review Chapter 6 in Bravaco. Short Answers 1. This type of method does not return a value. a. null b. void c. empty d. anonymous Assignment 3 Methods Review CSC 123 Fall 2018 Notes: All homework must be submitted via e-mail. All parts of assignment must be submitted in a single e-mail with multiple attachments when required. Notes:

More information

Arrays and Lists Review CSC 123 Fall 2018 Howard Rosenthal

Arrays and Lists Review CSC 123 Fall 2018 Howard Rosenthal Arrays and Lists Review CSC 123 Fall 2018 Howard Rosenthal Lesson Goals Review what an array is Review how to declare arrays Review what reference variables are Review how to pass arrays to methods Review

More information

High Institute of Computer Science & Information Technology Term : 1 st. El-Shorouk Academy Acad. Year : 2013 / Year : 2 nd

High Institute of Computer Science & Information Technology Term : 1 st. El-Shorouk Academy Acad. Year : 2013 / Year : 2 nd El-Shorouk Academy Acad. Year : 2013 / 2014 High Institute of Computer Science & Information Technology Term : 1 st Year : 2 nd Computer Science Department Object Oriented Programming Section (1) Arrays

More information

Array Basics: Outline. Creating and Accessing Arrays. Creating and Accessing Arrays. Arrays (Savitch, Chapter 7)

Array Basics: Outline. Creating and Accessing Arrays. Creating and Accessing Arrays. Arrays (Savitch, Chapter 7) Array Basics: Outline Arrays (Savitch, Chapter 7) TOPICS Array Basics Arrays in Classes and Methods Programming with Arrays Searching and Sorting Arrays Multi-Dimensional Arrays Static Variables and Constants

More information

Chapter 9 Introduction to Arrays. Fundamentals of Java

Chapter 9 Introduction to Arrays. Fundamentals of Java Chapter 9 Introduction to Arrays Objectives Write programs that handle collections of similar items. Declare array variables and instantiate array objects. Manipulate arrays with loops, including the enhanced

More information

Lecture 2 Arrays, Searching and Sorting (Arrays, multi-dimensional Arrays)

Lecture 2 Arrays, Searching and Sorting (Arrays, multi-dimensional Arrays) Lecture 2 Arrays, Searching and Sorting (Arrays, multi-dimensional Arrays) In this lecture, you will: Learn about arrays Explore how to declare and manipulate data into arrays Understand the meaning of

More information

C Language Part 2 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

C Language Part 2 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee C Language Part 2 (Minor modifications by the instructor) 1 Scope Rules A variable declared inside a function is a local variable Each local variable in a function comes into existence when the function

More information

Arrays and Lists CSC 121 Fall 2016 Howard Rosenthal

Arrays and Lists CSC 121 Fall 2016 Howard Rosenthal Arrays and Lists CSC 121 Fall 2016 Howard Rosenthal Lesson Goals Understand what an array is Understand how to declare arrays Understand what reference variables are Understand how to pass arrays to methods

More information

APCS Semester #1 Final Exam Practice Problems

APCS Semester #1 Final Exam Practice Problems Name: Date: Per: AP Computer Science, Mr. Ferraro APCS Semester #1 Final Exam Practice Problems The problems here are to get you thinking about topics we ve visited thus far in preparation for the semester

More information

Arrays and Lists CSC 121 Fall 2015 Howard Rosenthal

Arrays and Lists CSC 121 Fall 2015 Howard Rosenthal Arrays and Lists CSC 121 Fall 2015 Howard Rosenthal Lesson Goals Understand what an array is Understand how to declare arrays Understand what reference variables are Understand how to pass arrays to methods

More information

2-D Arrays. Of course, to set each grid location to 0, we have to use a loop structure as follows (assume i and j are already defined):

2-D Arrays. Of course, to set each grid location to 0, we have to use a loop structure as follows (assume i and j are already defined): 2-D Arrays We define 2-D arrays similar to 1-D arrays, except that we must specify the size of the second dimension. The following is how we can declare a 5x5 int array: int grid[5][5]; Essentially, this

More information

Arrays: Higher Dimensional Arrays. CS0007: Introduction to Computer Programming

Arrays: Higher Dimensional Arrays. CS0007: Introduction to Computer Programming Arrays: Higher Dimensional Arrays CS0007: Introduction to Computer Programming Review If the == operator has two array variable operands, what is being compared? The reference variables held in the variables.

More information

Lecture Programming in C++ PART 1. By Assistant Professor Dr. Ali Kattan

Lecture Programming in C++ PART 1. By Assistant Professor Dr. Ali Kattan Lecture 08-1 Programming in C++ PART 1 By Assistant Professor Dr. Ali Kattan 1 The Conditional Operator The conditional operator is similar to the if..else statement but has a shorter format. This is useful

More information

Chapter 2: Functions and Control Structures

Chapter 2: Functions and Control Structures Chapter 2: Functions and Control Structures TRUE/FALSE 1. A function definition contains the lines of code that make up a function. T PTS: 1 REF: 75 2. Functions are placed within parentheses that follow

More information

Introduction to Computer Science Midterm 3 Fall, Points

Introduction to Computer Science Midterm 3 Fall, Points Introduction to Computer Science Fall, 2001 100 Points Notes 1. Tear off this sheet and use it to keep your answers covered at all times. 2. Turn the exam over and write your name next to the staple. Do

More information

Computer Science & Engineering 150A Problem Solving Using Computers

Computer Science & Engineering 150A Problem Solving Using Computers Computer Science & Engineering 150A Problem Solving Using Computers Lecture 06 - Stephen Scott Adapted from Christopher M. Bourke 1 / 30 Fall 2009 Chapter 8 8.1 Declaring and 8.2 Array Subscripts 8.3 Using

More information

Arrays and Lists CSC 121 Fall 2014 Howard Rosenthal

Arrays and Lists CSC 121 Fall 2014 Howard Rosenthal Arrays and Lists CSC 121 Fall 2014 Howard Rosenthal Lesson Goals Understand what an array is Understand how to declare arrays Understand what reference variables are Understand how to pass arrays to methods

More information

More on Arrays CS 16: Solving Problems with Computers I Lecture #13

More on Arrays CS 16: Solving Problems with Computers I Lecture #13 More on Arrays CS 16: Solving Problems with Computers I Lecture #13 Ziad Matni Dept. of Computer Science, UCSB Announcements Homework #12 due today No homework assigned today!! Lab #7 is due on Monday,

More information

1 Short Answer (15 Points Each)

1 Short Answer (15 Points Each) Name: Write all of your responses on these exam pages. If you need extra space please use the backs of the pages. 1 Short Answer (15 Points Each) 1. Write the following Java declarations, (a) A double

More information

Arrays. Defining arrays, declaration and initialization of arrays. Designed by Parul Khurana, LIECA.

Arrays. Defining arrays, declaration and initialization of arrays. Designed by Parul Khurana, LIECA. Arrays Defining arrays, declaration and initialization of arrays Introduction Many applications require the processing of multiple data items that have common characteristics (e.g., a set of numerical

More information

Arrays and functions Multidimensional arrays Sorting and algorithm efficiency

Arrays and functions Multidimensional arrays Sorting and algorithm efficiency Introduction Fundamentals Declaring arrays Indexing arrays Initializing arrays Arrays and functions Multidimensional arrays Sorting and algorithm efficiency An array is a sequence of values of the same

More information

Class C{ int a; } what variables below are objects : a. C c; b. String str; c. Scanner scanner; d. int num; e. float f;

Class C{ int a; } what variables below are objects : a. C c; b. String str; c. Scanner scanner; d. int num; e. float f; Class C{ int a; } what variables below are objects : a. C c; b. String str; c. Scanner scanner; d. int num; e. float f; Starting Out with Java: From Control Structures Through Objects Sixth Edition Chapter

More information

Lesson 06 Arrays. MIT 11053, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL

Lesson 06 Arrays. MIT 11053, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL Lesson 06 Arrays MIT 11053, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL Array An array is a group of variables (called elements or components) containing

More information

CSC 307 DATA STRUCTURES AND ALGORITHM ANALYSIS IN C++ SPRING 2011

CSC 307 DATA STRUCTURES AND ALGORITHM ANALYSIS IN C++ SPRING 2011 CSC 307 DATA STRUCTURES AND ALGORITHM ANALYSIS IN C++ SPRING 2011 Date: 01/18/2011 (Due date: 01/20/2011) Name and ID (print): CHAPTER 6 USER-DEFINED FUNCTIONS I 1. The C++ function pow has parameters.

More information

Reviewing all Topics this term

Reviewing all Topics this term Today in CS161 Prepare for the Final Reviewing all Topics this term Variables If Statements Loops (do while, while, for) Functions (pass by value, pass by reference) Arrays (specifically arrays of characters)

More information

Final Exam. CSC 121 Fall Lecturer: Howard Rosenthal. Dec. 13, 2017

Final Exam. CSC 121 Fall Lecturer: Howard Rosenthal. Dec. 13, 2017 Your Name: Final Exam. CSC 121 Fall 2017 Lecturer: Howard Rosenthal Dec. 13, 2017 The following questions (or parts of questions) in numbers 1-17 are all worth 2 points each. The programs have indicated

More information

Lesson 9: Introduction To Arrays (Updated for Java 1.5 Modifications by Mr. Dave Clausen)

Lesson 9: Introduction To Arrays (Updated for Java 1.5 Modifications by Mr. Dave Clausen) Lesson 9: Introduction To Arrays (Updated for Java 1.5 Modifications by Mr. Dave Clausen) 1 Lesson 9: Introduction Objectives: To Arrays Write programs that handle collections of similar items. Declare

More information

Exam 1 Answer Key CSC 123 Fall 2018 Lecturer: Howard Rosenthal Oct. 17, 2018

Exam 1 Answer Key CSC 123 Fall 2018 Lecturer: Howard Rosenthal Oct. 17, 2018 Your Name: Exam 1 Answer Key CSC 123 Fall 2018 Lecturer: Howard Rosenthal Oct. 17, 2018 The following questions in numbers 1-11 are all worth 3 points each (including each true and false). The programs

More information

Integers and Absolute Value. Unit 1 Lesson 5

Integers and Absolute Value. Unit 1 Lesson 5 Unit 1 Lesson 5 Students will be able to: Understand integers and absolute value Key Vocabulary: An integer Positive number Negative number Absolute value Opposite Integers An integer is a positive or

More information

Array. Array Declaration:

Array. Array Declaration: Array Arrays are continuous memory locations having fixed size. Where we require storing multiple data elements under single name, there we can use arrays. Arrays are homogenous in nature. It means and

More information

Ex: If you use a program to record sales, you will want to remember data:

Ex: If you use a program to record sales, you will want to remember data: Data Variables Programs need to remember values. Ex: If you use a program to record sales, you will want to remember data: A loaf of bread was sold to Sione Latu on 14/02/19 for T$1.00. Customer Name:

More information

Computer Programming. C Array is a collection of data belongings to the same data type. data_type array_name[array_size];

Computer Programming. C Array is a collection of data belongings to the same data type. data_type array_name[array_size]; Arrays An array is a collection of two or more adjacent memory cells, called array elements. Array is derived data type that is used to represent collection of data items. C Array is a collection of data

More information

Chapter 6 Single-Dimensional Arrays. Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved.

Chapter 6 Single-Dimensional Arrays. Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. Chapter 6 Single-Dimensional Arrays rights reserved. 1 Opening Problem Read one hundred numbers, compute their average, and find out how many numbers are above the average. Solution AnalyzeNumbers rights

More information

Programming in C++ PART 2

Programming in C++ PART 2 Lecture 07-2 Programming in C++ PART 2 By Assistant Professor Dr. Ali Kattan 1 The while Loop and do..while loop In the previous lecture we studied the for Loop in C++. In this lecture we will cover iteration

More information

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal Lesson Goals Understand Control Structures Understand how to control the flow of a program

More information

CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING Chapter 6: One Dimensional Array

CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING Chapter 6: One Dimensional Array Lesson Outcomes At the end of this chapter, student should be able to: Define array Understand requirement of array Know how to access elements of an array Write program using array Know how to pass array

More information

Objectives. Order (sort) the elements of an array Search an array for a particular item Define, use multidimensional array

Objectives. Order (sort) the elements of an array Search an array for a particular item Define, use multidimensional array Arrays Chapter 7 Objectives Nature and purpose of an array Using arrays in Java programs Methods with array parameter Methods that return an array Array as an instance variable Use an array not filled

More information

Assignment 1 Expressions Data Types Formatted Printing Variables Scanning CSC 123 Fall 2018 Answer Sheet Short Answers

Assignment 1 Expressions Data Types Formatted Printing Variables Scanning CSC 123 Fall 2018 Answer Sheet Short Answers Assignment 1 Expressions Data Types Formatted Printing Variables Scanning CSC 123 Fall 2018 Answer Sheet Short Answers 1. Every complete statement ends with a c. a. period b. parenthesis c. semicolon d.

More information

Computer Programming: C++

Computer Programming: C++ The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2003 Muath i.alnabris Computer Programming: C++ Experiment #7 Arrays Part II Passing Array to a Function

More information

DO NOT. UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N.

DO NOT. UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. CS61B Fall 2013 UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division Test #2 Solutions DO NOT P. N. Hilfinger REPRODUCE 1 Test #2 Solution 2 Problems

More information

COSC 1P03. Chapter 1 Arrays. Introduction to Data Structures 1.2

COSC 1P03. Chapter 1 Arrays. Introduction to Data Structures 1.2 COSC 1P03 Chapter 1 Arrays Introduction to Data Structures 1.2 COSC 1P03 Arrays Collection like Pictures & Sounds Elements (components) any type (primitive or object) Non-sequential processing not just

More information

GridLang: Grid Based Game Development Language Language Reference Manual. Programming Language and Translators - Spring 2017 Prof.

GridLang: Grid Based Game Development Language Language Reference Manual. Programming Language and Translators - Spring 2017 Prof. GridLang: Grid Based Game Development Language Language Reference Manual Programming Language and Translators - Spring 2017 Prof. Stephen Edwards Akshay Nagpal Dhruv Shekhawat Parth Panchmatia Sagar Damani

More information

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types

More information

Control Structures. Lecture 4 COP 3014 Fall September 18, 2017

Control Structures. Lecture 4 COP 3014 Fall September 18, 2017 Control Structures Lecture 4 COP 3014 Fall 2017 September 18, 2017 Control Flow Control flow refers to the specification of the order in which the individual statements, instructions or function calls

More information

Two Types of Types. Primitive Types in Java. Using Primitive Variables. Class #07: Java Primitives. Integer types.

Two Types of Types. Primitive Types in Java. Using Primitive Variables. Class #07: Java Primitives. Integer types. Class #07: Java Primitives Software Design I (CS 120): M. Allen, 13 Sep. 2018 Two Types of Types So far, we have mainly been dealing with objects, like DrawingGizmo, Window, Triangle, that are: 1. Specified

More information

4. Java language basics: Function. Minhaeng Lee

4. Java language basics: Function. Minhaeng Lee 4. Java language basics: Function Minhaeng Lee Review : loop Program print from 20 to 10 (reverse order) While/for Program print from 1, 3, 5, 7.. 21 (two interval) Make a condition that make true only

More information

Lecture 3 Tao Wang 1

Lecture 3 Tao Wang 1 Lecture 3 Tao Wang 1 Objectives In this chapter, you will learn about: Arithmetic operations Variables and declaration statements Program input using the cin object Common programming errors C++ for Engineers

More information

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal Lesson Goals Understand Control Structures Understand how to control the flow of a program

More information

Exam 3 Chapters 7 & 9

Exam 3 Chapters 7 & 9 Exam 3 Chapters 7 & 9 CSC 2100-002/003 29 Mar 2017 Read through the entire test first BEFORE starting Put your name at the TOP of every page The test has 4 sections worth a total of 100 points o True/False

More information

Laboratorio di Algoritmi e Strutture Dati

Laboratorio di Algoritmi e Strutture Dati Laboratorio di Algoritmi e Strutture Dati Guido Fiorino guido.fiorino@unimib.it aa 2013-2014 Maximum in a sequence Given a sequence A 1,..., A N find the maximum. The maximum is in the first or in the

More information

Final Exam. CSC 121 Fall Lecturer: Howard Rosenthal. Dec. 13, 2017

Final Exam. CSC 121 Fall Lecturer: Howard Rosenthal. Dec. 13, 2017 Your Name: Final Exam. CSC 121 Fall 2017 Lecturer: Howard Rosenthal Dec. 13, 2017 The following questions (or parts of questions) in numbers 1-17 are all worth 2 points each. The programs have indicated

More information

There are four numeric types: 1. Integers, represented as a 32 bit (or longer) quantity. Digits sequences (possibly) signed are integer literals:

There are four numeric types: 1. Integers, represented as a 32 bit (or longer) quantity. Digits sequences (possibly) signed are integer literals: Numeric Types There are four numeric types: 1. Integers, represented as a 32 bit (or longer) quantity. Digits sequences (possibly) signed are integer literals: 1-123 +456 2. Long integers, of unlimited

More information

Data Types. Operators, Assignment, Output and Return Statements

Data Types. Operators, Assignment, Output and Return Statements Pseudocode Reference Sheet rev 4/17 jbo Note: This document has been developed by WeTeach_CS, and is solely based on current study materials and practice tests provided on the TEA website. An official

More information

Arrays. Chapter 7 (Done right after 4 arrays and loops go together, especially for loops)

Arrays. Chapter 7 (Done right after 4 arrays and loops go together, especially for loops) Arrays Chapter 7 (Done right after 4 arrays and loops go together, especially for loops) Object Quick Primer A large subset of Java s features are for OOP Object- Oriented Programming We ll get to that

More information

Review of Important Topics in CS1600. Functions Arrays C-strings

Review of Important Topics in CS1600. Functions Arrays C-strings Review of Important Topics in CS1600 Functions Arrays C-strings Array Basics Arrays An array is used to process a collection of data of the same type Examples: A list of names A list of temperatures Why

More information

ECE 122. Engineering Problem Solving with Java

ECE 122. Engineering Problem Solving with Java ECE 122 Engineering Problem Solving with Java Lecture 10 For Loops and Arrays Outline Problem: How can I perform the same operations a fixed number of times? Considering for loops Performs same operations

More information

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types and

More information

Programming in OOP/C++

Programming in OOP/C++ Introduction Lecture 3-2 Programming in OOP/C++ Arrays Part (2) By Assistant Professor Dr. Ali Kattan 1 Arrays Examples Solutions for previous assignments Write a program to enter and store your name and

More information

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #43. Multidimensional Arrays

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #43. Multidimensional Arrays Introduction to Programming in C Department of Computer Science and Engineering Lecture No. #43 Multidimensional Arrays In this video will look at multi-dimensional arrays. (Refer Slide Time: 00:03) In

More information

Lesson 6A Loops. By John B. Owen All rights reserved 2011, revised 2014

Lesson 6A Loops. By John B. Owen All rights reserved 2011, revised 2014 Lesson 6A Loops By John B. Owen All rights reserved 2011, revised 2014 Topic List Objectives Loop structure 4 parts Three loop styles Example of a while loop Example of a do while loop Comparison while

More information

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor. 3.Constructors and Destructors Develop cpp program to implement constructor and destructor. Constructors A constructor is a special member function whose task is to initialize the objects of its class.

More information

3. Except for strings, double quotes, identifiers, and keywords, C++ ignores all white space.

3. Except for strings, double quotes, identifiers, and keywords, C++ ignores all white space. Chapter 2: Problem Solving Using C++ TRUE/FALSE 1. Modular programs are easier to develop, correct, and modify than programs constructed in some other manner. ANS: T PTS: 1 REF: 45 2. One important requirement

More information

Pace University. Fundamental Concepts of CS121 1

Pace University. Fundamental Concepts of CS121 1 Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction

More information

Accelerating Information Technology Innovation

Accelerating Information Technology Innovation Accelerating Information Technology Innovation http://aiti.mit.edu Cali, Colombia Summer 2012 Lección 03 Control Structures Agenda 1. Block Statements 2. Decision Statements 3. Loops 2 What are Control

More information

Loops / Repetition Statements

Loops / Repetition Statements Loops / Repetition Statements Repetition statements allow us to execute a statement multiple times Often they are referred to as loops C has three kinds of repetition statements: the while loop the for

More information

Basics of Java: Expressions & Statements. Nathaniel Osgood CMPT 858 February 15, 2011

Basics of Java: Expressions & Statements. Nathaniel Osgood CMPT 858 February 15, 2011 Basics of Java: Expressions & Statements Nathaniel Osgood CMPT 858 February 15, 2011 Java as a Formal Language Java supports many constructs that serve different functions Class & Interface declarations

More information

Starting Out with C++: Early Objects, 9 th ed. (Gaddis, Walters & Muganda) Chapter 2 Introduction to C++ Chapter 2 Test 1 Key

Starting Out with C++: Early Objects, 9 th ed. (Gaddis, Walters & Muganda) Chapter 2 Introduction to C++ Chapter 2 Test 1 Key Starting Out with C++ Early Objects 9th Edition Gaddis TEST BANK Full clear download (no formatting errors) at: https://testbankreal.com/download/starting-c-early-objects-9thedition-gaddis-test-bank/ Starting

More information

Q1 Q2 Q3 Q4 Q5 Total 1 * 7 1 * 5 20 * * Final marks Marks First Question

Q1 Q2 Q3 Q4 Q5 Total 1 * 7 1 * 5 20 * * Final marks Marks First Question Page 1 of 6 Template no.: A Course Name: Computer Programming1 Course ID: Exam Duration: 2 Hours Exam Time: Exam Date: Final Exam 1'st Semester Student no. in the list: Exam pages: Student's Name: Student

More information

Arrays in C C Programming and Software Tools. N.C. State Department of Computer Science

Arrays in C C Programming and Software Tools. N.C. State Department of Computer Science Arrays in C C Programming and Software Tools N.C. State Department of Computer Science Contents Declaration Memory and Bounds Operations Variable Length Arrays Multidimensional Arrays Character Strings

More information

Give one example where you might wish to use a three dimensional array

Give one example where you might wish to use a three dimensional array CS 110: INTRODUCTION TO COMPUTER SCIENCE SAMPLE TEST 3 TIME ALLOWED: 60 MINUTES Student s Name: MAXIMUM MARK 100 NOTE: Unless otherwise stated, the questions are with reference to the Java Programming

More information

Announcements. PS 4 is ready, due next Thursday, 9:00pm. Midterm Exam 1: 10/14 (Fri), 9:00am-10:53am

Announcements. PS 4 is ready, due next Thursday, 9:00pm. Midterm Exam 1: 10/14 (Fri), 9:00am-10:53am Announcements PS 4 is ready, due next Thursday, 9:00pm Midterm Exam 1: 10/14 (Fri), 9:00am-10:53am Room TBD Scope: Lecture 1 to Lecture 9 (Chapters 1 to 6 of text) You may bring a sheet of paper (A4, both

More information

Module 6: Array in C

Module 6: Array in C 1 Table of Content 1. Introduction 2. Basics of array 3. Types of Array 4. Declaring Arrays 5. Initializing an array 6. Processing an array 7. Summary Learning objectives 1. To understand the concept of

More information

(Not Quite) Minijava

(Not Quite) Minijava (Not Quite) Minijava CMCS22620, Spring 2004 April 5, 2004 1 Syntax program mainclass classdecl mainclass class identifier { public static void main ( String [] identifier ) block } classdecl class identifier

More information

Sri Vidya College of Engineering & Technology

Sri Vidya College of Engineering & Technology UNIT I INTRODUCTION TO OOP AND FUNDAMENTALS OF JAVA 1. Define OOP. Part A Object-Oriented Programming (OOP) is a methodology or paradigm to design a program using classes and objects. It simplifies the

More information

The Warhol Language Reference Manual

The Warhol Language Reference Manual The Warhol Language Reference Manual Martina Atabong maa2247 Charvinia Neblett cdn2118 Samuel Nnodim son2105 Catherine Wes ciw2109 Sarina Xie sx2166 Introduction Warhol is a functional and imperative programming

More information

n Group of statements that are executed repeatedly while some condition remains true

n Group of statements that are executed repeatedly while some condition remains true Looping 1 Loops n Group of statements that are executed repeatedly while some condition remains true n Each execution of the group of statements is called an iteration of the loop 2 Example counter 1,

More information

UNIT 3 ARRAYS, RECURSION, AND COMPLEXITY CHAPTER 10 INTRODUCTION TO ARRAYS

UNIT 3 ARRAYS, RECURSION, AND COMPLEXITY CHAPTER 10 INTRODUCTION TO ARRAYS UNIT 3 ARRAYS, RECURSION, AND COMPLEXITY CHAPTER 10 INTRODUCTION TO ARRAYS EXERCISE 10.1 1. An array can contain many items and still be treated as one thing. Thus, instead of having many variables for

More information

COP 3014: Fall Final Study Guide. December 5, You will have an opportunity to earn 15 extra credit points.

COP 3014: Fall Final Study Guide. December 5, You will have an opportunity to earn 15 extra credit points. COP 3014: Fall 2017 Final Study Guide December 5, 2017 The test consists of 1. 15 multiple choice questions - 30 points 2. 2 find the output questions - 20 points 3. 2 code writing questions - 30 points

More information

5. PLEASE TAKE HOME the question bundle, but turn in 2 paper sheets: The scantron AND the paper where you wrote your programming question solution!

5. PLEASE TAKE HOME the question bundle, but turn in 2 paper sheets: The scantron AND the paper where you wrote your programming question solution! FINAL EXAM Introduction to Computer Science UA-CCI- ICSI 201--Fall13 This is a closed book and note examination, except for one 8 1/2 x 11 inch paper sheet of notes, both sides. There is no interpersonal

More information

More non-primitive types Lesson 06

More non-primitive types Lesson 06 CSC110 2.0 Object Oriented Programming Ms. Gnanakanthi Makalanda Dept. of Computer Science University of Sri Jayewardenepura More non-primitive types Lesson 06 1 2 Outline 1. Two-dimensional arrays 2.

More information

Chapter 12 Supplement: Recursion with Java 1.5. Mr. Dave Clausen La Cañada High School

Chapter 12 Supplement: Recursion with Java 1.5. Mr. Dave Clausen La Cañada High School Chapter 12 Supplement: Recursion with Java 1.5 La Cañada High School Recursion: Definitions Recursion The process of a subprogram (method) calling itself. A clearly defined stopping state must exist. The

More information

1 Lexical Considerations

1 Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Decaf Language Thursday, Feb 7 The project for the course is to write a compiler

More information

CS 230 Programming Languages

CS 230 Programming Languages CS 230 Programming Languages 09 / 16 / 2013 Instructor: Michael Eckmann Today s Topics Questions/comments? Continue Syntax & Semantics Mini-pascal Attribute Grammars More Perl A more complex grammar Let's

More information

Computer Programming, I. Laboratory Manual. Experiment #3. Selections

Computer Programming, I. Laboratory Manual. Experiment #3. Selections Think Twice Code Once The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2005 Khaleel I. Shaheen Computer Programming, I Laboratory Manual Experiment #3

More information

BaSICS OF excel By: Steven 10.1

BaSICS OF excel By: Steven 10.1 BaSICS OF excel By: Steven 10.1 Workbook 1 workbook is made out of spreadsheet files. You can add it by going to (File > New Workbook). Cell Each & every rectangular box in a spreadsheet is referred as

More information

Arrays in Java Multi-dimensional Arrays

Arrays in Java Multi-dimensional Arrays Suppose you are tasked with writing a program to help maintain seating records for a theatre company. The auditorium has 25 rows, each of which contains 30 seats. One utility you need to provide is tracking

More information

FORM 2 (Please put your name and form # on the scantron!!!!)

FORM 2 (Please put your name and form # on the scantron!!!!) CS 161 Exam 2: FORM 2 (Please put your name and form # on the scantron!!!!) True (A)/False(B) (2 pts each): 1. Recursive algorithms tend to be less efficient than iterative algorithms. 2. A recursive function

More information

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

More information

Fall Semester (081) Dr. El-Sayed El-Alfy Computer Science Department King Fahd University of Petroleum and Minerals

Fall Semester (081) Dr. El-Sayed El-Alfy Computer Science Department King Fahd University of Petroleum and Minerals INTERNET PROTOCOLS AND CLIENT-SERVER PROGRAMMING Client SWE344 request Internet response Fall Semester 2008-2009 (081) Server Module 2.1: C# Programming Essentials (Part 1) Dr. El-Sayed El-Alfy Computer

More information

Recursion. Chapter 7. Copyright 2012 by Pearson Education, Inc. All rights reserved

Recursion. Chapter 7. Copyright 2012 by Pearson Education, Inc. All rights reserved Recursion Chapter 7 Contents What Is Recursion? Tracing a Recursive Method Recursive Methods That Return a Value Recursively Processing an Array Recursively Processing a Linked Chain The Time Efficiency

More information

Repe$$on CSC 121 Spring 2017 Howard Rosenthal

Repe$$on CSC 121 Spring 2017 Howard Rosenthal Repe$$on CSC 121 Spring 2017 Howard Rosenthal Lesson Goals Learn the following three repetition structures in Java, their syntax, their similarities and differences, and how to avoid common errors when

More information

Here, type declares the base type of the array, which is the type of each element in the array size defines how many elements the array will hold

Here, type declares the base type of the array, which is the type of each element in the array size defines how many elements the array will hold Arrays 1. Introduction An array is a consecutive group of memory locations that all have the same name and the same type. A specific element in an array is accessed by an index. The lowest address corresponds

More information

Final Exam. CSC 121 Fall 2015 TTH. Lecturer: Howard Rosenthal. Dec. 15, 2015

Final Exam. CSC 121 Fall 2015 TTH. Lecturer: Howard Rosenthal. Dec. 15, 2015 Final Exam. CSC 121 Fall 2015 TTH Lecturer: Howard Rosenthal Dec. 15, 2015 Your Name: Key The following questions (or parts of questions) in numbers 1-17 are all worth 2 points each. The programs have

More information

Array Basics: Outline

Array Basics: Outline Array Basics: Outline More Arrays (Savitch, Chapter 7) TOPICS Array Basics Arrays in Classes and Methods Programming with Arrays Searching and Sorting Arrays Multi-Dimensional Arrays Static Variables and

More information

Creating Two-dimensional Arrays

Creating Two-dimensional Arrays ANY TYPE CAN BE USED as the base type of an array. You can have an array of ints, an array of Strings, an array of Objects, and so on. In particular, since an array type is a first-class Java type, you

More information

Lecture #8-10 Arrays

Lecture #8-10 Arrays Lecture #8-10 Arrays 1. Array data structure designed to store a fixed-size sequential collection of elements of the same type collection of variables of the same type 2. Array Declarations Creates a Storage

More information