1 / 9

Your First Data Structure: 1D Array

Your First Data Structure: 1D Array. Shirley Moore CS 1401 Spring 2013 cs1401spring2013.pbworks.com April 9-11, 2013. Agenda. Announcements Recap Exam 2 last two problems (TR only) Recap Quiz 5 (TR only) Introduction to Arrays Assignments for next class Intro to Lab 7. Announcements.

john
Download Presentation

Your First Data Structure: 1D Array

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Your First Data Structure: 1D Array Shirley Moore CS 1401 Spring 2013 cs1401spring2013.pbworks.com April 9-11, 2013

  2. Agenda • Announcements • Recap Exam 2 last two problems (TR only) • Recap Quiz 5 (TR only) • Introduction to Arrays • Assignments for next class • Intro to Lab 7

  3. Announcements • CS Seminar • April 12, 2013 -- 1:00-2:00 PM in CCSB G.0208 • Guillaume Melquiond, Universite Paris Sud • Title: Formal proof and interval arithmetic, a virtuous circle • CS Seminar • April 16, 2013 -- 2:00-3:00 PM in CCSB 3.0908 (Conference Room) • Maria Eskevich, Dublin City University • Title: Focus on Spoken Content in Multimedia Retrieval • Grades for quizzes, labs, and exams on BlackBoard • Turn in Quiz 5 redo (if you took it the first time) (TR only) • Quiz 6 on Monday, April 15; Tuesday, April 16 • Exam 2 retest on last two problems Thursday, April 11 (TR only) • First research paper due by April 25

  4. Arrays • After completing this lesson, students will be able to • declare and create arrays • access and manipulate array elements, including in loops • use arrays in programs, including as method arguments

  5. Motivating Example: Standard Deviation • Suppose you want to read in a set of values, compute the mean and the standard deviation, and report how many values are within one standard deviation of the mean. • See http://www.mathsisfun.com/data/standard-deviation.html for definitions. • We need to store the values as we read them in and then be able to process them.

  6. Class Activity • Complete the program DogHeights.java (download from class website)

  7. Arrays and Methods • Arrays can be passed to and returned by methods. • Examples from class website: • ArrayFun.java • Add a main program that • randomly fills an array and calls PrintList to print it • calls ReverseList to generate a list in the reverse order and calls PrintList to print it. • Add a method ReverseListInPlace() that reverses the list in place. Call this method from your main program and then call PrintList to print the reversed list. • Swap.java – Why does the array version work while the scalar version doesn’t?

  8. Overloaded Array Methods • Let’s revisit DogHeights.java • Implement an overloaded method for mean that takes an integer array as the first argument and an optional second argument that tells the number of items in the array (default is the length of the array). Implement an overloaded method for standard deviation that takes an integer array as the first argument, an optional second argument that tells the number of items, and an optional third argument that passes in the mean of the array. Rewrite the program to use these methods. • Suppose you wanted to use the same method name for the mean of an array but have it work for both integer and double arrays. How could you do this?

  9. Assignments for Next Class • Read textbook sections 6.1-6.2, 6.5-6.7, 6.9 • Programming Exercises (at the end of the chapter) 6.2, 6.6*, 6.12, 6.13

More Related