首页 > > 详细

代写SP20 CSE调试C/C++语言

4/28/2020 Midterm 2: SP20 CSE 3341 - Prin Prgrmng Langs (7799)
https://osu.instructure.com/courses/75896/quizzes/326390?module_item_id=4045683 1/11
Midterm 2
Due Apr 15 at 11:59pm Points 25 Questions 8
Available Apr 15 at 8am - Apr 16 at 8am 1 day Time Limit 60 Minutes
This quiz was locked Apr 16 at 8am.
Attempt History
Attempt Time Score
LATEST Attempt 1 59 minutes 17.75 out of 25
Score for this quiz: 17.75 out of 25
Submitted Apr 15 at 9:58pm
This attempt took 59 minutes.
2 / 2 ptsQuestion 1
Consider the grammar for the Core language from your programming
assignment (available here: Here (http://web.cse.ohio-
state.edu/~heym.1/3341/BNF%20for%20Core.pdf) ). What is the First set for ?
(Assume the a Tokenizer is responsible for the and rules)
  {WHILE, READ, WRITE, IF, ID} Correct!
  {WHILE, DIGIT, WRITE, IF, lLET}
  {WHILE, READ, WRITE, IF}
  {SEMICOLON, END, ELSE}
2 / 2 ptsQuestion 2
4/28/2020 Midterm 2: SP20 CSE 3341 - Prin Prgrmng Langs (7799)
https://osu.instructure.com/courses/75896/quizzes/326390?module_item_id=4045683 2/11
Consider the grammar for the Core language from your programming
assignment (available here: Here (http://web.cse.ohio-
state.edu/~heym.1/3341/BNF%20for%20Core.pdf) ). Select the option that best
describes the rule for .
  It is not an LR(1) grammar.
  It defines an LR(1) language, and the current grammar is also LR(1).
  It definesan LR(1) language, but the current grammar is not LR(1). Correct!
  It is an LL(1) grammar.
0 / 2 ptsQuestion 3
Consider the following Java code:
class MT2 {
  static class Super {
    static int p(int i) {...}
    int m () {...}
  }
  static class Sub extends Super{
    int m (int i) {...}
  }
  static void foo() {
    Super sup = new Sub();
    Sub sub = new Sub();
    sub.m (sub.p(sup.m()));
  }
}
Assume that the code in the "..." can compile and run correctly. The code above:
  Compiles without errors or warnings. You Answered
4/28/2020 Midterm 2: SP20 CSE 3341 - Prin Prgrmng Langs (7799)
https://osu.instructure.com/courses/75896/quizzes/326390?module_item_id=4045683 3/11
  Does not compile because sub does not have an instance method p.
 
Does not compile because the method p for sub should take an integer as
its parameter.
 
Does not compile because the method m for sum should take an integer as
its parameter.
  Compiles with a warning about accessing static fields as instance fields. orrect Answer
2 / 2 ptsQuestion 4
Consider the following Java code:
class MT2 {
  static class Super {
    static int p(int i) {...}
    int m (int i) {...}
  }
  static class Sub extends Super{
    int m () {...}
  }
  static void foo() {
    Super sup = new Sub();
    Sub sub = new Sub();
    sub.m (sub.p(sup.m()));
  }
}
Assume that the code in the "..." can compile and run correctly. The code above:
4/28/2020 Midterm 2: SP20 CSE 3341 - Prin Prgrmng Langs (7799)
https://osu.instructure.com/courses/75896/quizzes/326390?module_item_id=4045683 4/11
 
Does not compile because the method m for sup should take an integer as
its parameter.
Correct!
  Does not compile because sub does not have an instance method p.
 
Does not compile because the method p for sub should take an integer as
its parameter.
 
Does not compile because the method m for sum should take an integer as
its parameter.
  Compiles with a warning about accessing static fields as instance fields.
0 / 2 ptsQuestion 5
Consider the following Java code:
class MT2 {
  static class Super {
    static int p(int i) {...}
    int m (int i) {...}
    int m () {...}
  }
  static class Sub extends Super{
  }
  static void foo() {
    Super sup = new Sub();
    Sub sub = new Sub();
    sup.m (sub.p(sub.m()));
  }
}
4/28/2020 Midterm 2: SP20 CSE 3341 - Prin Prgrmng Langs (7799)
https://osu.instructure.com/courses/75896/quizzes/326390?module_item_id=4045683 5/11
Assume that the code in the "..." can compile and run correctly. The code above:
  Compiles with a warning about accessing static fields as instance fields. orrect Answer
  Compiles without errors or warnings. You Answered
 
Does not compile because the method p for sub should take an integer as
its parameter.
  Does not compile because sub does not have an instance method p.
 
Does not compile because the method m for sum should take an integer as
its parameter.
3.75 / 6 ptsQuestion 6
Given the following C code:
void foo(int x, int* y){
  if(x < *y){
      x++; *y = *y - 1;
      foo (x , y);
  }
}
int main() {
  int x = 3, y = 7;
  foo( x, y);
}
Complete the memory stack for the moment when main has called foo(3,7),
which has called foo(4,6), which is about to return (the method body has finished
executing). For pointers, use the memory address, for non-pointers write the
values. For both pointers and non-pointers, if teh value is unknown leave the
entry black. Note: You do not need to worry about  the program counter (PC) or
return values.
4/28/2020 Midterm 2: SP20 CSE 3341 - Prin Prgrmng Langs (7799)
https://osu.instructure.com/courses/75896/quizzes/326390?module_item_id=4045683 6/11
Answer 1:
Answer 2:
Method Record Name Location Value
foo
x 0xA398 5
y 0xA397 0xA394
previous AP 0xA396
foo
x 0xA395 4
y 0xA394 0xA391
previous AP 0xA393
main
x 0xA392 7
y 0xA391 5
previous AP 0xA390 0xA30E
Current AP = 0xA396
Current SP= 0xA399
5Correct!
0xA394You Answered
A391 orrect Answer
0xA391 orrect Answer
0XA391 orrect Answer
OxA391 orrect Answer
OXA391 orrect Answer
4/28/2020 Midterm 2: SP20 CSE 3341 - Prin Prgrmng Langs (7799)
https://osu.instructure.com/courses/75896/quizzes/326390?module_item_id=4045683 7/11
Answer 3:
Answer 4:
Answer 5:
Answer 6:
Answer 7:
(You left this blank)You Answered
0xA393 orrect Answer
0XA393 orrect Answer
OxA393 orrect Answer
OXA393 orrect Answer
A393 orrect Answer
4Correct!
(You left this blank)You Answered
A390 orrect Answer
0xA390 orrect Answer
0XA390 orrect Answer
OXA390 orrect Answer
OxA390 orrect Answer
5Correct!
0xA396Correct!
0XA396 orrect Answer
OxA396 orrect Answer
OXA396 orrect Answer
4/28/2020 Midterm 2: SP20 CSE 3341 - Prin Prgrmng Langs (7799)
https://osu.instructure.com/courses/75896/quizzes/326390?module_item_id=4045683 8/11
Answer 8:
A396 orrect Answer
0xA399Correct!
0XA399 orrect Answer
OxA399 orrect Answer
OXA399 orrect Answer
A399 orrect Answer
2 / 3 ptsQuestion 7
Given the C++ code below:
int foo(int x){
    x = x + 10;
    return 10;
}
int main() {
    int x = 5;
    x = x - foo(x);
}
What is the final value for the variable x if evaluation of '-' is performed from left
to right:
x= [ Select ]
 
What is the final value for the variable x if evaluation of '-' is performed from right
to left:
x= [ Select ]
 
4/28/2020 Midterm 2: SP20 CSE 3341 - Prin Prgrmng Langs (7799)
https://osu.instructure.com/courses/75896/quizzes/326390?module_item_id=4045683 9/11
Answer 1:
Answer 2:
Answer 3:
Does this code exhibit referential transparency? Yes
-5 Correct!
5 Correct!
Yes You Answered
No orrect Answer
6 / 6 ptsQuestion 8
Consider the Java code below:
1 public class MT2Question {
2     interface Pet {
3         void petTalk();
4     }
5     static class Dog implements Pet{
6         @Override public void petTalk() {
7             System.out.println("Dog");
9         }
10     }
11     static class PoliceDog extends Dog{
12         @Override public void petTalk() {
13             System.out.println("Woof");
14         }
15     }
16     static void petTalk(Pet pd) {
17         pd.petTalk();
18     }
4/28/2020 Midterm 2: SP20 CSE 3341 - Prin Prgrmng Langs (7799)
https://osu.instructure.com/courses/75896/quizzes/326390?module_item_id=4045683 10/11
Answer 1:
Answer 2:
Answer 3:
19     public static void main (String[] args) {
20         Dog d1 = new PoliceDog();
21         Pet d2 = new Dog();
22         PoliceDog pd1 = new PoliceDog();
23         d1.petTalk();
24         petTalk(d2);
25         petTalk(pd1);
26     }
27 }
For each of the calls in the table below, select it's compile-time target.
Call on line Compile-Time target line
17 [ Select ]
23 [ Select ]
24 [ Select ]
25 [ Select ]
And select the three lines output:
[ Select ]
Dog
[ Select ]
Line 3 Correct!
Line 6 Correct!
Line 16 Correct!
4/28/2020 Midterm 2: SP20 CSE 3341 - Prin Prgrmng Langs (7799)
https://osu.instructure.com/courses/75896/quizzes/326390?module_item_id=4045683 11/11
Answer 4:
Answer 5:
Answer 6:
Answer 7:
Line 16 Correct!
Woof Correct!
Dog Correct!
Woof Correct!
Quiz Score: 17.75 out of 25

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp2
热点文章
程序代写更多图片

联系我们 - QQ: 99515681 微信:codinghelp2
© 2014 www.7daixie.com
程序代写网!