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

  What resources do need to conduct

What restraints are in your workplace that prevents the new computer system installation.

  Listing the name and salary of all employees

List the name and hours worked per week for each employee who works on the Reorganization project. Order the list by hours worked in explaning order and by last name within each amount of hours.

  Using a lock guarantees that deadlock cannot occur

Once a Lock has been obtained by a thread, the Lock object will not allow another thread to obtain lock until the first thread releases it.

  How to compute the subnet mask

how to Compute the subnet mask and number of subnets and number of hosts in each subnet, in each of the given scenarios.

  Describe some of the attributes that would prove beneficial

Describe some of the attributes that would prove beneficial to a Website for that industry. Explain how those attributes could be used and what value they would add.

  Which is a method for copying a file or folder

Which of the following locations is not a valid place from that to delete a file and send it to the Recycle Bin.

  Create and initialise the main program objects

CP1300 SP51 2015 Assignment Details -create and initialise the main program objects, and to control program behaviour and

  Create class saving account use a shared class variable to

create class savingaccount. use a shared class variable to store the annualinterestrate for all savingsaccounts. each

  What are the some elements of budgets and estimates

Budgets are actually price estimates tied to detailed distribution of revenues. Dissimilar conservative monetary statements, revenue and defeat and cash flow statements.

  Find the express code that corresponds to the service tag

Find the express code that corresponds to the service tag: H32Y1F1. You must show how you got your answer - For each hexadecimal digit it displays a line showing how that digit was created and finally displays a line containing the final result.

  Realize the circuit using a rom

A circuit has four inputs RSTU and four outputs VWYZ. RSTU represents a binarycoded- decimal digit. VW represents the quotient and YZ the remainder when RSTU. Realize the circuit using a ROM

  Design a script that will allow the user to enter one

make a script that will allow the user to enter one of several choices from the command line.

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