1 / 29

Rules

Rules. Two Teams Questions worth 1-3 points Entire team can confer to answer the question Max of 2 minutes per question You can use a computer on any question except “what does this program output…” Teams switch when either Three questions have been asked or

gustav
Download Presentation

Rules

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. Rules • Two Teams • Questions worth 1-3 points • Entire team can confer to answer the question • Max of 2 minutes per question • You can use a computer on any question except “what does this program output…” • Teams switch when either • Three questions have been asked or • A team answers incorrectly three times (three strikes) • After three strikes, the opposing team can “steal” the points by answering the question correctly • Team with the most points at the end wins

  2. Question 1 of 12 • Name at least two ways a List is more flexible than an array.

  3. Answer 1 (2 points) • Name at least two ways a List is more flexible than an array. • Don’t have to specify the size of the List, can add items to the end • Can remove items at a specified index • Built-in methods to search the list

  4. Question 2 (3 points) • What is the output of this code? int[] a = { 0, 1, 1, 0, 2, 1 }; int[] h = new int[3]; h[0] = 0; h[1] = 0; h[2] = 0; for (int i = 0; i < a.Length; i++) { h[a[i]]++; } Console.WriteLine(h[0]); Console.WriteLine(h[1]); Console.WriteLine(h[2]);

  5. Answer 2 • 2 • 3 • 1

  6. Question 3 (1 point) • If a method is declared to be virtual then what can we do with that method in a derived class?

  7. Answer 3 • Override it

  8. Question 4 (1 point) • Write code that creates an instance of the Dude class using the constructor (send in any data you like that is valid) class Dude { private string name; private int age; public Dude(string n, int a) { name = n; age = a; } }

  9. Answer 4 • Dude dude = new Dude("Ben Curtis", 29);

  10. Question 5 (3 point) • Write equivalent code that uses two while loops instead of two for loops for (inti = 0; i < 10; i++) { for (int j = 0; j < i; j++) { int temp = ary[j]; ary[j] = ary[i]; ary[i] = temp; } }

  11. Answer 5 • Code inti = 0; while (i < 10) { int j = 0; while (j < i) { int temp = ary[j]; ary[j] = ary[i]; ary[i] = temp; j++; } i++; }

  12. Question 6 (2 points) • What is the difference between a reference type and a primitive type?

  13. Answer 6 • Primitive type stores the actual value directly in the memory location for the variable • Reference type stores an address in memory, or a reference, to another place in memory that stores the actual value of the data

  14. Question 7 (2 points) • Give the code to create a variable named “nums” that is a List of doubles, and then add 3.5 and 10.4 to the list

  15. Answer 7 • List<double> nums = new List<double>(); • nums.Items.Add(3.5); • nums.Items.Add(10.4);

  16. Question 8 (1 point) • What is the difference between public, private, and protected?

  17. Answer 8 • Public: accessible from outside the class • Private: accessible only inside the class • Protected: accessible inside the class and in any derived classes

  18. Question 9 (3 points) • Write a class named “AfricanGrey” that is derived from Parrot and override description() to return “Grey with red tails” class Parrot { public virtual string description() { return ("Talking Bird"); } }

  19. Answer 9 • Code class AfricanGrey: Parrot { public override string description() { return ("Grey with Red Tails"); } }

  20. Question 10 (1 point) • How is it that inheritance helps us eliminate redundant code?

  21. Answer 10 • Methods or variables can be defined in parent classes and are “inherited” by any derived class, so we don’t have to write the inherited code again

  22. Question 11 (2 points) • Fill in the blanks so the method accepts an array of strings and a target string, and also invokes the method public boolsearch( __________ ary, string targetname) { for (int i = 0; i < ary.Length; i++) { if (ary[i].Equals(targetname)) return true; } return false; } public void button_click() { string[] ary = { "Joe", "Bob", "Ted" }; if (search( _______ , "Ted")) { MessageBox.Show ("Ted is in the array."); } }

  23. Answer 11 • Code public boolsearch( string[] ary, string targetname) { for (int i = 0; i < ary.Length; i++) { if (ary[i].Equals(targetname)) return true; } return false; } public void button_click() { string[] ary = { "Joe", "Bob", "Ted" }; if (search( ary, "Ted")) { MessageBox.Show ("Ted is in the array."); } }

  24. Question 12 (3 points) • Give the output private void question12(string[] a, int count) { a[2] = ""; count--; } private void button6_Click(object sender, EventArgs e) { string[] ary = { "Joe", "Bob", "Ted" }; int count = 3; question12(ary, count); Console.WriteLine("Count: " + count); for (inti = 0; i < count; i++) { Console.WriteLine(ary[i]); } }

  25. Answer 12 • Count = 3 • Joe • Bob • <blank>

  26. The End

  27. Runoff Question • Write the Money class so the following code works: Money dinero = new Money(10000, "pesos"); Money cash = new Money(5, "dollars"); // Outputs 10000 pesos MessageBox.Show(dinero.Amount+ " " + dinero.Currency); // Outputs 5 dollars MessageBox.Show(cash.Amount+ " " + cash.Currency);

  28. Answer class Money { private int amount; public int Amount { get { return amount; } set { amount = value; } } private string currency; public string Currency { get { return currency; } set { currency = value; } } public Money(int a, string c) { amount = a; currency = c; } }

More Related