Things to know for exam on Thursday - JMU
Things to know for exam on Thursday
Note that it is not possible to take a make-up exam
|Bindings |What are the four types of bindings generally associated with a variable? |
|types | |
|times |For each of the following bindings commonly associated with a variable, tell when |
| |they most commonly occur (be as specific as possible): |
| |location |
| |value |
| |type |
| |name |
| c. times |What type of binding generally occurs at |
| |language design time |
| |language implementation time |
| |compile time |
| |load time |
| |run time |
|times |Pick a language from among the languages C, Java, Ada, and Pascal, and give as |
|Louden, p. 80 #5.1 2nd edition |precise binding times as you can for the following attributes, and give reasons for |
| |your answers: |
| |the maximum number of significant digits in a real number |
| |the meaning of char |
| |the size of an array variable |
| |the size of an array parameter |
| |the location of a local variable |
| |the value of a constant |
| |the location of a function |
| | |
|Variable | procedure scope2 is |
|scope |a, b: integer; |
|dynamic |function p return integer is |
|static |a : integer; |
| |begin –- point 1 |
|Louden, p. 181, #5.9, 2nd edition |a := 0; |
| |b := 1; |
| |return 2; |
| |end p; |
| | |
| |procedure print is |
| |begin -- point2 |
| |put(a); |
| |new_line; |
| |put(b); |
| |new_line; |
| |put(p); |
| |new_line; |
| |end print; |
| | |
| |procedure q is |
| |b, p : integer; |
| |begin – point 3 |
| |a:= 3; |
| |b := 4; |
| |p := 5; |
| |print; |
| |end q; |
| | |
| |begin |
| |a := p; |
| |q; |
| |end scope2; |
| |with ada.text_io; |
| |with ada.integer_text_io; |
| |use ada.text_io; |
| |use ada.integer_text_io; |
| |procedure scope1 is |
| |a, b: integer; |
| |function p return integer is |
| |a,p : integer; |
| |begin -- point 1 |
| |a := 0; |
| |b := 1; |
| |p := 2; |
| |return p; |
| |end p; |
| | |
| |procedure print is |
| |begin -- point2 |
| |put(a); |
| |new_line; |
| |put(b); |
| |new_line; |
| |end print; |
| | |
| |procedure q is |
| |b : integer; |
| |begin -- point 3 |
| |a:= 3; |
| |b := 4; |
| |print; |
| |end q; |
| | |
| |begin |
| |a := p; |
| |q; |
| |end scope1; |
| | |
|lifetime | |
| |The basic form of an is shown below in EBNF|
|Selection statements in FORTRAN, Java, Pascal, Ada |where is either a single statement or a group |
|types |of statements enclosed in curly braces. |
|behavior | → if () [else |
|syntax |] |
|short circuit evaluation |By the above run, the following is a legal |
| |in which e1 and e2 are expressions and S1 and S2 are |
| |statements or statement groups. |
| |if (e1) if (e2) S1 else S2 |
| |Either explain in words why this if-statement is ambiguous|
| |or draw two different parse trees for |
|The advantage of short-circuit evaluation of Boolean or logical expressions is |Given the following legal FORTRAN statements, show how |
|that it can prevent certain runtime errors from occurring. |they would be written in Java or Pascal. |
| |if (x) 10, 20, 30 |
|Describe how short-circuit evaluation behaves with the and operator. |10 write (6,22) x * x |
| |go to 40 |
|Given the following pseudo-code examples, which is the one that can prevent an |20 write (6, 22) x + 4.5 |
|error from occurring and what error might occur with the other one? |go to 40 |
| |30 write (6, 22) x - 5.3 |
|if (i = x) then |40 x = x + 2.2 |
|.... | |
| | |
|if (a(i) >= x) and (i |
| |y := 0; |
| |z := 2; |
| |when 2..5 => |
| |y := 3; |
| |z := 1; |
| |when 7 | 9 => |
| |z := 10; |
| |when other => |
| |null; |
| |end case; |
|How would the following FORTRAN statement be written in Pascal? | |
| | |
|goto (53, 42, 1, 13, 20) X | |
|Iteration statements in FORTRAN, Java, Pascal, Ada |In C and Java the index value of a for loop may be defined|
|types |outside of the for loop or inside it. Where is the index |
|behavior |values of an Ada for loop declared? |
|syntax | |
|What are three differences between the for loop in Ada and Pascal? |The following code would be flagged as illegal by the Ada |
| |compiler |
|What are three differences between the for loop in Ada and Java? |for i in 1..10 loop |
| |i := 5; |
| |ada.integer_text_io.put (i); |
| |end loop; |
| |Why? |
|The following code is legal in Ada. |How many times would i be output if the following Ada loop|
| |was executed? |
|for i in -1 .. 1 loop |num := 5; |
|ada.integer_text_io.put (i); |for i in 1..num loop |
|for i in 3..3 loop |ada.integer_text_io.put (i); |
|ada.integer_text_io.put (i); |num := 3; |
|for i in reverse 6..7 loop |end loop; |
|ada.integer_text_io.put(i); | |
|end loop; |How many times would i be output if the corresponding Java|
|ada.text_io.new_line; |loop was executed? |
|end loop; | |
|end loop; | |
| |How many times would i be output if the corresponding |
|What would the output be if it were run? |Pascal loop was executed? |
| | |
|Assuming i is declared previous to this code, what would the output be in the | |
|corresponding Java loop? | |
| | |
|Assuming i is declared previous to this code, what would the output be in the | |
|corresponding Pascal loop? | |
|Ada, Java, FORTRAN, and Pascal all have iteration control structures. Choose | |
|two (2) forms of iteration control structures in any one (1) of these languages,| |
|show their syntax in pseudo code and describe clearly the major difference | |
|between them. | |
|Subprograms in FORTRAN, Java, Pascal, Ada |What are two distinct types of subprograms present in all |
|types |of these languages? |
|parameter modes | |
|syntax |What is the major difference between them? |
|results | |
|How do each of the following languages pass their parameters? |What are Ada’s parameter modes |
|FORTRAN | |
|Java | |
|Pascal | |
|In FORTRAN IV, a function returns its value by assignment to the function |Te following subproram is written in FORTRAN. If this |
|name. What type of function is available in Java, Pascal and Ada that this |program is called with actual parameters M and N holding|
|type of return mechanism prevents? |4 and 5 respectively, then after return from the |
| |subprogram, M and N will hold 5 and 4 respectively. What|
| |parameter mechanism does FORTRAN use that causes this? |
| | |
| |SUBROUTINE SWAP (K, L) |
| |ITEMP = K |
| |K = L |
| |L = ITEMP |
| |RETURN |
| |END |
| | |
| |If this subprogram were written in Java and called with M |
| |and N holding 4 and 5 respectively, what would M and N |
| |hold after return from the subprogram? What parameter |
| |mechanism does Java use that causes this? |
| | |
| |If this subprogram were written in Pascal, the programmer |
| |could choose what M and N would hold after return from the|
| |subprogram. Describe how this is accomplished. |
|The following code fragment uses arrays in Java. The first line declares and |Briefly explain the following parameter passing mechanisms|
|allocates an array of two integers. the next two lines initialize it. |and the difference between them. For each, tell a |
|int[ ] A = new int [2]’ |language that uses it. |
|A [ 0] = 0; | |
|A[1] = 2; |parameter passing by value |
|f ( A[0], A[A[0]]); |parameter passing by reference |
| |parameter passing by result |
|Function f is defined as |parameter passing by value-result |
|void f (int x, int y) | |
|{ | |
|x = 1; |page 101, exercise 15, Roosta |
|y = 3; | |
|} | |
| | |
|For each of the following parameter-passing methods, say what the final values | |
|in the array A would be after the call to f. | |
|by value (i.e. copy) | |
|by reference (i.e. address) | |
|by result (i.e. copy out) | |
|by value-result (i.e. copy in, copy out) | |
|by name - not yet | |
| | |
|page 385 Webber, Modern Programming Languages, ex 6 | |
|What is the output of the following program written in Pascal syntax using the | |
|following parameter passing mechanisms: | |
|pass by value | |
|pass by reference | |
|pass by result | |
|pass by value-result | |
| | |
|program test (output); | |
|var i : integer; | |
|a : array [1..2] of integer; | |
| | |
|procedure P( x,y : integer); | |
|begin | |
|x := x + 1; | |
|i := i + 1; | |
|y := y + 1; | |
|end; | |
| | |
|begin | |
|a[1] := 1; | |
|a[2] := 1; | |
|i := 1; | |
|P( a[i], a[i]); (* here’s the problem line *) | |
|writeln (a[1]); | |
|writeln (a[2]); | |
|end. | |
| | |
|page 101, exercise 16, Roosta (have some doubts about this one) | |
|Grammars |What were three (3) of the things that the BNF for Mini-Language |
|components |Core was not able to specify? |
|purposes | |
|BNF vs EBNF | |
|pre-conditions | |
|Dr. Grove’s material | |
|limitations | |
|What are the component parts of a grammar? |What are the two main purposes of a grammar? (i.e. what can we do |
| |with one?) |
|Given the following context-free grammar: |Given the following grammar |
| |G = ( {S,A}, {0,1}, P, S) represented by the following production |
|S → 0S | 1A |rules where ℇ is the empty string which has length 0. |
|A → 0S | 1B |S → 0A1 |
|B → 0S | 1C | 1 |A → 0A1 |
|C → 1C | 0C | 1 | 0 |A → ℇ |
| | |
|Generate 3 valid sentences in this language |Generate 3 valid sentences in this language. |
| | |
| |Tell in words what the sentences in this language look like. |
|page 117, example 4.7 Roosta | |
| |page 118, example 4.9 Roosta |
|Assume the following grammar: |Using the following syntactic specifications, demonstrate the |
|< assign > ::= < id > := < expr > |ambiguity of the grammar by displaying two derivation tress fo the |
|< id > ::= A | B | C |expression a+b+c |
|< expr > ::= < id > + < expr > | |
|< expr > ::= < id > * < expr> | ::= | |
|< expr > ::= (< expr>) | ::= | |
|< expr> ::= < id > | ::= + | - |
| | ::= a|b|c |
|Show a parse tree and a left-most derivation of the following | |
|statement: |page 137 , problem 15, Roosta |
|A := A * ( B + ( C * A )) | |
| | |
|page 136, problem 8, Roosta | |
|Consider the following productions: |Prove that the following grammar is ambiguous but first, tell what|
| |it means for a grammar to be ambiguous. |
| ::= [ , ] | |
| ::= | ::= |
| ::= | ::= + |
| ::= () | ::= |
| ::= x | ::= a|b|c |
| ::= y | |
| ::= z |page 136, problem 9, Roosta |
| | |
|for each of the following strings, show every step in the derivation | |
|tree that proves that the string belongs in the grammar | |
| | |
|z | |
|(x) | |
|[y] | |
|[(x),y] | |
|[ (x), [y,x]] | |
| | |
|page 137, #13, Roosta | |
|Assume that we have the following production rules |Copnsider the following grammar specifications: |
| ::= | ::= * |
| ::= + | ::= & |
| ::= - | ::= c |
| ::= * | |
| ::= 40 | 3 | 9 |Give a derivation and parse tree for the string c*c&c&c*c |
| | |
|Is the expression 40-3-9 ambiguous? |Prove that the grammar is ambiguous |
|Prove that it is or it isn’t | |
| |modification of p 138, problem 20, Roosta |
|page 136, problem 10 Roosta | |
|Given the following grammar | |
|G = ( {S,T}, {a,b}, P, S) represented by the following production | |
|rules where ℇ is the empty string which has length 0. | |
| | |
|S → aaTb | |
|T → aaTb | |
|T → ℇ | |
| | |
|Generate 3 valid sentences in this language. | |
| | |
|Tell in words what the sentences in this language look like. | |
| | |
|variation of page 138, problem 19 , Roosta | |
|Exception handling in FORTRAN, Java, Pascal, Ada |Describe the exception handling mechanisms we have seen in|
| |two (2) of the following four (4) languages: FORTRAN, |
| |Java, Pascal, Ada |
|What is the difference in approach to exception handling between Java and |Describe what happens when an exception occurs in Java |
|Ada? | |
| | |
|All of Chapter 1 in our text |What are three (3) desireable characteristics of a |
|why study languages |programming language? |
|how to evaluate languages | |
|influences on language design | |
|language categories | |
|language design trade-offs | |
|implementation methods | |
|What do we gain from studying a variety of programming languages? |It has been said that “languages shape the way we |
| |think”. With regard to the domain of programming |
| |languages, do you agree or disagree with that statement?|
| |Explain why you agree or disagree and give examples to |
| |illustrate your choice. |
|In order for high level programming languages to be run on computers they must |The two common methods of translation from high level |
|be translated into the machine language of the computer they are running on. |programming language to machine language are compilation|
|What are the two methods of translation we have talked about? Describe the |and interpretation. |
|major difference between them. |Tell what methods are used by each of the following |
| |languages: |
| |FORTRAN |
| |Java |
| |Pascal |
|Data types in FORTRAN, Java, Pascal, Ada |Describe two (2) ways in which FORTRAN differs from Ada |
|scalar |with regard to data type |
|structured | |
|type compatibility | |
|type checking | |
|What are the scalar types we studied in FORTRAN? |Pascal has a structured data type called a record. |
| |FORTRAN IV’s only structured data type is an array. |
|What are the scalar types we studied in Pascal? |Given the following Pascal declaration for an array of |
| |records, write the necessary FORTRAN declarations to |
| |manipulate the same data. |
| | |
| |InfoRecord = Record |
| |number : integer; |
| |earnings, tax : real; |
| |end; |
| |EmployeeRecords = Array [1..100] of InfoRecord |
|Assuming that X has been declared to be a floating point number and | |
|assigned the value 98.7 and that N has been declared to be an integer and | |
|assigned the value 25, | |
| | |
|What is the result of adding X and N and storing the result in N in | |
|FORTRAN? Describe what happened and why? | |
| | |
|What is the result of adding x and n and storing the result in X in Ada? | |
|Describe what happened and why. | |
| | |
| Dr. Bernstein’s material | |
| | |
|Chapter 2 in our text on FORTRAN, Java, Pascal | |
|and Ada | |
| Basic statements |What are the five basic types of statements that we |
|types |generally expect to find in a programming language. |
| | |
| |For one (1) of these types of statements, pick two (2) of |
| |the languages we have written programs in this semester |
| |(FORTRAN, Java, Pascal and Ada) and describe two (2) |
| |differences between them. |
| Miscellaneous |What is a potential problem that occurs when using DOS |
|DOS compilation commands |redirection to send a program’s output to a file? |
|use of files | |
|redirection | |
|When using files in Pascal, what are the necessary actions that must |When using files in Pascal, if you neglect to close the files |
|occur? ( you may either give a series of code statements or describe in |when you are done with them, what problem may occur? |
|words) | |
|Given the following FORTRAN code and a line of input consisting of the | |
|digits shown below with no spaces between them , what would be stored in | |
|the variables and what would the output be? |Given the following FORTRAN code and a line of input consisting |
|1234567898765432123456789 |of the digits shown below with no spaces between them , what |
| |would be stored in the variables and what would the output be? |
|READ (5, 13) X, Y, I, Z |1234567898765432123456789 |
|FORMAT (F3.2, 1X, F7.3, I4, F2.1) | |
|WRITE (6, 14) X,Y,I,Z |READ (5, 13) X, Y, I, Z |
|FORMAT (1X, F5.2, 2X, F8.3, 1X, I5, 1X, F3.1) |13 FORMAT (F3.2, 1X, F7.3, I4, F2.1) |
| |WRITE (6, 14) X,Y,I,Z |
|1234567898765432123456789 |14 FORMAT (1X, F5.2, 2X, F7.2, 1X, I5, 1X, F3.1) |
|1.23 5678.987 6543 2.1 |STOP |
| |END |
| | |
| | |
| |1234567898765432123456789 |
| |1.23 5678.99 6543 2.1 |
|Given the following FORTRAN code and a line of input consisting of the | |
|digits shown below with no spaces between them , what would be stored in | |
|the variables and what would the output be? | |
|1234567898765432123456789 | |
| | |
| | |
|READ (5, 13) X, Y, I, Z | |
|13 FORMAT (F3.2, 1X, F7.3, I4, F2.1) | |
|WRITE (6, 14) X,Y,I,Z | |
|14 FORMAT (1X, F5.2, 2X, F7.3, 1X, I5, 1X, F3.1) | |
|STOP | |
|END | |
| | |
| | |
|12345678987654321234567898 | |
|1.23 ******* 6543 2.1 | |
|Chapter 5 | |
|textbook | |
|slides | |
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- introduction who world health organization
- microsoft frontpage to expression web
- opc alarms and events interface to the pi system
- microsoft word specs
- real numbers ucla mathematics
- facilities management strategic plan
- things to know for exam on thursday jmu
- ada 9x compatibility guide version 6 0 letter
- compatibility home the site
Related searches
- things to know before buying a house
- things to know when buying a home
- important things to know in life
- things to know about investing in stocks
- things to know before buying a car
- things to say about yourself on resume
- things to know before marriage
- things to know about annuities
- things to know about earth
- things to know before getting married
- things to know about science
- things to know before high school