Concept of Programming Language Assignment 6

Assignment given by Mr. Tri Djoko Wahjono

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

3. What are the design issues for character string types ?
Should strings be simply a special kind of character array or a primitive type ? and Should strings have static or dynamic length ?

4. Describe the three string length options.
The length can be static and set when the string is created, allow strings to have varying length up to a declared and fixed maximum set by the variable’s definition. And allow strings to have varying length with no maximum.

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 type is one in which all of the possible values, which are named constants, are provided, or enumerated, in the definition.
-Subrange type is contiguous subsequence of an ordinal type.

6. What are the advantages of user-defined enumeration types ?
Improved writability and readibility, No arithmetic operations are legal on enum types and no enumeration types can be assigned values outside its defined range.

8. What are the design issues for arrays ?
-What types are legal for subscripts ?
-Are subscripting expressions in element references range checked ?
– When are subscripts ranges bound ?
– When does array allocation take place ?
– Are ragged or rectangular multidimensional 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 an nonexistent element of an array is referenced in Perl ?
No error will be reported

11. How does JavaScript support sparse arrays ?
The value of subscripts need not to be contiguous

12. What languages support negative subscripts ?
Ruby and Lua

13. What languages support array slices with stepsizes ?
Python,Perl and Ruby

14. What array initialization feature is available in Ada that is not available in other common imperative languages ?
Listing arrays in order in which they are to be stored or direcly assigning them to an index position using the => operator

15. What is an aggregate constant ?
Nonscalar constant which value never change or are not changed during execution of the program

16. What array operations are provided specifically for single-dimensioned arrays in Ada ?
Ada allows array assignments, including those where the right side is an aggregate value rather than an array name. Ada also provides catenation, which is defined between two single-dimensioned arrays and between a single-dimensioned array and a scalar. Nearly all types in Ada have built-in relational operators for equality and inequality.

17. Define row major order and column major order.
Row major order is where elements of the array that have as their first subscript the lower bound value of the subscript are stored first.
Column major order has elements of an array that have as their last subscript the lower bound value of that subscript are stored first.

18. What is an access function for an array ?
For multidimensional array : the mapping of its base address and a set of index values to the address in memory of the element specified by index values.
For two-dimensional array : the address of an element is the base address of the structure plus the element size times the number of elements that precede it in the structure.

21. What is the purpose of level numbers in COBOL records ?
It represents relation between groupd and elementary items in COBOL

22. Define fully qualified and elliptical references to field in records.
A fully qualified reference is one in which all intermediate record names, from the largest enclosing record to the specific field are named in reference.
Elliptical reference has the field named, but any or all of the enclosing record names can be omitted, as long as the resulting reference is unambiguous in the referencing environment.

24. Are the tuples of Python mutable ?
No. They are not.

44. Define type error.
Type error is the application of an operator to an operand of an inappropriate type.

45. Define strongly typed.
Characteristic of programming language where the typing errors are always detected

Problem Set
2. How are negative integers stored in memory ?
It uses most-significant-bit (the leftmost number). The “sign bit”. If it is 1, the number is negative. Vice versa.

3. The collection of values that can be represented by a floating-point type is defined in terms of precision and range. What are precision and range ? Show the IEEE floating-point standard 754 format for single- and double-precision representation.
Precision is accuracy of the fractional part of a value. Range is a combination of the range of fractions and, more important, the range of exponents.
Representation of IEEE floating-point standard 754 format for single- and double- precision :

6. Compare the use of Boolean data types in C++ and Java. Give emphasis on their use in conditional statements and conditional loops.
The use of boolean in C++ and Java is almost the same. Boolean is a variable which has only 2 values : true and false. The only difference would be the primitive in C++ is bool while Java uses Boolean. On their use of conditional statements, they determine whether a loop or conditional statement is executed. The difference is that Boolean in Java does not accept integers as true / false value. They only accept the value either “true” or “false”. While in C++, it is possible to assign 1 as the value of a boolean which means true and 0 as false.

17. What kind of conversion is called a nonconverting cast ? explain with an example in Ada language .
Nonconverting cast is a conversion which happen between types of the same storage size.
Example :
type Source (<>) is limited private;
type Target (<>) is limited private;
function Ada.Unchecked_Conversion (S : Source) return Target;

21. In what way is dynamic type checking better than static type checking ?
Dynamic type checking allows the programmer to be more flexible. Because the dynamic checking is happening on compile time, not run time. And earlier correction is less costly.
Than later correction in case of static type checking usage, which runs on runtime of the application.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s