Rabu, 26 November 2014
Tugas Konsep Bahasa Pemrograman Pak Tri Djoko Wahjono "Asignment Chapter VII"
REVIEW QUESTION
11. What is an overloaded operator?
Answer : Use of an operator for more than one purpose is called operator overloading.
12. Define narrowing and widening conversions.
Answer : A narrowing conversion is one that converts an object to a type that cannot include all of the values of the original type e.g., float to int
A widening conversion is one in which an object is converted to a type that can include at least approximations to all of the values of the original type. e.g., int to float.
13. In JavaScript, what is the difference between == and ===?
Answer : It is the same but === prevent its operands from being coerced.
14. What is a mixed-mode expression?
Answer : A mixed-mode expression is one that has operands of different types.
15. What is referential transparency?
Answer : A program has the property of referential transparency if any two expressions in the program that have the same value can be substituted for one another anywhere in the program, without affecting the action of the program.
PROBLEM SET
11. Write a BNF description of the precedence and associativity rules
defined for the expressions in Problem 9. Assume the only operands are
the names a,b,c,d, and e.
Answer : Precedence: Highest *, /, not
+, -, &, mod
- (unary)
=, /=, <, <=, >=, >
and
Lowest or, xor
Associativity: Left to right
<expression> → <expression> or <or_exp>
| < expression > xor <or_exp>
| <or_exp>
<or_exp> → <or_exp> and <and_exp>
| <and_exp>
< and_exp > → <and_exp> = <expr>
| <and_exp /= <expr>
| <and_exp> < <expr>
| <and_exp> <= <expr>
| <and_exp> >= <expr>
| <and_exp> > <expr>
| <expr>
<expr> → – <unary_expr>
| <unary_expr>
<unary_expr> → <unary_expr> + <term>
| <unary_expr> – <term>
| <unary_expr> & <term>
| <unary_expr> mod < term>
| <term>
< term > → < term > * < factor >
| < term > / < factor >
| not < factor >
| < factor >
< factor > → ( < expr > )
| <operand>
<operand> → a | b | c | d | e
12. Using the grammar of Problem 11, draw parse trees for the expressions
of Problem 9.
Answer :
13. Let the function fun be defined as
int fun(int *k) {
*k += 4;
return 3 * (*k) - 1;
}
Suppose fun is used in a program as follows:
void main() {
int i = 10, j = 10, sum1, sum2;
sum1 = (i / 2) + fun(&i);
sum2 = fun(&j) + (j / 2);
}
What are the values of sum1 and sum2
a. if the operands in the expressions are evaluated left to right?
b. if the operands in the expressions are evaluated right to left?
Answer :
a. sum1 = (10/2) + (3 * 10 - 1) = 5 + 29 = 34
sum2 = (3 * 14 - 1) + (14/2) = 41 + 7 = 49
b. sum1 = (14/2) + (3 * 14 - 1) = 7 + 41 = 49
sum2 = (3 * 10 - 1) + (10/2) = 29 + 5 = 34
14. What is your primary argument against (or for) the operator precedence
rules of APL?
Answer : The operator precedence rules of the common imperative languages are nearly all the same, because they are based on those of mathematics.
15. Explain why it is difficult to eliminate functional side effects in C.
Answer : One reason functional side effects would be difficult to remove from C is that all of C’s subprograms are functions, providing the ability of returning only a single data value (though it could be an array). The problem is that in many cases it is necessary (or at least convenient) to return more than one data value, which is done through the use of pointer actual parameters, which are a means of creating functional side effects
Langganan:
Posting Komentar (Atom)
Entri Populer
-
Ada hal yang pengen gua ceritain disini . Hal yang pasti semua orang rasain juga, beda sikap antara orang yang bener-bener suka sama ya...
-
Sebulan yang lalu gua masuk UI, dan ternyata murah sekali masuk UI itu . Hanya seribu rupiah bisa masuk ke salah 1 dari 10 Universitas terb...
-
Programming Language Chapter 5 ASSIGNMENT 5 30 Oct 2014 REVIEW QUESTION 11. Q: What are the advantages and disadvantages of dynamic ty...
-
Diliat dari data dan fakta dilapangan, gua sebenernya ngiri sama supir angkot, semua orang membutuhkan dia, apalagi cewek, yang biasa...
-
hmmm gue mau ngereview tentang buku yang 1 bulan lalu yang gue beli di gramedia. yaitu buku Kelakar Tanpa Batas karya Om Sammy @notaslimboy....
-
JAKARTA - Pemandangan serupa kala demam AFF Suzuki Cup 2010 tampak di Lapangan C Gelora Bung Karno, Senayan, Jakarta, Jumat (7/1/2011) pagi...
-
Oke, ini cerita yg uda lumayan lama. Kejaidannya itu waktu gue masih Kelas 3 SMP. Chekidot! Namanya Siti Rahma Hamidah (gue samar...
-
Ni gan bagi yang suka Owl city ai kasih tau sejarahnya buat yang suka owl city ini sejarah nya cekibrottt Owl City. Musik elec...
-
11. What primitive control statement is used to build more complicated control statements in languages that lack them? -> Pemilihan P...
-
Kemampuan menulis materi stand up comedy adalah hal paling dasar yang harus dimiliki seorang stand up comedian, materi inilah nantinya ya...
Tidak ada komentar:
Posting Komentar