rules two teams questions worth 1-3 points – entire team can confer to answer the question – max...
TRANSCRIPT
![Page 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](https://reader037.vdocument.in/reader037/viewer/2022110406/56649f065503460f94c1c4be/html5/thumbnails/1.jpg)
![Page 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](https://reader037.vdocument.in/reader037/viewer/2022110406/56649f065503460f94c1c4be/html5/thumbnails/2.jpg)
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
![Page 3: 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](https://reader037.vdocument.in/reader037/viewer/2022110406/56649f065503460f94c1c4be/html5/thumbnails/3.jpg)
Question 1 of 12• Name at least two ways a List is more flexible
than an array.
![Page 4: 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](https://reader037.vdocument.in/reader037/viewer/2022110406/56649f065503460f94c1c4be/html5/thumbnails/4.jpg)
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
![Page 5: 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](https://reader037.vdocument.in/reader037/viewer/2022110406/56649f065503460f94c1c4be/html5/thumbnails/5.jpg)
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]);
![Page 6: 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](https://reader037.vdocument.in/reader037/viewer/2022110406/56649f065503460f94c1c4be/html5/thumbnails/6.jpg)
Answer 2• 2• 3• 1
![Page 7: 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](https://reader037.vdocument.in/reader037/viewer/2022110406/56649f065503460f94c1c4be/html5/thumbnails/7.jpg)
Question 3 (1 point)• If a method is declared to be virtual then what
can we do with that method in a derived class?
![Page 8: 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](https://reader037.vdocument.in/reader037/viewer/2022110406/56649f065503460f94c1c4be/html5/thumbnails/8.jpg)
Answer 3• Override it
![Page 9: 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](https://reader037.vdocument.in/reader037/viewer/2022110406/56649f065503460f94c1c4be/html5/thumbnails/9.jpg)
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; } }
![Page 10: 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](https://reader037.vdocument.in/reader037/viewer/2022110406/56649f065503460f94c1c4be/html5/thumbnails/10.jpg)
Answer 4• Dude dude = new Dude("Ben Curtis", 29);
![Page 11: 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](https://reader037.vdocument.in/reader037/viewer/2022110406/56649f065503460f94c1c4be/html5/thumbnails/11.jpg)
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; } }
![Page 12: 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](https://reader037.vdocument.in/reader037/viewer/2022110406/56649f065503460f94c1c4be/html5/thumbnails/12.jpg)
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++; }
![Page 13: 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](https://reader037.vdocument.in/reader037/viewer/2022110406/56649f065503460f94c1c4be/html5/thumbnails/13.jpg)
Question 6 (2 points)• What is the difference between a reference
type and a primitive type?
![Page 14: 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](https://reader037.vdocument.in/reader037/viewer/2022110406/56649f065503460f94c1c4be/html5/thumbnails/14.jpg)
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
![Page 15: 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](https://reader037.vdocument.in/reader037/viewer/2022110406/56649f065503460f94c1c4be/html5/thumbnails/15.jpg)
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
![Page 16: 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](https://reader037.vdocument.in/reader037/viewer/2022110406/56649f065503460f94c1c4be/html5/thumbnails/16.jpg)
Answer 7• List<double> nums = new List<double>();• nums.Items.Add(3.5);• nums.Items.Add(10.4);
![Page 17: 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](https://reader037.vdocument.in/reader037/viewer/2022110406/56649f065503460f94c1c4be/html5/thumbnails/17.jpg)
Question 8 (1 point)• What is the difference between public,
private, and protected?
![Page 18: 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](https://reader037.vdocument.in/reader037/viewer/2022110406/56649f065503460f94c1c4be/html5/thumbnails/18.jpg)
Answer 8• Public: accessible from outside the class• Private: accessible only inside the class• Protected: accessible inside the class and in
any derived classes
![Page 19: 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](https://reader037.vdocument.in/reader037/viewer/2022110406/56649f065503460f94c1c4be/html5/thumbnails/19.jpg)
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"); } }
![Page 20: 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](https://reader037.vdocument.in/reader037/viewer/2022110406/56649f065503460f94c1c4be/html5/thumbnails/20.jpg)
Answer 9• Code
class AfricanGrey : Parrot { public override string description() { return ("Grey with Red Tails"); } }
![Page 21: 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](https://reader037.vdocument.in/reader037/viewer/2022110406/56649f065503460f94c1c4be/html5/thumbnails/21.jpg)
Question 10 (1 point)• How is it that inheritance helps us eliminate
redundant code?
![Page 22: 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](https://reader037.vdocument.in/reader037/viewer/2022110406/56649f065503460f94c1c4be/html5/thumbnails/22.jpg)
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
![Page 23: 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](https://reader037.vdocument.in/reader037/viewer/2022110406/56649f065503460f94c1c4be/html5/thumbnails/23.jpg)
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."); }}
![Page 24: 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](https://reader037.vdocument.in/reader037/viewer/2022110406/56649f065503460f94c1c4be/html5/thumbnails/24.jpg)
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."); }}
![Page 25: 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](https://reader037.vdocument.in/reader037/viewer/2022110406/56649f065503460f94c1c4be/html5/thumbnails/25.jpg)
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]); }}
![Page 26: 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](https://reader037.vdocument.in/reader037/viewer/2022110406/56649f065503460f94c1c4be/html5/thumbnails/26.jpg)
Answer 12• Count = 3• Joe• Bob• <blank>
![Page 27: 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](https://reader037.vdocument.in/reader037/viewer/2022110406/56649f065503460f94c1c4be/html5/thumbnails/27.jpg)
The End
![Page 28: 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](https://reader037.vdocument.in/reader037/viewer/2022110406/56649f065503460f94c1c4be/html5/thumbnails/28.jpg)
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 pesosMessageBox.Show(dinero.Amount + " " + dinero.Currency);// Outputs 5 dollarsMessageBox.Show(cash.Amount + " " + cash.Currency);
![Page 29: 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](https://reader037.vdocument.in/reader037/viewer/2022110406/56649f065503460f94c1c4be/html5/thumbnails/29.jpg)
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; } }