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

Info icon This preview shows pages 1–13. Sign up to view the full content.

Engineering 1D04 Teaching Session 6
Image of page 1

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

© Copyright 2006 David Das, Ryan Lortie, Alan Wassyng 1 Records square4 So far we've seen a number of different types of variables: circle4 Integers (int) circle4 Strings (string) circle4 Floating Point Numbers (float, double) circle4 Boolean Values (bool)
Image of page 2
© Copyright 2006 David Das, Ryan Lortie, Alan Wassyng 2 Records square4 In many cases, we have a need to represent data more complex than a single number or a text string.
Image of page 3

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

© 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 0 3 2 1 0 High Scores square4 Recall the high score system. circle4 We used two separate arrays to store the following items: The top ten scores The names associated with those scores
Image of page 4
© 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 0 3 2 1 0 High Scores
Image of page 5

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

© 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 0 3 2 1 0 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;
Image of page 6
© 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 0 3 2 1 0 High Scores
Image of page 7

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

© 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 0 3 2 1 0 High Scores
Image of page 8
© 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 0 3 2 1 0 High Scores
Image of page 9

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

© 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 0 3 2 1 0 High Scores Name moves but score does not!
Image of page 10
© 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 0 3 2 1 0 High Scores
Image of page 11

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

© Copyright 2006 David Das, Ryan Lortie, Alan Wassyng 11 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 7000 4000 2000 New score to be inserted here 1 j 1 i Dave 6000 ???
Image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern