Write test programs in c java and c to determine the scope


Questions -

Q1. Some programming languages are typeless. What are the obvious advantages and disadvantages of having no types in a language?

Q2. Consider the following JavaScript skeletal program:

// The main function

var x;

function sub1 () {

var x;

function sub2 () {

 . . .

}

}

function  sub3 () {

. . .

}

Assume that the execution of this program is in the following unit order:

main calls sub1

sub1 calls sub2

sub2 calls sub3

a. Assuming static scoping, in the following, which declaration of x is the correct one for a reference to x?

i. sub1

ii. sub2

iii. sub3

b. Repeat part a, but assume dynamic scoping.

Q3. Consider the following Python program:

x = 1;

y = 3;

z = 5;

def sub1 ():

a = 7;

y = 9;

z = 11;

. . .

def sub2 ():

global x;

a = 13;

x = 15;

w = 17;

. . .

def sub3 ():

nonlocal a;

a = 19;

b = 21;

z = 23;

. . .

. . .

List all the variables, along with the program units where they are declared, that are visible in the bodies of sub1, sub2, and sub3, assuming static scoping is used.

Q4. Write test programs in C++, Java, and C# to determine the scope of a variable declared in a for statement. Specifically, the code must determine whether such a variable is visible after the body of the for statement.  

Q5. What are the arguments for and against representing Boolean values as single bits in memory?

Q6. What disadvantages are there in implicit dereferencing of pointers, but only in certain contexts?

Q7. Write a short discussion of what was lost and what was gained in Java's designers' decision to not include the pointers of C++.

Q8. In what way is static type checking better than dynamic type checking?

Q9. Design a set of simple test programs to determine the type compatibility rules of a C compiler to which you have access. Write a report of your findings.

Q10. Write a Perl program that uses a hash and a large number of operations on the hash. For example, the hash could store people's names and their ages. A random-number generator could be used to create three-character names and ages, which could be added to the hash. When a duplicate name was generated, it would cause an access to the hash but not add a new element. Rewrite the same program without using hashes. Compare the execution efficiency of the two. Compare the ease of programming and readability of the two.

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

Q12. 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?

Q13. 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, sum 2;

sum1 = (i/2) + fun (&i);

sum2 = fun(&j) + (j/2);

}

What are the values of sum 1 and sum2

a. operands in the expressions are evaluated left to right?

b. operands in the expressions are evaluated right to left?

Q14. Consider the following C Program:

int fun (int*i) {

*i += 5;

Return 4;

}

Void main () {

int x = 3;

x = x + fun(&x);

}

What is the value of x after the assignment statement in main, assuming

a. operands are evaluated left to right.

b. operands are evaluated right to left.

Q15. Write a program in either C++, Java, or C# that illustrates the order of evaluation of expressions used as actual parameters to a method.

Q16. What are the arguments, pros and cons, for Python's use of indentation to specify compound statements in control statements?

Q17. Describe three specific programming situations that require a posttest loop.

Q18. Speculate as to the reason control can be transferred into a C loop statement.

Q19. In a letter to the editor of CACM, Rubin (1987) uses the following code segment as evidence that the readability of some code with gotos is better than the equivalent code without gotos. This code finds the first row of an n by n integer matrix named x that has nothing but zero values.

for (i = 1; I <= n; i++) {

for (j = 1; j <= n; j++)

if (x[i][j] != 0)

goto reject;

println ('First all-zero row is:' , i);

 

brecak;

reject:

}

Q20. Rewrite the C Program segment of Programming in Java without using a switch statement.

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: Write test programs in c java and c to determine the scope
Reference No:- TGS01653569

Expected delivery within 24 Hours