MultiMedia Individual Assignment – Storyboard

 

001 002 003

http://www.binus.ac.id/
http://bcs.binus.ac.id/
http://bm3.binus.ac.id/

Categories: About Me | Leave a comment

KBP Chapter 13 – Concurrency Assignment Pak Tri Djoko Wahjono

1. Three possible levels of concurrency in programs:
• instruction level (executing two or more machine instructions simultaneously),
• statement level (executing two or more high-level language statements simultaneously)
• unit level (executing two or more subprogram units simultaneously)

2. In an SIMD computer, each processor has its own local memory. One processor controls the operation of the other processors. Because all of the processors, except the controller, execute the same instruction at the same time, no synchronization is required in the software.

5. Unit-level concurrency is best supported by MIMD computers.

6. Vector processor have groups of registers that store the operands of a vector operation in which
the same instruction is executed on the whole group of operands simultaneously.

7. Physical concurrency is several program units from the same program that literally execute simultaneously.

Logical concurrency is multiple processors providing actual concurrency, when in fact the actual execution of programs is taking place in interleaved fashion on a single processor.

8. A scheduler manages the sharing of processors among the tasks. If there were never any interruptions and tasks all had the same priority, the scheduler could simply give each task a time slice, such as 0.1 second, and when a task’s turn came, the scheduler could let it execute on a processor for that amount of time.

16. A task descriptor is a data structure that stores all of the relevant information about the execution state of a task.

18. The purpose of a task-ready queue is to be storage of tasks that are ready to run.

21. A binary semaphore is a semaphore that requires only a binary-valued counter.

A counting semaphore is a synchronization object that can have an arbitrarily large number of states.

30. Ada terminate clause, when selected, means that the task is finished with its job but is not yet terminated. Task termination is discussed later in this section.

34. Sleep method in Java blocks the the thread.

35. Yield method in Java surrenders the processor voluntarily as a request from the running thread.

36. The join method in Java is used to force a method to delay its execution until the run method of another thread has completed its execution.

55. Concurrent ML is an extension to ML that includes a fform of threads and a form of synchronous message passing to support concurrency.

56. The use of spawn primitive of CML is to take the function as its parameter and to create a thread.

57. The use of subprograms BeginInvoke and Endinvoke in F# is to call threads asynchronously.

60. What is the type of an F# heap-allocated mutatable variable?

A mutable heap-allocated variable is of type ref

63. The FORALL statement of High-Performance Fortran is to specifies a sequence of assignment statements that may be executed concurrently.

PROBLEM SET

1. Explain clearly why a race condition can create problems for a system.

Race condition can create problems for a system, because two or more tasks are racing to use the shared resource and the behavior of the program depends on which task arrives first (and wins the race).

2. The different ways to handle deadlock:

– Ignoring deadlock

– Detection

– Prevention

– Avoidance

3. Busy waiting is a method whereby a task waits for a given event by continuously checking for that event to occur. What is the main problem with this approach?

Busy-waiting or spinning is a technique in which a process repeatedly checks to see if a condition is true, such as whether keyboard input or a lock is available. Spinning can also be used to generate an arbitrary time delay, a technique that was necessary on systems that lacked a method of waiting a specific length of time. Processor speeds vary greatly from computer to computer, especially as some processors are designed to dynamically adjust speed based on external factors, such as the load on the operating system. Busy waiting may loop forever and it may cause a computer freezing.

Categories: Tugas | Leave a comment

KBP Chapter 12 – Support for Object-Oriented Programming Assignment Pak Tri Djoko Wahjono

2. The problems associated with programming using abstract data types are:

• In nearly all cases, the features and capabilities of the existing type are not quite right for the new use.

• The type definitions are all independent and are at the same level.

3. The advantage of inheritance is inheritance offers a solution to both the modification problem posed by abstract data type reuse and the program organization problem. If a new abstract data type can inherit the data and functionality of some existing type, and is also allowed to modify some of those entities and add new entities, reuse is greatly facilitated without requiring changes to the reused abstract data type.

4. Message protocol is the entire collection of methods of an object.

6. Describe a situation where dynamic binding is a great advantage over its absence.
– There is a base class, A, that defines a method draw that draws some figure associated with the base class. A second class, B, is defined as a subclass of A. Objects of this new class also need a draw method that is like that provided by A but a bit different. With overriding, we can directly modify B’s draw function. But without it, we either make a specific function in A for B and inherit it.

7. Dynamic dispatch is the third characteristic (after abstract data types and inheritance) of object-oriented programming language which is a kind of polymorhphism provided by the dynamic binding of messages to method definitions.

8. An abstract method is an implemented method which all of descendant class should have and it is included in Building.

An abstract class is a class that includes at least one abstract method.

10. An inner class is a nonstatic class that is nested directly in another class.

12. All Smalltalk objects are allocated from the heap and are referenced through reference variables, which are implicitly dereferenced.

15. Smalltalk supports single inheritance; it does not allow multiple inheritance.

19. C++ heap-allocated objects are deallocated using destructor.

29. No Objective-C doesn’t support it. Objective-C only supports single inheritance.

31. The root class in Objective-C is called NSObject

38. Boxing is primitive values in Java 5.0+ which is implicitly coerced when they are put in object context. This coercion converts the primitive value to an object of the wrapper class of the primitive value’s type.

49. Access control in Ruby is different for data than it is for methods. All instance data has private access by default, and that cannot be changed. If external access to an instance variable is required, accessor methods must be defined.

PROBLEM SET

2. In what ways can “compatible “ be defined for the relationship between an overridden method and the overriding method?

Every overriding method must have the same number of parameters as the overridden method and the types of the parameters and the return type must be compatible with those of the parent class.

3. Compare the inheritance of C++ and Java.

• In Java, all objects are Inherited, either directly or indirectly. While in C++ a class can be defined to stand on its own without an ancestor.

• The meaning of protected member access specifier is somewhat different in Java. In Java, protected members of a class “A” are accessible in other class “B” of same package, even if B doesn’t inherit from A (they both have to be in the same package).

• Java uses extends keyword for inheritence. Unlike C++, Java doesn’t provide an inheritance specifier like public, protected or private. Therefore, we cannot change the protection level of members of base class in Java, if some data member is public or protected in base class then it remains public or protected in derived class. Like C++, private members of base class are not accessible in derived class. Unlike C++, in Java, we don’t have to remember those rules of inheritance which are combination of base class access specifier and inheritance specifier.

5. Compare abstract class and interface in Java.

• First and major difference between abstract class and interface is that, abstract class is a class while interface is a interface, means by extending abstract class you can not extend another class because Java does not support multiple inheritance but you can implement multiple inheritance in Java.
• Second difference between interface and abstract class in Java is that you can not create non abstract method in interface, every method in interface is by default abstract, but you can create non abstract method in abstract class. Even a class which doesn’t contain any abstract method can be abstract by using abstract keyword.
• Third difference between abstract class and interface in Java is that abstract class are slightly faster than interface because interface involves a search before calling any overridden method in Java. This is not a significant difference in most of cases but if you are writing a time critical application than you may not want to leave any stone unturned.
• Fourth difference between abstract class vs interface in Java is that, interface are better suited for Type declaration and abstract class is more suited for code reuse and evolution perspective.
• Another notable difference between interface and abstract class is that when you add a new method in existing interface it breaks all its implementation and you need to provide an implementation in all clients which is not good. By using abstract class you can provide default implementation in super class.

7. What is one programming situation where multiple inheritance has a significant disadvantage over interfaces?

A situation when there are two classes derived from a common parent and those two derived class has one child.

9. Give an example of inheritance in C++, where a subclass overrides the superclass methods.

class Enemy{

protected:

int Hp;

public:

void attack(){

cout<<”Enemy Attacks using GUN!!”<<endl;
}
};

class BossEnemy: public Enemy{

public:

void attack(){

cout<<”Boss Enemy attacks using MAGIC!!”<<endl;
}
};

10. Explain one advantage of inheritance.

One of the key benefits of inheritance is to minimize the amount of duplicate code in an application by sharing common code amongst several subclasses. Where equivalent code exists in two related classes, the hierarchy can usually be refactored to move the common code up to a mutual superclass. This also tends to result in a better organization of code and smaller, simpler compilation units.

17. What are the different options for object destruction in Java?

There is no explicit deallocation operator. A finalize method is implicitly called when the garbage collector is about to reclaim the storage occupied by the object.

Categories: Tugas | Leave a comment

KBP Chapter 11 – Abstract Data Types and Encapsulation Constructs Assignment Pak Tri Djoko Wahjono

1. Two kinds of abstractions in programming languages are process abstraction and data abstraction.

5. The first design issue for abstract data types is the form of the container for the interface to the type. The second design issue is whether abstract data types can be parameterized. The third design issue is what access controls are provided and how such controls are specified.

6. Explain how information hiding is provided in an Ada package.
There are two approaches to hiding the representation from clients in the package specification. One is to include two sections in the package specification—one in which entities are visible to clients and one that hides its contents.

9. Package specification, is an Ada package which provides the interface of the encapsulation (and perhaps more)
Body package, is an Ada package which provides the implementation of most, if not all, of the entities named in the associated package specification.

10. The ‘with’ clause in Ada makes the names defined in external packages visible.

15. The purpose of a C++ destructor is to deallocate heap space (memory) that the object or class used.

16. A destructor has no return types.

20. Limited private types are useful when the usual predefined operations of assignment and comparison are not meaningful or useful.

21. Intializers in Objective-C are constructors.

26. The purpose of a Destructor is usually to clear off unused variables and clean up the memory. Java has in built memory handling mechanisms (Garbage collection) that clear off unused memory automatically. Hence there is no requirement for destructor methods. So that Java doesn’t need any destructor

27. Methods in Java must be defined completely in a class.

28. Java classes are allocated from the heap and accessed through reference variables.

PROBLEM SET

2. Suppose someone designed a stack abstract data type in which the function top returned an access path (or pointer ) rather than returning a copy of the top element. This is not a true data abstraction. Why ? Give an example that illustrates the problem.

– The problem with this is that the user is given access to the stack through the returned value of the “top” function. For example, if p is a pointer to objects of the type stored in the stack, we could have:

p = top(stack1);

*p = 42;

These statements access the stack directly, which violates the principle of a data abstraction.

4. The advantages of the nonpointer concept in Java?

• There is no memory leak such as dangling pointers or unnamed variables.

• Memory access via pointer arithmetic – this is fundamentally unsafe. Java has a robust security model and disallows pointer arithmetic for this reason.

• Array access via pointer offsets – Java does this via indexed array access so you don’t need pointers. A big advantage of Java’s indexed array access is that it detects and disallows out of bounds array access, which can be a major source of bugs.

• References to objects – Java has this, it just doesn’t call them pointers. Any normal object reference works as one of these.

8. Some drawbacks of user-defined generic classes in Java 5.0 are: for one thing, they cannot store primitives. Second, the elements cannot be indexed. Elements must be added to user-defined generic collections with the add method.

9. If the constuctor is absent in Java and C++, it will be automatically made by the compiler.

11. Destructors in C# are rarely used because it uses garbage collection for most of its heap objects.

12. Classes in Ruby are dynamic in the sense that members can be added at any time. This is done by simply including additional class definitions that specify the new members.

Categories: Tugas | Leave a comment

KBP Chapter 10 – Implementing Subprograms Assignment Pak Tri Djoko Wahjono

1. By “simple” it means that subprograms cannot be nested and all local variables are static

2. Which of the caller of callee saves execution status information ?

-Either can save the execution status

3. Execution status information be stored for the linkage to a subprogram

4. What is the task of a linker?
Its first task is to find the files that contain the translated subprograms referenced in that program and load them into memory. Then, the linker must set the target addresses of all calls to those subprograms in the main program to the entry addresses of those subprograms.

6. What is the difference between an activation record and an activation record instance?
An activation record is the format, or layout, of the moncode part of a subprogram, whereas an activation record instance is a concrete example of an activation record, a collection of data in the form of an activation record.

8. What kind of machines often use registers to pass parameters?
RISC machines, parameters are passed in registers

11. What is an EP, and what is its purpose?
EP is a point or first address of the activation record instance of the main program. It is required to control the execution of a subprogram.

14. What are two potentialproblems with the static-chain method?
• It is difficult for a programmer working on a time-critical program to estimate the costs of nonlocal references, because the cost of each reference depends on the depth of nesting between the reference and the scope of declaration.
• Subsequent code modifications may change nesting depths, thereby changing the timing of some references, both in the changed code and possibly in code far from the changes.

PROBLEM SET

6. Although local variables in Java methods are dynamically allocated at the beginning of each activation, under what circumstances could the value of a local variable in a particular activation retain the value of previous activation?
If the variable is declared as static. Static modifier is a modifier that makes a variable history – sensitive.

7. It is stated in this chapter that when nonlocal variables are accessed in a dynamic-scoped language using the dynamic chain, variable names must be stored in the activation records with the values. If this were actually done, every nonlocal access would require a sequence of costly string comparisons on names. Design an alternative to these string comparisons that would be faster.

Using approach that uses an auxiliary data structure called a display. Or, to write variable names as integers. These integers act like an array. So when the activation happens, the comparisons will be faster.

8. Pascal allows gotos with nonlocal targets. How could such statements be handled if static chains were used for nonlocal variable access? Hint:Consider the way the correct activation record instance of the static parent of a newly enacted procedure is found(see Section 10.4.2).

Based on the hint statement, the target of every goto in a program could be represented as an address and a nesting_depth, where the nesting_depth is the difference between the nesting level of the procedure that contains the goto and that of the procedure containing the target. Then, when a goto is executed, the static chain is followed by the number of links indicated in the nesting_depth of the goto target. The stack top pointer is reset to the top of the activation record at the end of the chain.

9. The static-chain method could be expanded slightly by using two static links in each activation record instance where the second points to the static grandparent activation record instance. How would this approach affect the time required for subprogram linkage and nonlocal references?

Including two static links would reduce the access time to nonlocals that are defined in scopes two steps away to be equal to that for nonlocals that are one step away. Overall, because most nonlocal references are relatively close, this could significantly increase the execution efficiency of many programs.

11. If a compiler uses the static chain approach to implementing blocks, which of the entries in the activation records for subprograms are needed in the activation records for blocks?

There are two options for implementing blocks as parameterless subprograms: One way is to use the same activation record as a subprogram that has no parameters. This is the most simple way, because accesses to block variables will be exactly like accesses to local variables. Of course, the space for the static and dynamic links and the return address will be wasted. The alternative is to leave out the static and dynamic links and the return address, which saves space but makes accesses to block variables different from subprogram locals.

Categories: Tugas | Leave a comment

KBP Chapter 9 – Subprograms Assignment Pak Tri Djoko Wahjono

1. 3 general characteristics of subprograms

• Each subprogram has a single entry point.
• The calling program unit is suspended during the execution of the called subprogram, which implies that there is only one subprogram in execution at any given time.
• Control always returns to the caller when the subprogram execution terminates.

2. A subprogram is said to be active if, after having been called, it has begun execution but has not yet completed that execution.

3. What is given in the header of a subprogram?

• First, it specifies that the following syntactic unit is a subprogram definition of some particular kind.1 In languages that have more than one kind of subprogram, the kind of the subprogram is usually specified with a special word.
• Second, if the subprogram is not anonymous, the header provides a name for the subprogram.
• Third, it may optionally specify a list of parameters.

4. Characteristics of Python subprograms that sets them apart from those of other languages:
– function def statements are executable

5. Languages allow a variable number of parameters:
– C,C++,Perl JavaScript, and Lua

8. Formal parameters are The parameters in the subprogram header. They are sometimes thought of as dummy variables because they are not variables in the usual sense.

Actual parameters are a list of parameters to be bound to the formal parameters of the subprogram.

9. The advantage of keyword parameters is that they can appear in any order in the actual parameter list.

The disadvantage to keyword parameters is that the user of the subprogram must know the names of formal parameters.

15. 3 semantic models of parameter passing?

• They can receive data from the corresponding actual parameter;

• They can transmit data to the actual parameter; or

• They can do both.

These models are called in mode, out mode, and inout mode, respectively.

24. An overloaded subprogram is a subprogram that has the same name as another subprogram in the same referencing environment.

25. Ad hoc binding is the environment of the call statement that passed the subprogram as an actual parameter

30. The design issues for functions:

• Are side effects allowed?
• What types of values can be returned?
• How many values can be returned?

 

PROBLEM SET

1. What are arguments for and against a user program building additional definitions for existing operators, as can be done in Python and C++? Do you think such user-defined operator overloading is good or bad? Support your answer.

Arguments for:

It allows the developer to program using notation “closer to the target domain” and allows user-defined types a similar level of syntactic support as types built into the language. It can easily be emulated using function calls.

Arguments against:

It can be implemented according to user’s want, eventhough it is not logically true.

I think such user-defined operator overloading is good as long as user use it according to its logical rules. User must use for example, + operator to be overloaded to implement “add” not “substraction”. And sometimes, in C++ there is condition when user need to add many data in class, so user-defined operator like this is needed to make it easier.

3. Argue in support of the templated functions of C++. How is it different from the templated functions of other languages?

It is different as C++ differentiates function based on overloading. It is not practical to make multiple function overloading in regard to writability and readability. Instead, creating a template allows a function to receive any datatype as long as the variation is based on the formal parameter definition.

5. Consider the following program written in C syntax:
void swap(int a, int b) {
int temp;
temp = a;
a = b;
b = temp;
}

void main() {
int value =1, list[5]= {2,4,6,8,10};
swap (value,list[0]);
swap(list[0],list[1]);
swap(value,list[value]);
}
for each of the following parameter-passing methods, what are all of the values of the variables value, and list after each of the three calls to swap?

a. Passed by value
b. Passed by reference
c. Passed by value-result

Answer:

a. Passed by value : value = 1, list[5] = { 2 , 4 , 6 , 8 , 10 }

b. Passed by reference: value = 6, list[5] = { 4 , 1 , 2 , 8 , 10 }

c. Passed by value-Result: value = 6, list[5] = { 4 , 1 , 2 , 8 , 10 }

6. Compare and contrast PHP’s parameter passing with that of C#

PHP’s parameter passing is similiar to that of C#, excfept that either the actual parameter or formal parameter can specify pass-by-reference. Pass by reference is specified by preceding one or both of the parameters with an ampersand.

7. Consider the following program written in C syntax:
void fun(int first, int second){
first+=first;
second+=second;
}

void main(){
int list[2] = { 3 , 5 };
fun(list[0], list[1]);
}
for each of the following parameter-passing methods, what are the values of the list array after execution?
a. Passed by value
b. Passed by reference
c. Passed by value-result

Answer:

a. Passed by value: list[2] = { 3 , 5 }

b. Passed by reference: list[2] = { 6 , 10 }

c. Passed by value-result: list[2] = { 6 , 10 }

15. How is the problem of passing multidimensional arrays handled by Ada?

Ada compilers are able to determine the defined size of the dimensions of all arrays that are used as parameters at the time subprograms are compiled

Categories: Tugas | Leave a comment

KBP Chapter 8 – Statement-Level Control Structure Assignment Pak Tri Djoko Wahjono

1. A control structure is a control statement and the collection of statements whose execution it controls.

2. Böhm and Jacopini proved that all algorithms that can be expressed by flowcharts can be coded in a programming language with only two control statements: one for choosing between two control flow paths and one for logically controlled iterations

4. There is only one design issue that is relevant to all of the selection and iteration control statements: Should the control structure have multiple entries? All selection and iteration constructs control the execution of code segments, and the question is whether the execution of those code segments always begins with the first statement in the segment.

7. An F# selector have an else clause when the if expression does return a value

9. The design issues for multiple-selection statements:
• What is the form and type of the expression that controls the selection?
• How are the selectable segments specified?
• Is execution flow through the structure restricted to include just a single selectable segment?
• How are the case values specified?
• How should unrepresented selector expression values be handled, if at all?

14. The design issues for all iterative control statements:
• How is the iteration controlled?
• Where should the control mechanism appear in the loop statement?

15. The design issues for counter-controlled loop statements:
• What are the type and scope of the loop variable?
• Should it be legal for the loop variable or loop parameters to be changed in the loop, and if so, does the change affect loop control?
• Should the loop parameters be evaluated only once, or once for every iteration?

16. Pretest loop statements are set of statements to be executed repeatedly in which the test for loop completion occurs before the loop body is executed
Posttest loop statements are set of statements to be executed repeatedly in which the test for loop completion occurs after the loop body is executed

21. The design issues for logically controlled loop statements:
• Should the control be pretest or posttest?
• Should the logically controlled loop be a special form of a counting loop or a separate statement?

26. A user-defined iteration control is the one that issues a special call to the iterator, in which the iterator is called at the beginning of each iteration, and each time it is called, the iterator returns an element from a particular data structure in some specific order.

PROBLEM SET
1. Design issues should be considered for two-way selection statements:
• What is the form and type of the expression that controls the selection?
• How are the then and else clauses specified?
• How should the meaning of nested selectors be specified?
2. Python uses indentation to specify compound statements. Give an example in support of this statement.
if x > y :
x = y
print “case 1?
All statements equally indented are included in the compound statement.

5. What are the arguments pro and con, for Java’s approach to specify compound statements in control statements?
• Compound statements are required in control statements when the body of the if or else clause requires multiple statements.
• Java uses braces to form compound statements, which serve as the bodies of if and else clauses.

6. In C language, a control statement can be implemented using a nested if else, as well as by using a switch statement. Make a list of differences in the implementation of a nested if else and a switch statement. Also suggest under what circumstances the if else control structure is used and in which condition the switch case is used.
– Switch
• switch is usually more compact than lots of nested if else and therefore, more readable
• In many languages, switch only accepts only some data types.
if-else
• if allows complex expressions in the condition while switch wants a constant
• it accepts all data types
The if-else statement is used, in case if the programmer wants to the program to check whether a condition is true while the program is running, for example if the programmer wants to check whether a variable’s value is larger or smaller than x, he can use the if(var>x){stmts}.
The switch statements are usually used if the outcome of conditions are already known. For example ,in a menu input switch statement, the options are limited to either ‘Y’ or an ‘N’. Or numbered options. Using switch statement would allow the programmer to code with better readability than usign if-else statement.

14. State one of the main legitimate needs for gotos.
One of the main legitimate needs for gotos—premature exits from loops—can be met with highly restricted branch statements, such as break

Categories: Tugas | Leave a comment

KBP Chapter 7 – Arithmetic Expression Assignment Pak Tri Djoko Wahjono

Review Question

1. Define operator precedence and operator associativity.
operator precedence = expression evaluation partially define
the order in which the operators of different precedence levels are evaluated.

operator associativity = When an expression contains two adjacent
occurrences of operators with the same level of precedence, the question of which operator is evaluated first

3.What is a prefix operator?
the operator precede the operands

5. What operator usually has right associativity?
the indices never need to be stored

6. What associativity rules are used by APL?
all operators have the same level of
precedence. Thus, the order of evaluation of operators in APL expressions is
determined entirely by the associativity rule, which is right to left for all operators.

8. Define functional side effect.
A side effectof a function, naturally called a functional side effect,occurs when the function changes either one of its parameters or a global variable. (A global
variable is declared outside the function but is accessible in the function.

9. What is a coercion?
an implicit type conversion that is initiated by the compiler

10. What is an overloaded operator?
This multiple use of an operator and is generally thought to
be acceptable, as long as neither readability nor reliability suffers.

14. What is a mixed-mode expression?
Languages that allow arithmetic expressions is whether
an operator can have operands of different types

15. What is referential transparency?
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

1. When might you want the compiler to ignore type differences in an expression?

run time

3.Do you think the elimination of overloaded operators in your favorite language would be beneficial?Why or why not?

no, because operator need to multiply use the operator, so it won’t be hard to use the operator again and again

4. Would it be a good idea to eliminate all operator precedence rules and
require parentheses to show the desired precedence in expressions? Why
or why not?

no, because it partially define the order in which the operators of different precedence levels are evaluated

9.Assume the following rules of associativity and precedence for
expressions
Show the order of evaluation of the following expressions by parenthe-sizing all subexpressions and placing a superscript on the right parenthe-sis to indicate order. For example, for the expression
a + b * c + d
the order of evaluation would be represented as

(a) ( ( ( a * b )1 – 1 )2 + c )3
(b) ( ( ( a * ( b – 1 )1 )2 / c )3 mod d )4
(c) ( ( ( a – b )1 / c )2 & ( ( ( d * e )3 / a )4 – 3 )5 )6
(d) ( ( ( – a )1 or ( c = d )2 )3 and e )4
(e) ( ( a > b )1 xor ( c or ( d <= 17 )2 )3 )4
(f) ( – ( a + b )1 )2

 

13. Let the function fun be defined as

What is the value of xafter the assignment statement in main, assuming
a. operands are evaluated left to right.
b. operands are evaluated right to left.

(a) (left -> right) sum1 is 46; sum2 is 48
(b) (right -> left) sum1 is 48; sum2 is 46

14. What is your primary argument against (or for) the operator precedence
rules of APL?

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 effect in C.

Because C programming is sensitive and it not detecting where is functional side effect

Categories: Tugas | Leave a comment

KBP Chapter 6 – Data Types Assignment Pak Tri Djoko Wahjono

Review Question
1. What is a descriptor?
descriptor is the collection of the attributes of a variable.

2. What are the advantages and disadvantages of decimal data types?
advantage = able to precisely store dec-imal values, at least those within a restricted range, which cannot be done
with floating-point.
disadvantage = that the range of val-ues is restricted because no exponents are allowed, and their representation in
memory is mildly wasteful, for reasons discussed in the following paragraph.

3. What are the design issues of character string types?
• Should strings be simply a special kind of character array or a primitive type?

• Should strings have static or dynamic length?

4. Describe the three string lenght option.

– static lenght string = the length can be static and set when the string is created
limited
– dynamic length strings = to allow strings to have varying length up to a
declared and fixed maximum set by the variable’s definition, as exemplified
by the strings in C and the C-style strings of C++
– dynamic length strings = to allow strings to have varying length with no maxi-mum, as in JavaScript, Perl, and the standard C++ library.

5. Define ordinal, enumeration, and subrange types.
– ordinal type is one in which the range of possible values can be easily
associated with the set of positive integers
– enumeration typeis one in which all of the possible values, which are
named constants, are provided, or enumerated, in the definition
– subrange typeis a contiguous subsequence of an ordinal type

8.What are the design issues for array
• What types are legal for subscripts?
• Are subscripting expressions in element references range checked?
• When are subscript ranges bound?
• When does array allocation take place?
• Are ragged or rectangular multidimensioned arrays allowed, or both?
• Can arrays be initialized when they have their storage allocated?
• What kinds of slices are allowed, if any?
10. What happens when a nnexistent element of an array is referenced in Perl?
A reference to a nonexistent ele-ment in Perl yields undef, but no error is reported.

12. What languages support negative subscripts?
Ruby and Lua

13. What languages support array slices with stepsizes?
Ruby

17. Define row major order and column major order.
row major order = the elements of the array that have as their first subscript the lower bound value of
that subscript are stored first, followed by the elements of the second value of
the first subscript, and so forth.

column major order = the elements of an array that have as their last sub-script the lower bound value of that subscript are stored first, followed by the
elements of the second value of the last subscript, and so forth.

20.What is the structure of an associative array?
hashes

43. What is a compatible type?
compatibletype is one that either is legal for
the operator or is allowed under language rules to be implicitly converted by
compiler-generated code (or the interpreter) to a legal type.

44. Define type error.
type erroris the application of an operator to an operand of an inap-propriate type.

45. Define strongly typed.
widely acknowledged as being a highly valuable language characteris-tic

47. What is a nonconverting cast?
extracting the value of a variable of one type and using it as if it were of a different type

48. What languages have no type coercions?
Ada

49. Why are C and C++ not strongly typed?
because both include union types, which are not type checked.

50. What is name type equivalence?
Name type equivalencemeans that two
variables have equivalent types if they are defined either in the same declaration
or in declarations that use the same type name
Problem set
2. How are negative integers stored in memory?
Integer values stored in decimal waste storage in binary memory computers, simply as
a result of the fact that it takes four binary bits to store a single decimal digit, but those
four bits are capable of storing 16 different values. Therefore, the ability to store six out
of every 16 possible values is wasted. Numeric values can be stored efficiently on binary
memory computers only in number bases that are multiples of 2. If humans had
developed hands with a number of fingers that was a power of 2, these kinds of problems
would not occur.

5. What disadvantages are there in implicit dereferencing of pointers,
but only in certain contexts? For example, consider the implicit deref-erence of a pointer to a record in Ada when it is used to reference a
record field.

When implicit dereferencing of pointers occurs only in certain contexts, it makes the
language slightly less orthogonal. The context of the reference to the pointer determines
its meaning. This detracts from the readability of the language and makes it slightly more
difficult to learn

7. Compare the pointer and reference type variable in c++.
The only justification for the -> operator in C++ is writability. It is slightly
easier to write p -> q than (*p).q.

10. Multidimensional arrays can be stored in row major order, as in C++, or
in column major order, as in Fortran. Give a generic expression for the lication of the a[i,j] element in a matrix in both row major and clumn major order.

Row Major Order:
location(a[i,j,k]) = (address of a[min(1),min(2),min(3)])
+((i-min(1))*size(3) + (j-min(2)))*size(2) + (k-min(3))
Column Major Order:
location(a[i,j,k]) = (address of a[min(1),min(2),min(3)])
+((k-min(3))*size(1) + (j-min(2)))*size(2) + (i-min(1))

11. In the Burroughs Extended ALGOL language, matrices are stored as a
single-dimensioned array of pointers to the rows of the matrix, which are
treated as single-dimensioned arrays of values. What are the advantages
and disadvantages of such a scheme?

The advantage of this scheme is that accesses that are done in order of the rows can
be made very fast; once the pointer to a row is gotten, all of the elements of the row can
be fetched very quickly. If, however, the elements of a matrix must be accessed in
column order, these accesses will be much slower; every access requires the fetch of a
row pointer and an address computation from there. Note that this access technique was
devised to allow multidimensional array rows to be segments in a virtual storage
management technique. Using this method, multidimensional arrays could be stored and
manipulated that are much larger than the physical memory of the computer.

15. What are the arguments for and against Head management’s single-size cells and variable-size cells?
Integer values stored in decimal waste storage in binary memory computers, simply as
a result of the fact that it takes four binary bits to store a single decimal digit, but those
four bits are capable of storing 16 different values. Therefore, the ability to store six out
of every 16 possible values is wasted. Numeric values can be stored efficiently on binary
memory computers only in number bases that are multiples of 2. If humans had
developed hands with a number of fingers that was a power of 2, these kinds of problems
would not occur.

21. In what way is dynamic type checking better than static type checking?
run time

Categories: Tugas | Leave a comment

KBP Chapter 5 – The Concept of Binding Assignment Pak Tri Djoko Wahjono

Review Question

1. What are the design issues for names?
– Are names case sensitive?
– Are the special words of the language reserved words or keywords?

4. What is an alias?
a hindrance to readability because it allows a variable to have its value changed by an assignment to a different vari-able.

5. Which category of C++ reference variable is always aliases?
union types

6. What is the l-value of a variable? What is the r-value?
l-value = address of a variable
r-value = variable’s value

7. Difine binding and binding time.
binding = an association between an attribute and an entity, such as
between a variable and its type or value, or between an operation and a sym-bol.
binding time = the time at which a binding takes place

15. What is the general problem with static scoping?
First, in most cases it allows
more access to both variables and subprograms than is necessary. It is simply
too crude a tool for concisely specifying such restrictions. Second, and perhaps
more important, is a problem related to program evolution. Software is highly
dynamic—programs that are used regularly continually change.

16. What is the referencing enviroment of a statement?
referencing environment of a statement is the collection of all variables
that are visible in the statement

18. What is block?
Such vari-ables are typically stack dynamic, so their storage is allocated when the section
is entered and deallocated when the section is exited
Problem set

1. Decide which of the following indentifier names is valid in C language.
Support your decision
Student & Student123
because no consist of special character and number at the first of names

2. What is l-value? Write a statement in C language which gives the compile time error “l-value required”>
The address of a variable is sometimes called its l-value
scanf(“%d”,score);

4. Why is the type declaration of a variable necessary? What is the value range of the int type variable in Java?
because it must inclde an initial value, byte

8.a.Assuming statuc scooping, in the following, which decllaration of x is the correct one for a reference to x?
b.Repeat part a, but assume dynamic scoping.
(a) i. Sub1
ii. Sub126
iii. Main
(b) i. Sub1
ii. Sub1
iii. Sub1

Categories: Tugas | Leave a comment

Blog at WordPress.com.