Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1

2 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

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

4 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

5 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]);

6 Answer 2 2 3 1

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

8 Answer 3 Override it

9 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; }

10 Answer 4 Dude dude = new Dude("Ben Curtis", 29);

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

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

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

14 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

15 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

16 Answer 7 List nums = new List (); nums.Items.Add(3.5); nums.Items.Add(10.4);

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

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

19 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"); }

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

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

22 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

23 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 bool search( __________ 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."); }

24 Answer 11 Code public bool search( 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."); }

25 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 (int i = 0; i < count; i++) { Console.WriteLine(ary[i]); }

26 Answer 12 Count = 3 Joe Bob

27 The End

28 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);

29 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; }


Download ppt "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."

Similar presentations


Ads by Google