With the above definitions, what is the outcome of running the following Scala code?

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
Scala programming
Name:
Serial Number: 500
val sample ExpMul (ExpAdd (ExpInt (1), ExpInt (2)), ExpAdd (ExpInt (3), ExpInt (4)))
println (f (sample))
A: The code runs successfully and prints: 24
B: The code runs successfully and prints: 11
C: The code runs successfully and prints: 21
D: The code runs successfully and prints: 10
E: The code fails to compile because the parameter to ExpInt is called n in the class declaration, but is called m
in the function f.
RETURN ALL SHEETS FROM THIS PAPER!
Transcribed Image Text:Name: Serial Number: 500 val sample ExpMul (ExpAdd (ExpInt (1), ExpInt (2)), ExpAdd (ExpInt (3), ExpInt (4))) println (f (sample)) A: The code runs successfully and prints: 24 B: The code runs successfully and prints: 11 C: The code runs successfully and prints: 21 D: The code runs successfully and prints: 10 E: The code fails to compile because the parameter to ExpInt is called n in the class declaration, but is called m in the function f. RETURN ALL SHEETS FROM THIS PAPER!
Serial Number: 500
Name:
B: Returns 10.
C: Returns 12.
D: Returns List (10, 11, 12).
E: Returns List (12,12,12).
Question 29: Consider the C code:
#include "stdio.h"
#include "stdlib.h"
typedef int (*funcptr) (int);
int a;
funcptr f (int x) {
a = x;
int g (int y) { return a + y; }
return &g;
}
int main (void)
{
funcptr h= f (10);
printf ("result = %d\n", h (20));
return 0;
}
Which one of the following statements is true about the C code?
A: The variable a is moved to the heap at runtime.
B: The variable x is moved to the heap at runtime.
C: The call to h is standard C and does not need the GCC extension for nested functions.
D: The call to h is unsafe when using the GCC extension for nested functions.
E: The call to h is safe when using the GCC extension for nested functions.
Question 30: Consider the Scala definitions:
sealed abstract class Exp
case class ExpInt (n: Int) extends Exp.
case class ExpAdd (e1: Exp, e2: Exp) extends Exp
case class ExpMul (e1: Exp, e2: Exp) extends Exp
def f (e: Exp): Inte match {
case ExpInt (m) => m
case ExpAdd (e1, e2) => f (el) + f (e2)
case ExpMul (e1, e2) => f (e1) * f (e2)
}
With the above definitions, what is the outcome of running the following Scala code?
Transcribed Image Text:Serial Number: 500 Name: B: Returns 10. C: Returns 12. D: Returns List (10, 11, 12). E: Returns List (12,12,12). Question 29: Consider the C code: #include "stdio.h" #include "stdlib.h" typedef int (*funcptr) (int); int a; funcptr f (int x) { a = x; int g (int y) { return a + y; } return &g; } int main (void) { funcptr h= f (10); printf ("result = %d\n", h (20)); return 0; } Which one of the following statements is true about the C code? A: The variable a is moved to the heap at runtime. B: The variable x is moved to the heap at runtime. C: The call to h is standard C and does not need the GCC extension for nested functions. D: The call to h is unsafe when using the GCC extension for nested functions. E: The call to h is safe when using the GCC extension for nested functions. Question 30: Consider the Scala definitions: sealed abstract class Exp case class ExpInt (n: Int) extends Exp. case class ExpAdd (e1: Exp, e2: Exp) extends Exp case class ExpMul (e1: Exp, e2: Exp) extends Exp def f (e: Exp): Inte match { case ExpInt (m) => m case ExpAdd (e1, e2) => f (el) + f (e2) case ExpMul (e1, e2) => f (e1) * f (e2) } With the above definitions, what is the outcome of running the following Scala code?
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY