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

  Evaluate the total with insurance

Enter the insurance rate as a mixed cell reference in the formula, making the row number absolute.

  Describe the object-oriented databases

Describe the database planning and development process. What steps are involved, and what tools may be appropriate or helpful.

  Make table to be a pointer to pointer of type double

make table to be a pointer to pointer of type double.

  Commercial ids systems

Utilizing the Internet, search for the commercial IDS systems. What are the classification systems and descriptions are used.

  The aim of this project is to design developand evaluate a

the aim of this project is to design developand evaluate a 2d game for pc. you can choose any type of game you like

  Customers may purchase recordings by making a selection

as Napster is going out of business, you have decided to start your own on-line music sharing site. You will provide individual music files at your site.

  Difference between paging and swapping

a) Explain the term ‘Process swapping'. Why is process swapping necessary in a typical modern operating system? Include an explanation of the difference between paging and swapping.

  Body language conveys non-verbal cues to the recipient of

body language conveys nonverbal cues to the recipient of any given communication. explain the five nonverbal methods of

  Be substantive and clear and use illustrations to reinforce

write 400-600 words that respond to the following questions with your thoughts ideas and comments. this will be the

  Questiona file has r 20000 student records of permanent

questiona file has r 20000 student records of permanent length. each record has following fields-name 30 bytes ssn 9

  What will the swap macro

What will the SWAP macro in the following program be expanded to on preprocessing? will the code compile?

  The cost of building and maintaining an organizational

the cost of building and maintaining an organizational computing ecosystem has become a bigger part of most

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