Determine the scope of a variable declared in for statement

Assignment Help Computer Engineering
Reference no: EM131249729

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.

Reference no: EM131249729

Write an assembly program that has a subroutine named rmndr

Write an assembly program that has a subroutine named rmndr which computes the remainder for a variable N when it is divided by 10 and stores the result into a variable M.

Discuss the core security mechanisms

Discuss the core security mechanisms Windows implements to prevent the attacker achievingthat goal - Discuss briefly how the above outlined security mechanisms would fail, and

Create a program for your lego windstorm nxt robot

Create a program for your Lego Windstorm NXT robot. The program will allow the robot to "patrol" in a bounded area. The area will be a white background bounded by a thick bl

Write all possible node and edge facts

COMP348: PRINCIPLES OF PROGRAMMING LANGUAGES - write all possible node and edge facts that describes the structure of this graph - Implement your facts & rules as a Prolog pro

Implement the system using sockets programming

Design and implementation details and a CD having the system source code -  implement the system using sockets programming for message exchange over TCP/IP. You may choose an

Develop web application system that scan classified files

I want to develop a private web application system that scan the confidential and classified files with multiple Anti-virus engines. The web should be look like " virusetotal

Develop and deploy a smart application

You are allowed to use available services of IBM Bluemix like IoT foundation services to develop smart applications. There are many demo codes like Connected Vehicle applica

Compute the millionth fibonacci number in under a minute

Based on you answer to 7 rewrite NewFib using loops instead of recursion. Your implementation should be able to compute the millionth Fibonacci number in under a minute. Pri

Reviews

len1249729

10/20/2016 6:01:25 AM

Please do circled problems from each chapter. Also, where possible, for programming assignments do those in C# if possible but C++ is fine. 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.

Write a Review

 
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd