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

Questions Cloud

How you have dealt with one of these universal themes : Develop a one-page (250-350 word) response in which you demonstrate how you have dealt with one of these universal themes in your personal life.
What is the cost of new equity to the firm : What is cost of new equity to the firm? What are the advantages and disadvantages of issuing new equity in the capital structure? What are the advantages and disadvantages of using preferred stock in the capital structure?
Is it morally reprehensible to consume animal products : What are specific instances where eating meat would definitely be wrong? What are specific instances where eating meat would clearly not be wrong? To what extent should humans have a higher moral status than animals? Why?
Different department and supervisor names : Write an application that stores at least five different department and supervisor names in a two-dimensional array. Allow the user to enter a department name (such as"Marketing") and display the corresponding supervisor's name.
Determine the scope of a variable declared in for statement : 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
Distributed around the outside of a circle : Suppose that n a's and n b's are distributed around the outside ofa circle. Use mathematical induction to prove that for all integers n ≥ 1, given any such arrangement, it is possible to find a starting point so that if one travels around the circ..
What is the most effective way to wash laboratory glassware : What is the most effective way to wash laboratory glassware? Assume that you have a 1.0 L flask that contains 5 ml, of residual droplets of a 1.0 M NaCL solution.
Components of a green information system : JJ seems to be very interested in RFIDs, He is considering using RFIDs as components of a Green Information System, in order to improve the sustainability of IRCL's operations. He asks you to prepare a report addressing the following question:
Determining the database design diagram : Suppose a local college has tasked you to develop a database that will keep track of students and the courses that they have taken. In addition to tracking the students and courses, the client wants the database to keep track of the instructors te..

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

Computer Engineering Questions & Answers

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

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