CSC 335 Review Game Exam 2. Teams Andrew, Marshall, Riley, Z Emily, Paul, Dawn, Lisa Gavan,...
-
Upload
jean-knight -
Category
Documents
-
view
214 -
download
0
Transcript of CSC 335 Review Game Exam 2. Teams Andrew, Marshall, Riley, Z Emily, Paul, Dawn, Lisa Gavan,...
![Page 1: CSC 335 Review Game Exam 2. Teams Andrew, Marshall, Riley, Z Emily, Paul, Dawn, Lisa Gavan, Catharine, David, Alex D Michelle, Matt, Rohan, Jamie Ben,](https://reader033.fdocuments.us/reader033/viewer/2022051621/56649ea05503460f94ba2d3d/html5/thumbnails/1.jpg)
CSC 335 Review Game
Exam 2
![Page 2: CSC 335 Review Game Exam 2. Teams Andrew, Marshall, Riley, Z Emily, Paul, Dawn, Lisa Gavan, Catharine, David, Alex D Michelle, Matt, Rohan, Jamie Ben,](https://reader033.fdocuments.us/reader033/viewer/2022051621/56649ea05503460f94ba2d3d/html5/thumbnails/2.jpg)
Teams
• Andrew, Marshall, Riley, Z• Emily, Paul, Dawn, Lisa• Gavan, Catharine, David, Alex D• Michelle, Matt, Rohan, Jamie• Ben, Jerry, Alex Z, John• Casey, Zane, Lawrence, Alexis• Hugh, Zack, Fritz, Dillon• Colby, Malecki, Spencer, Tim, Patrick
![Page 3: CSC 335 Review Game Exam 2. Teams Andrew, Marshall, Riley, Z Emily, Paul, Dawn, Lisa Gavan, Catharine, David, Alex D Michelle, Matt, Rohan, Jamie Ben,](https://reader033.fdocuments.us/reader033/viewer/2022051621/56649ea05503460f94ba2d3d/html5/thumbnails/3.jpg)
Individual Round
![Page 4: CSC 335 Review Game Exam 2. Teams Andrew, Marshall, Riley, Z Emily, Paul, Dawn, Lisa Gavan, Catharine, David, Alex D Michelle, Matt, Rohan, Jamie Ben,](https://reader033.fdocuments.us/reader033/viewer/2022051621/56649ea05503460f94ba2d3d/html5/thumbnails/4.jpg)
1.
• What are the values of x & y at the end?
int x = 3;
int y = 1;
y = ++x;
![Page 5: CSC 335 Review Game Exam 2. Teams Andrew, Marshall, Riley, Z Emily, Paul, Dawn, Lisa Gavan, Catharine, David, Alex D Michelle, Matt, Rohan, Jamie Ben,](https://reader033.fdocuments.us/reader033/viewer/2022051621/56649ea05503460f94ba2d3d/html5/thumbnails/5.jpg)
2.
What is printed?
int *ptr;
int x = 5;
ptr = &x;
*ptr = 4;
printf(“%d”, x);
![Page 6: CSC 335 Review Game Exam 2. Teams Andrew, Marshall, Riley, Z Emily, Paul, Dawn, Lisa Gavan, Catharine, David, Alex D Michelle, Matt, Rohan, Jamie Ben,](https://reader033.fdocuments.us/reader033/viewer/2022051621/56649ea05503460f94ba2d3d/html5/thumbnails/6.jpg)
3.
• Finish the function:
int add(int *a, int *b){
return __________;
}
![Page 7: CSC 335 Review Game Exam 2. Teams Andrew, Marshall, Riley, Z Emily, Paul, Dawn, Lisa Gavan, Catharine, David, Alex D Michelle, Matt, Rohan, Jamie Ben,](https://reader033.fdocuments.us/reader033/viewer/2022051621/56649ea05503460f94ba2d3d/html5/thumbnails/7.jpg)
4.
• Call the function:
int f = 712;
int g = 63;
int sum = add(____,____);
int add(int *a, int *b){
![Page 8: CSC 335 Review Game Exam 2. Teams Andrew, Marshall, Riley, Z Emily, Paul, Dawn, Lisa Gavan, Catharine, David, Alex D Michelle, Matt, Rohan, Jamie Ben,](https://reader033.fdocuments.us/reader033/viewer/2022051621/56649ea05503460f94ba2d3d/html5/thumbnails/8.jpg)
5.
• Which is true of C?– It is a third-generation language.– It is imperative.– It is procedural.
![Page 9: CSC 335 Review Game Exam 2. Teams Andrew, Marshall, Riley, Z Emily, Paul, Dawn, Lisa Gavan, Catharine, David, Alex D Michelle, Matt, Rohan, Jamie Ben,](https://reader033.fdocuments.us/reader033/viewer/2022051621/56649ea05503460f94ba2d3d/html5/thumbnails/9.jpg)
6.
• What is y?
y = [x % 2 ==1 for x in range(1,6)]
![Page 10: CSC 335 Review Game Exam 2. Teams Andrew, Marshall, Riley, Z Emily, Paul, Dawn, Lisa Gavan, Catharine, David, Alex D Michelle, Matt, Rohan, Jamie Ben,](https://reader033.fdocuments.us/reader033/viewer/2022051621/56649ea05503460f94ba2d3d/html5/thumbnails/10.jpg)
7.
• What is y?
y = [x for x in range(1,6) if x%3 ==1]
![Page 11: CSC 335 Review Game Exam 2. Teams Andrew, Marshall, Riley, Z Emily, Paul, Dawn, Lisa Gavan, Catharine, David, Alex D Michelle, Matt, Rohan, Jamie Ben,](https://reader033.fdocuments.us/reader033/viewer/2022051621/56649ea05503460f94ba2d3d/html5/thumbnails/11.jpg)
8.
• What regular expression matches ten symbols (letters, numbers, spaces, whatever) followed by zero or one a?
![Page 12: CSC 335 Review Game Exam 2. Teams Andrew, Marshall, Riley, Z Emily, Paul, Dawn, Lisa Gavan, Catharine, David, Alex D Michelle, Matt, Rohan, Jamie Ben,](https://reader033.fdocuments.us/reader033/viewer/2022051621/56649ea05503460f94ba2d3d/html5/thumbnails/12.jpg)
9.
• Describe Prolog in terms of:- Declarative/Procedural?- Compiled/ Interpreted?
![Page 13: CSC 335 Review Game Exam 2. Teams Andrew, Marshall, Riley, Z Emily, Paul, Dawn, Lisa Gavan, Catharine, David, Alex D Michelle, Matt, Rohan, Jamie Ben,](https://reader033.fdocuments.us/reader033/viewer/2022051621/56649ea05503460f94ba2d3d/html5/thumbnails/13.jpg)
10.
• Describe Prolog in terms of – Paradigm– Generation
![Page 14: CSC 335 Review Game Exam 2. Teams Andrew, Marshall, Riley, Z Emily, Paul, Dawn, Lisa Gavan, Catharine, David, Alex D Michelle, Matt, Rohan, Jamie Ben,](https://reader033.fdocuments.us/reader033/viewer/2022051621/56649ea05503460f94ba2d3d/html5/thumbnails/14.jpg)
11.
• Do they unify?
a(b(X),X,c(d(Y))) with a(Z,e,c(A))
![Page 15: CSC 335 Review Game Exam 2. Teams Andrew, Marshall, Riley, Z Emily, Paul, Dawn, Lisa Gavan, Catharine, David, Alex D Michelle, Matt, Rohan, Jamie Ben,](https://reader033.fdocuments.us/reader033/viewer/2022051621/56649ea05503460f94ba2d3d/html5/thumbnails/15.jpg)
12.
• What does it do?
mystery([4|T], X):- mystery(T,X1), X is X1+1.mystery([H|T],X):-mystery(T,X).
![Page 16: CSC 335 Review Game Exam 2. Teams Andrew, Marshall, Riley, Z Emily, Paul, Dawn, Lisa Gavan, Catharine, David, Alex D Michelle, Matt, Rohan, Jamie Ben,](https://reader033.fdocuments.us/reader033/viewer/2022051621/56649ea05503460f94ba2d3d/html5/thumbnails/16.jpg)
13.
• What language does it generate?S -> ABA -> aA | aB -> bbb
![Page 17: CSC 335 Review Game Exam 2. Teams Andrew, Marshall, Riley, Z Emily, Paul, Dawn, Lisa Gavan, Catharine, David, Alex D Michelle, Matt, Rohan, Jamie Ben,](https://reader033.fdocuments.us/reader033/viewer/2022051621/56649ea05503460f94ba2d3d/html5/thumbnails/17.jpg)
14.
• What makes a language context-free?
![Page 18: CSC 335 Review Game Exam 2. Teams Andrew, Marshall, Riley, Z Emily, Paul, Dawn, Lisa Gavan, Catharine, David, Alex D Michelle, Matt, Rohan, Jamie Ben,](https://reader033.fdocuments.us/reader033/viewer/2022051621/56649ea05503460f94ba2d3d/html5/thumbnails/18.jpg)
15.
• When would you prefer to write a program in Prolog rather than C?
![Page 19: CSC 335 Review Game Exam 2. Teams Andrew, Marshall, Riley, Z Emily, Paul, Dawn, Lisa Gavan, Catharine, David, Alex D Michelle, Matt, Rohan, Jamie Ben,](https://reader033.fdocuments.us/reader033/viewer/2022051621/56649ea05503460f94ba2d3d/html5/thumbnails/19.jpg)
16.
• How do you prove a language is ambiguous?
![Page 20: CSC 335 Review Game Exam 2. Teams Andrew, Marshall, Riley, Z Emily, Paul, Dawn, Lisa Gavan, Catharine, David, Alex D Michelle, Matt, Rohan, Jamie Ben,](https://reader033.fdocuments.us/reader033/viewer/2022051621/56649ea05503460f94ba2d3d/html5/thumbnails/20.jpg)
17.
• What is special about a line of C code that starts with the # symbol?
![Page 21: CSC 335 Review Game Exam 2. Teams Andrew, Marshall, Riley, Z Emily, Paul, Dawn, Lisa Gavan, Catharine, David, Alex D Michelle, Matt, Rohan, Jamie Ben,](https://reader033.fdocuments.us/reader033/viewer/2022051621/56649ea05503460f94ba2d3d/html5/thumbnails/21.jpg)
18.
• Consider the language anbn. Is it:– Regular– Context-free– Both– Neither
![Page 22: CSC 335 Review Game Exam 2. Teams Andrew, Marshall, Riley, Z Emily, Paul, Dawn, Lisa Gavan, Catharine, David, Alex D Michelle, Matt, Rohan, Jamie Ben,](https://reader033.fdocuments.us/reader033/viewer/2022051621/56649ea05503460f94ba2d3d/html5/thumbnails/22.jpg)
19.
• When might you declare a C variable with the “register” keyword?
![Page 23: CSC 335 Review Game Exam 2. Teams Andrew, Marshall, Riley, Z Emily, Paul, Dawn, Lisa Gavan, Catharine, David, Alex D Michelle, Matt, Rohan, Jamie Ben,](https://reader033.fdocuments.us/reader033/viewer/2022051621/56649ea05503460f94ba2d3d/html5/thumbnails/23.jpg)
20.
• What is aliasing?
![Page 24: CSC 335 Review Game Exam 2. Teams Andrew, Marshall, Riley, Z Emily, Paul, Dawn, Lisa Gavan, Catharine, David, Alex D Michelle, Matt, Rohan, Jamie Ben,](https://reader033.fdocuments.us/reader033/viewer/2022051621/56649ea05503460f94ba2d3d/html5/thumbnails/24.jpg)
21.
• Which regular expression gives an odd number of a’s?
![Page 25: CSC 335 Review Game Exam 2. Teams Andrew, Marshall, Riley, Z Emily, Paul, Dawn, Lisa Gavan, Catharine, David, Alex D Michelle, Matt, Rohan, Jamie Ben,](https://reader033.fdocuments.us/reader033/viewer/2022051621/56649ea05503460f94ba2d3d/html5/thumbnails/25.jpg)
22.
• What language does it generate?S -> abS | ab
![Page 26: CSC 335 Review Game Exam 2. Teams Andrew, Marshall, Riley, Z Emily, Paul, Dawn, Lisa Gavan, Catharine, David, Alex D Michelle, Matt, Rohan, Jamie Ben,](https://reader033.fdocuments.us/reader033/viewer/2022051621/56649ea05503460f94ba2d3d/html5/thumbnails/26.jpg)
23.
• Give an advantage of static scoping over dynamic scoping.
![Page 27: CSC 335 Review Game Exam 2. Teams Andrew, Marshall, Riley, Z Emily, Paul, Dawn, Lisa Gavan, Catharine, David, Alex D Michelle, Matt, Rohan, Jamie Ben,](https://reader033.fdocuments.us/reader033/viewer/2022051621/56649ea05503460f94ba2d3d/html5/thumbnails/27.jpg)
24.
• What parameter passing mechanism does C use?
![Page 28: CSC 335 Review Game Exam 2. Teams Andrew, Marshall, Riley, Z Emily, Paul, Dawn, Lisa Gavan, Catharine, David, Alex D Michelle, Matt, Rohan, Jamie Ben,](https://reader033.fdocuments.us/reader033/viewer/2022051621/56649ea05503460f94ba2d3d/html5/thumbnails/28.jpg)
All-Play
![Page 29: CSC 335 Review Game Exam 2. Teams Andrew, Marshall, Riley, Z Emily, Paul, Dawn, Lisa Gavan, Catharine, David, Alex D Michelle, Matt, Rohan, Jamie Ben,](https://reader033.fdocuments.us/reader033/viewer/2022051621/56649ea05503460f94ba2d3d/html5/thumbnails/29.jpg)
All-Play
• What is the result for the different passing schemes?
global int z = 0;
func(z);
write(z);
void func(int x){
x = z+1;
z= z+10;
}
![Page 30: CSC 335 Review Game Exam 2. Teams Andrew, Marshall, Riley, Z Emily, Paul, Dawn, Lisa Gavan, Catharine, David, Alex D Michelle, Matt, Rohan, Jamie Ben,](https://reader033.fdocuments.us/reader033/viewer/2022051621/56649ea05503460f94ba2d3d/html5/thumbnails/30.jpg)
1. int a = 22. int b = 13. Main():4. a=35. b=76. int x = 107. A(x)8. A(x):9. int a = -310. Print x11. B(x)12. B(x):13. Print aWhat is the symbol table on line 13 if there is static scoping?If Main calls A which calls B, & there’s dynamic scoping, what is symbol table on line 13?
![Page 31: CSC 335 Review Game Exam 2. Teams Andrew, Marshall, Riley, Z Emily, Paul, Dawn, Lisa Gavan, Catharine, David, Alex D Michelle, Matt, Rohan, Jamie Ben,](https://reader033.fdocuments.us/reader033/viewer/2022051621/56649ea05503460f94ba2d3d/html5/thumbnails/31.jpg)
Write regular expressions
• String is either 4 or 5 digits.• String is either 40 or 50 digits.• String includes 2 of the same number.
![Page 32: CSC 335 Review Game Exam 2. Teams Andrew, Marshall, Riley, Z Emily, Paul, Dawn, Lisa Gavan, Catharine, David, Alex D Michelle, Matt, Rohan, Jamie Ben,](https://reader033.fdocuments.us/reader033/viewer/2022051621/56649ea05503460f94ba2d3d/html5/thumbnails/32.jpg)
Write the grammar:
• L = {anbm, m>=n+2}
![Page 33: CSC 335 Review Game Exam 2. Teams Andrew, Marshall, Riley, Z Emily, Paul, Dawn, Lisa Gavan, Catharine, David, Alex D Michelle, Matt, Rohan, Jamie Ben,](https://reader033.fdocuments.us/reader033/viewer/2022051621/56649ea05503460f94ba2d3d/html5/thumbnails/33.jpg)
• Write a prolog predicate that takes a number and generates a list of that number down to one.
• generate(+Num, -List)• Example: generate(5,L) gives
L=[5,4,3,2,1]
![Page 34: CSC 335 Review Game Exam 2. Teams Andrew, Marshall, Riley, Z Emily, Paul, Dawn, Lisa Gavan, Catharine, David, Alex D Michelle, Matt, Rohan, Jamie Ben,](https://reader033.fdocuments.us/reader033/viewer/2022051621/56649ea05503460f94ba2d3d/html5/thumbnails/34.jpg)
All-play
• Write C function that counts how many numbers in an array are positive.
int numPos(int* array, int size)