Give brief examples of different variable scoping using Haskell, Prolog, Java, C, JavaScript, and/or MIPS
/*------------------- Scope of variables in Java -------------------------*/
1. Member Variables (Class Level Scope) : These variables should be declared inside class but outside any member function/method . They can be directly accessed from anywhere in the class.
Example :
public class ScopeClassTest
{
int variable1;
private String variable2;
String function1() {}
float function2() {}
char c;
}
2. Local Variables (Method Level Scope) : These variables are declared inside a method/function and can’t be accessed outside the method.
Example :
public class ScopeMethodTest
{
void function1()
{
int localVar;
}
}
3. Loop Variables (Block Scope) : The variables declared inside pair of brackets “{” and “}” in a method has scope withing the brackets only.
public class BlockScopeTest
{
public static void main(String args[])
{
{
int y = 5550;
System.out.println(y);
}
}
}
/*----------------------Scope of variables in JavaScript
--------------------------*/
1. Local Variable : Variables declared within a function. These variables can only be accessed from within the function.
Example :
function getHospitalName() {
var hospitalName = "ABC";
// Only here we can use this variable hospitalName
}
2. Global Variables : Variables which are declared outside a
function, has global scope.
Example
var hospitalName = "ABC";
// code here can use hospitalName
function getHospitalName() {
// code here can also use hospitalName
}
/*----------------------Scope of variables in C
--------------------------*/
1. Local Scope :
int main ()
{
int a,b,c; /* local variables */
a = 80;
b = 50;
c = a - b;
printf ("value of a = %d, b = %d and c = %d\n", a, b, c);
return 0;
}
2. Global Scope :
#include <stdio.h>
int c; /* global variable */
int main ()
{
int a,b; /* local variables */
a = 20;
b = 30;
c = a + b;
printf ("value of a = %d, b = %d and c = %d\n", a, b, c);
return 0;
}
/*----------------------Scope of variables in Haskell --------------------------*/
1. Global Scope :
a = 100
2. Local (Function) Scope :
multiply x = x * x
/*----------------------Scope of variables in Prolog --------------------------*/
Two uses of an identical name for a variable only refer to the same memory location if they are within a single clause.
good(X) :- old(X).
good(Y) :- wise(Y).
/*----------------------Scope of variables in MIPS
--------------------------*/
data
globalVariable: .abc 20
.text
#access
lw $a0, globalVariable
#modify
la $a0, globalVariable #get address
li $a1, 11 #new value
sw $a1 0($a0) #save new value
lw $a2, globalVariable #get new value
Give brief examples of different variable scoping using Haskell, Prolog, Java, C, JavaScript, and/or MIPS
create table please for my SQL data.txt 1,C,Richie,1955 2,JAVA Script,Karen,1958 4,Java,Schwartz,1959 5,C++,Ross,1959 6,prolog,Maria,1972 7,Perl,Wall,1987 ID Title Author Price 1 Richie Karen Year 1955 1958 1959 C JAVA Script Java C++ prolog 2 4 10 20 10 5 Schwartz Ross Maria 1959 1972 20 10 6 7 Perl Wall 1987 20 The above relation has information about different books. The table information is already saved as txt format in Moodle under the name Quiz2Data.txt. Using MySql on your computer do: Create...
In a brief paragraph please explain what are the different types of polymerization reactions and give specific examples of polymers (products) of those reactions.
Using OSI model, find the different attack on each layer. Give a brief description about them.
help create a table data.txt 1,C,Richie,1955 2,JAVA Script,Karen,1958 4,Java,Schwartz,1959 5,C++,Ross,1959 6,prolog,Maria,1972 7,Perl,Wall,1987 ID Title Year Price 1 Author Richie Karen 1955 1958 10 20 2 4 C JAVA Script Java C++ prolog 1959 10 5 Schwartz Ross Maria 1959 1972 20 10 6 7 Perl Wall 1987 20 The above relation has information about different books. The table information is already saved as txt format in Moodle under the name Quiz2Data.txt. Using MySql on your computer do: Create a database...
Create a brief argument using all the Toulmin elements and label each element in your argument. Describe and give examples of ethos, pathos and logos. Describe three different kinds of evidence someone could use to support a claim and give an example of each.
just brief discussion please reul Ululeueudle. 3. List and describe the different methods that economists take to value environmental benefits. Describe whether or not they are appropriate for use values, nonuse values or option values. Give examples from the reading of specific types of environmental benefits that have been valued with the different methods. Describe some of the pros and cons of using the different methods.
Explain the following object-oriented(OO) concepts with the aid of code examples (either C++ or Java): Inheritance Over-riding . Over-loading Describe any differences between C++ and Java in how these OO concepts are implemented? 3(c) 17 Marks] Describe C++ namespaces using a code example. Describe Java packages, again using a code example. How do C++ namespaces compare to Java packages? 3(d) [5 Marks] What are inline methods in C++/Java? Explain the terms accessor and mutator. Explain the following object-oriented(OO) concepts with...
Using MIPS: Consider the following fragment of C code: for i=0: i < = 100: i = i + 1) {a[i] = b[i] + c;} Assume that a and bare arrays of words and the base address of a is in $a0 and the base address of b is in $a1. Register $t0 is associated with variable i and register $s0 with c. Write the code for MIPS. How many instructions are executed during the running of this code? How...
using the website repl.it (must be done in Javascript) PGM #1 Write a Java program that can perform the Caesar cipher for English messages that include both upper and lowercase alphabetic characters. The Caesar cipher replaces each plaintext letter with a different one, by a fixed number of places down the alphabet. The cipher illustrated here uses a left shift of three, so that (for example) each occurrence of E in the plaintext becomes B in the ciphertext. For example...
Using a typical fast food business give two examples of the following costs: direct material, direct labor, fixed manufacturing overhead, and variable manufacturing overhead