Computer Science 2 Getting an unknown # of …. Into an array.

Slides:



Advertisements
Similar presentations
CS107 Introduction to Computer Science Lecture 5, 6 An Introduction to Algorithms: List variables.
Advertisements

Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the basic concepts and uses of arrays ❏ To be able to define C.
Advanced Decisions and Loops Chapter Some Simple Schoolroom Statistics.
Truth and while Today 15 Minutes online time to finish the random/Swing programs. Truth tables: Ways to organize results of Boolean expressions. Note Taking:
More Sequences. Review: String Sequences  Strings are sequences of characters so we can: Use an index to refer to an individual character: Use slices.
The number which appears most often in a set of numbers. Example: in {6, 3, 9, 6, 6, 5, 9, 3} the Mode is 6 (it occurs most often). Mode : The middle number.
Computer Science 1 How do you store a bunch of similar stuff?
Java Methods 11/10/2015. Learning Objectives  Be able to read a program that uses methods.  Be able to write a write a program that uses methods.
Computer Science I: Understand how to evaluate expressions with DIV and MOD Random Numbers Reading random code Writing random code Odds/evens/…
Simple “VICO” (“VIPO”) Programs (Variables, Input, Calculating or Processing, Output)
Array Review Selection Sort Get out your notes.. Learning Objectives Be able to dry run programs that use arrays Be able to dry run programs that use.
World of Wokcraft The very best in Single pan cooking themed fantasy gaming!
Permutations and Combinations Review Plus a little Dry Run, Sorting and Code.
Computer Science 2 Arrays of Records. First Record Program Input an unknown number of Team Names, School names, and Total scores. (While loop) –Output:
DEVRY COMP 122 L AB 6 L AB R EPORT AND S OURCE C ODE C HECK THIS A+ TUTORIAL GUIDELINE AT HTTP :// WWW. ASSIGNMENTCLOUD. COM / COMP -122/ COMP LAB.
7 - Programming 7J, K, L, M, N, O – Handling Data.
Some Assignments  Write a program which prints the following information about at least 5 persons: NAME MAIL-ID EMPLOYEE-CODE PHONE Eg. Umesh
2008/11/19: Lecture 18 CMSC 104, Section 0101 John Y. Park
Chapter 8 Arrays Objectives
Chapter 7 Arrays.
Array Review Selection Sort
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Chapter 4 LOOPS © Bobby Hoggard, Department of Computer Science, East Carolina University / These slides may not be used or duplicated without permission.
Use proper case (ie Caps for the beginnings of words)
Chapter 9 - Arrays Outline 6.1 Introduction 6.2 Arrays
How do you store a bunch of similar stuff?
Chapter 8 Arrays Objectives
Computer Science II First With files.
Computer Science II First With files.
© A+ Computer Science - Arrays and Lists © A+ Computer Science -
Sorts on the AP Exam Insertion Sort.
Computer Science 2 Arrays of Records.
Computer Science 2 Review the Bubble Sort
Continue on the Array of Records program
Insertion Sort Quiz on Thursday.
Computer Science 2 Arrays of Records.
Dry run Fix Random Numbers
Java Fix a program that has if Online time for Monday’s Program
Topics discussed in this section:
Insertion Sort.
CS150 Introduction to Computer Science 1
Computer Science Sorting.
Computer Science 1 1/19/2011 On the record (paper) write the following
Computer Science 2 Arrays of Records.
Arrays Topics Definition of a Data Structure Definition of an Array
How do you store a bunch of similar stuff?
Computer Science Sorting Pre-Test Discussion/program
Computer Science 2 Tally Arrays 2/4/2016.
CS 2 Records 2/22/2018.
Chapter 8 Arrays Objectives
Python Basics with Jupyter Notebook
Computer Science II Second With files.
Sorting Develop a sorting algorithm
Computer Science 2 More Trees.
Computer Science 1 while
Computer Science 1 For..do loop Dry Run Take notes on the For loop
How do you store a bunch of similar stuff?
Welcome Back CS 2 2/4/2013 On the record (paper) write the following
Computer Science I: Get out your notes.
Array Review Selection Sort
Computer Science 1 Review and finish Number base conversion
Computer Science 1 while
Insertion Sort.
Random Numbers while loop
Computer Science 1 while
2008/11/19: Lecture 18 CMSC 104, Section 0101 John Y. Park
Dry Run Fix it Write a program
Arrays Topics Definition of a Data Structure Definition of an Array
Insertion and Shell Sorts
Computer Science II First With files.
Presentation transcript:

Computer Science 2 Getting an unknown # of …. Into an array. Looking at another type of sort.

Learning Objectives Review Bubble Sort Be able to put an unknown number of items into an array. Understand how a Selection Sort Works Be able to write a program that uses the selection sort.

Bubble Sort Speed = Stability = How it works =

Warm up Show the following after each pass of the Bubble Sort High Low 20 10 8 14 61 90

How can you store an unknown number of Song Titles into an array? Type Songtype = array[1..100] of string; Var Songs:songtype; numberOfSongs:integer;

Pseudo Code Use a while loop to get the information (Semantics of a while loop!) In the condition part of the while loop also check to make sure the user does not go beyond the number of elements in the array. Include a count variable to keep track of how many items were added to the array.

Code

Another Sort Selection Sort https://www.youtube.com/watch?v=bkf3idGw8xw Speed:_________ Stability: _____________ How it works: _____________

Showing it after each pass Low High 8 30 22 15 2 45 3 High Low 10 14 3 26 15 31 7

Selection Sort: Code {*** This is just the sorting code } for pass:= 1 to size-1 do begin mark:=pass; for check:= pass to size do if numbers[check] < numbers[mark] then mark:=check; {Mark} dummy:=numbers[mark]; {Switch} numbers[mark]:=numbers[pass]; numbers[pass]:= dummy; end; {Of the for pass loop}

Program Options Song Sort: Input an unknown number of songs (but less than 100) Show out of order Sort Show in order Push: Let the user also enter the Style of music, and be able to sort by style. Name age sort Input: An unknown number of names and ages Output: The names and corresponding ages in a chart sorted by age. Push: Let the user decide if they want to sort by age or name, then sort and show the chart. Stats are great Input:9 integers Output: The mean, median, mode and range of the values Push: Let the user enter an unknown number of scores, but less than 100 and calculate the above