Teaching%20Session%206

Teaching%20Session%206 - Engineering 1D04 Teaching Session...

Info iconThis preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Engineering 1D04 Teaching Session 6 © Copyright 2006 David Das, Ryan Lortie, Alan Wassyng 1 Records s So far we've seen a number of different types of variables: c Integers (int) c Strings (string) c Floating Point Numbers (float, double) c Boolean Values (bool) © Copyright 2006 David Das, Ryan Lortie, Alan Wassyng 2 Records s In many cases, we have a need to represent data more complex than a single number or a text string. © Copyright 2006 David Das, Ryan Lortie, Alan Wassyng 3 Alice Eve Bob Charlie A string An array containing 4 strings 7000 5000 4000 2000 An integer An array containing 4 integers 3 2 1 3 2 1 High Scores s Recall the high score system. c We used two separate arrays to store the following items: • The top ten scores • The names associated with those scores © Copyright 2006 David Das, Ryan Lortie, Alan Wassyng 4 for (j = names.Length - 1; j > i; j--) names[j] = names[j-1]; scores[j] = scores[j-1]; names[i] = name; scores[i] = score; Alice Eve Bob Charlie 7000 5000 4000 2000 New score to be inserted here j 1 i Dave 6000 3 2 1 3 2 1 3 2 1 3 2 1 High Scores © Copyright 2006 David Das, Ryan Lortie, Alan Wassyng 5 Alice Eve Bob Charlie 7000 5000 4000 2000 New score to be inserted here j 1 i Dave 6000 Before starting, notice that Eve's score is 5000. 3 2 1 3 2 1 High Scores for (j = names.Length - 1; j > i; j--) names[j] = names[j-1]; scores[j] = scores[j-1]; names[i] = name; scores[i] = score; © Copyright 2006 David Das, Ryan Lortie, Alan Wassyng 6 for (j = names.Length - 1; j > i; j--) names[j] = names[j-1]; scores[j] = scores[j-1]; names[i] = name; scores[i] = score; Alice Eve Bob Charlie 7000 5000 4000 2000 New score to be inserted here 3 j 1 i Dave 6000 3 2 1 3 2 1 High Scores © Copyright 2006 David Das, Ryan Lortie, Alan Wassyng 7 for (j = names.Length - 1; j > i; j--) names[j] = names[j-1]; scores[j] = scores[j-1]; names[i] = name; scores[i] = score; Alice Eve Bob Bob 7000 5000 4000 2000 New score to be inserted here 3 j 1 i Name moves Dave 6000 3 2 1 3 2 1 High Scores © Copyright 2006 David Das, Ryan Lortie, Alan Wassyng 8 for (j = names.Length - 1; j > i; j--) names[j] = names[j-1]; scores[j] = scores[j-1]; names[i] = name; scores[i] = score; Alice Eve Bob Bob 7000 5000 4000 2000 New score to be inserted here 2 j 1 i Name moves but score does not! Dave 6000 3 2 1 3 2 1 High Scores © Copyright 2006 David Das, Ryan Lortie, Alan Wassyng 9 for (j = names.Length - 1; j > i; j--) names[j] = names[j-1]; scores[j] = scores[j-1]; names[i] = name; scores[i] = score; Alice Eve Eve Bob 7000 5000 4000 2000 New score to be inserted here 2 j 1 i Dave 6000 3 2 1 3 2 1 High Scores Name moves but score does not! © Copyright 2006 David Das, Ryan Lortie, Alan Wassyng 10 for (j = names.Length - 1; j > i; j--) names[j] = names[j-1]; scores[j] = scores[j-1]; names[i] = name; scores[i] = score; Alice Eve Eve Bob 7000 5000 4000 2000 New score to be inserted here 1 j 1 i No longer true Dave 6000 3 2 1 3 2 1 High Scores © Copyright 2006 David Das, Ryan Lortie, Alan Wassyng...
View Full Document

This note was uploaded on 12/05/2010 for the course MATH 1Z04 taught by Professor Childs during the Spring '08 term at McMaster University.

Page1 / 86

Teaching%20Session%206 - Engineering 1D04 Teaching Session...

This preview shows document pages 1 - 12. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online