EECS 183 Discussion #10: I’m actually Alex Trebek. November 15th, 2016

1 EECS 183 Discussion #10: I’m actually Alex Trebek. Nove...
Author: Vivian Wilson
0 downloads 0 Views

1 EECS 183 Discussion #10: I’m actually Alex Trebek. November 15th, 2016Kevin Lee (mrkevin)

2 Topics for Exam 2 Questions? C++ Pass by ReferenceOne-dimensional Arrays Multi-dimensional Arrays File I/O Steam states Classes Member variables / functions Testing Questions?

3 Game plan Any Questions about Material? Jeopardy!Bonus Free Response Practice Example

4 any questions? Before we begin, any questions?

5 JEOPARDY! (wow is this high school?)

6 THE TOPICS FOR TODAY ARE:

7 I/O MY GOD File input and output! Get those #include s ready!

8 [A][R][R][A][Y][S] (It’s… about arrays. Don’t know how more specific I can make this title)

9 DINOS 101 (Welcome to class! Get it? It’s about classes but with a Dinosaur-ific twist!)

10 HISS HISS (Don’t get bit! All about Python.)

11 KEVIN IS  (Wildcard topic! Why is Kevin sad this time?)

12 I/O my god! [A][R][R][A][Y][S] DINOS 101 HISS HISS KEVIN IS  100 100 100 100 100 200 200 200 200 200 300 300 300 300 300 400 400 400 400 400 500 500 500 500 500

13 I/O my god! – 100 Points QUESTION: ANSWER: What is “Go Blue”?This is what prints when the user types in: Go Blue into the following code snippet. ANSWER: What is “Go Blue”?

14 I/O my god! – 200 Points QUESTION: ANSWER: What is A?Consider the below code. This is the correct answer. A) ifstream is a class B) ifstream is not a class C) Neither ANSWER: What is A?

15 I/O my god! – 300 Points QUESTION: ANSWER: What is:This is the entire correct body code for reading in the first integer in a file named “Jeopardy.txt”. ANSWER: What is:

16 I/O my god! – 400 Points QUESTION: ANSWER: What is 10?This is what prints from the following code if “infile.txt” contains the text: “10 a ”. ANSWER: What is 10?

17 DAILY DOUBLE!

18 I/O my god! – 500 Points QUESTION: ANSWER: What is 12?Consider the code below. This is what prints when “file.txt” contains “ ”. ANSWER: What is 12?

19 [A][R][R][A][Y][S] – 100 PointsQUESTION: A “____” can be used to traverse and print all of the components of an array, and is what we encourage in this class. ANSWER: What is “for loop”?

20 [A][R][R][A][Y][S] – 200 PointsQUESTION: How many elements are in the following array? ANSWER: What is 294?

21 [A][R][R][A][Y][S] – 300 PointsQUESTION: This is the double for loop that is required to print out every index of the array backwards. Assume the array name is arr. ANSWER: What is: Example:

22 DAILY DOUBLE!

23 [A][R][R][A][Y][S] – 400 PointsQUESTION: This is the for loop needed to reverse the following array using the variable SIZE. ANSWER: What is:

24 [A][R][R][A][Y][S] – 500 PointsQUESTION: This is the nested for loop required to print out the diagonal of a two-dimensional array backwards. Assume the name of the array is arr. ANSWER: What is: Example:

25 dinos 101 – 100 Points QUESTION: ANSWER: What is a “constructor”?This is the name for the code that initializes JurassicWorld’s private member variable “actor” to “Chris Pratt”. ANSWER: What is a “constructor”?

26 dinos 101 – 200 Points QUESTION: ANSWER: What is a “JurassicWorld”?This is the data type of x[30]. ANSWER: What is a “JurassicWorld”?

27 Dinos 101 – 300 Points QUESTION: ANSWER: What is:This is the declaration of the code that sets the private member variable “actor” in JurassicWorld to “Chris Pratt”? ANSWER: What is:

28 Dinos 101 – 400 Points QUESTION: ANSWER: What is:This is the line of code to print the actor’s mother’s name. ANSWER: What is:

29 DAILY DOUBLE!

30 Dinos 101 – 500 Points QUESTION: ANSWER: What is:Write the implementation of member function “setTired()” that is inside JurassicWorld that sets actor’s isTired to true if and only if runtime is greater than ANSWER: What is:

31 DAILY DOUBLE!

32 HISS HISS – 100 Points QUESTION: ANSWER: What are:These are just three differences between Python and C++. Example: C++ requires “#include” wheras Python uses “import”. ANSWER: What are: Python uses raw_input(), C++ uses cin Python uses print, C++ uses cout Python is interpreted, C++ is compiled Python does not need a type when declaring variables Python’s lists can be of different types Python can negatively index a list

33 HISS HISS – 200 Points QUESTION:These are two different ways to index the 3rd element, “Hello”, in this following list (one will use positive indexing, one will use negative): ANSWER: What are myList[2] and myList[-4]?

34 HISS HISS – 300 Points QUESTION: ANSWER: What is:This is what the following code will print: ANSWER: What is:

35 HISS HISS – 400 Points QUESTION:This is an explanation to the question: “Is Python pass by reference or pass by value?” ANSWER: What is “simple types are passed by value, these include strings and ints. Complex types with member functions are passed by reference. These include the list’s .append() function”?

36 HISS HISS – 500 Points QUESTION: ANSWER: What is: ?? BThis is what prints from the following code: ANSWER: What is: ?? B (type answer here)

37 Kevin is  – 100 Points QUESTION: ANSWER: What is .eof()?Kevin is  because he used an EECS 183 forbidden way to check whether or not the file stream has reached the end of the file. This is the way. ANSWER: What is .eof()?

38 Kevin is  – 200 Points QUESTION: ANSWER: What is:Kevin is  because he forgot how to write a setter function for his class in KevinIsSad.cpp. This is how he should write it. ANSWER: What is:

39 Kevin is  – 300 Points QUESTION: ANSWER: What is E?Kevin is  because he does not know if his code is right. Please check it for him! This is the correct answer. A) x is 6 B) x is 3 C) x is undetermined D) Seg. Fault E) Compiler Error F) Kevin, why? ANSWER: What is E?

40 Kevin is  – 400 Points QUESTION: ANSWER: What is:Kevin is  because, in Python, everyone prints variables the same way, by using the comma operator. He wants to be 2H!pster4U, and wants to use the % operator to print. This is how he can print the following info. ANSWER: What is:

41 DAILY DOUBLE!

42 Kevin is  – 500 Points QUESTION: ANSWER: What is:Kevin is  because his code isn’t working correctly. He wants to increment every value in an int array by one. These are at least three things that are wrong with his code. ANSWER: What is: int &arr[] is incorrect, as arrays are always passed by reference. arr[i] is incorrect as it starts at i = size, thus it must be arr[i – 1]. arr[i] could also be correct, but that means starting at int i = size – 1 and i >= 0. arr = addOne(arr, 5)is incorrect as addOne is a void function.

43 Free response Here are two fantastic free response questions!

44