REVIEW FOR FINAL:
Topics from text and notes that we have covered this semester and may be covered on final exam
* -- Topics with an asterisk have an extremely high probability of appearing on the final. Other items may also be on final.
Chapter 1 -- Language design issues
Chapter 2 -- Impact of machine architectures
Chapter 3 -- Language translation issues
Chapter 4 -- Modeling language properties
Chapter 5 -- Elementary data types
Chapter 6 -- Encapsulation
Chapter 7 -- Inheritance
Chapter 8 -- Sequence control
Chapter 9 -- Subprograms
Chapter 10 -- Storage Management
Test questions will be similar to questions in: (1) your previous exams, (2) your homeworks, and (3) the sample questions below. The questions on the final may not be identical to any previously given questions but they will be similar in content.
SAMPLE QUESTIONS FOR CHAPTER 9:
...
var element : Integer;
a: array[1..2] of Integer;
procedure whichmode(x: ? mode Integer)
begin
a[1] := 6;
element := 2;
x := x + 3;
end;
begin
a[1] := 6;
a[2] := 2;
element := 1;
whichmode(a[element]);
...
program example;
var a, b: integer;
...
procedure sub1;
var x, y : integer;
begin { sub1 }
...
end; { sub1 }
procedure sub2;
var x : integer;
...
procedure sub3;
var x: integer;
begin { sub3 }
...
end; { sub3 }
begin { sub2 }
...
end; { sub2 }
begin { example }
...
end. { example }
SAMPLE QUESTIONS FOR CHAPTER 10:
void f(void) {
BigTable Tom(300) ;
BigTable *Jerry ;
Jerry = new BigTable(500) ;
}
Link *Fun1(void) {
Link staticL(200) ;
Link *dynamoL ;
dynamoL = new Link(100, &staticL) ;
return dynamoL ;
}
Link *Fun2(void) {
Link *dynamoL1, *dynamoL2 ;
dynamoL2 = new Link(200) ;
dynamoL1 = new Link(100, dynamoL2) ;
delete dynamoL2 ;
return dynamoL1 ;
}
Link *Fun3(void) {
Link *DynamoL1, *DynamoL2, *DynamoL3 ;
DynamoL3 = new Link(300) ;
DynamoL2 = new Link(200, DynamoL3) ;
DynamoL1 = new Link(100, DynamoL2) ;
return DynamoL2 ;
}
template class BigTable {
private:
int tsize; // Size of table
Elem *table; // Table pointer
public:
BigTable(int size = 100)
{ tsize = size ; table = new Elem[tsize]; }
~BigTable()
{ delete[] table ; }
SetLast(Elem& newLast)
{table[tsize] = newLast ; }
… other methods
};
SAMPLE QUESTIONS FOR SPECIFIC PROGRAMMING LANGUAGES:
<?xml version="1.0" ?>
<addressbook>
<contact id="1">
<firstname>Daisy</firstname>
<lastname>Flemming</lastname>
<email>daisyf@stanford.edu</email>
</contact>
<contact id="2">
<firstname>Lois</firstname>
<lastname>Brooks</lastname>
<email>lbrooks@stanford.edu</email>
<address>Meyer 380</address>
<phone type="office" >650-723-3064</phone>
</contact>
</addressbook>
<?xml version="1.0" ?>
<addressbook>
<contact id="1">
<firstname>Daisy
<lastname>Flemming
<email>daisyf@stanford.edu
</contact></email></lastname></firstname>
...
</addressbook>
<!ELEMENT pizzas (pizza+)>
<!ELEMENT pizza (pizza-name, created-by?, description?, crust,
sauce, topping*, cheese+, picture?, review*)>
<!ATTLIST pizza pizza-id CDATA #REQUIRED>
<!ELEMENT pizza-name (#PCDATA)>
<!ELEMENT created-by (person)>
<!ELEMENT description (#PCDATA)>
<!ELEMENT crust (#PCDATA)>
<!ELEMENT sauce (#PCDATA)>
<!ELEMENT topping (#PCDATA)>
<!ELEMENT cheese (#PCDATA)>
<!ELEMENT picture EMPTY>
<!ATTLIST picture src CDATA #REQUIRED>
<!ATTLIST picture width CDATA #REQUIRED>
<!ATTLIST picture height CDATA #REQUIRED>
<!ATTLIST picture alt CDATA #REQUIRED>
<!ELEMENT review (reviewer, rating, date,
review-text)>
<!ELEMENT reviewer (person)>
<!ELEMENT rating (#PCDATA)>
<!ELEMENT date (#PCDATA)>
<!ELEMENT review-text (#PCDATA)>
<!ELEMENT person EMPTY>
<!ATTLIST person fname CDATA #REQUIRED>
<!ATTLIST person lname CDATA #REQUIRED>
DO 20 i = 2,10,2
PRINT *, i
20 CONTINUE
DO 20 n = 25,5,-5
PRINT *,n
20 CONTINUE
PROGRAM Fun
REAL temp
PRINT *,'Enter a number'
READ *,temp
PRINT*,'It is ',(temp.gt.80.0),' that the number is greater than 80'
PRINT*,'It is ',(temp.lt.80.0),' that the number is less than 80'
STOP
END
program fun
real r, t, sum
integer m
read (*,*) t
sum = 0.0
do 10 m = 1, 5
sum = sum + r(m, t)
10 continue
write (*,*) 'The output is ', sum, 'inches'
stop
end
real function r(m,t)
integer m
real t
r = t + 1.0*m
if (r .LT. 0) r = 0.0
return
end
count := 0;
while count /= 10 loop
count := count +1;
put(count,3);
new_line;
end loop;
for i in reverse 1..10 loop
put(i,3);
new_line;
end loop;
procedure fun is
package Int_IO is new Integer_IO(Integer); use Int_IO;
type ArrayType is array(1..7) of Integer;
myList : ArrayType := (3,5,2,7,-9,1,-10);
begin
Fun2(myList,7);
for i in 1..7 loop
put(mylist(i),4);
end loop;
end fun;
procedure fun1(a,b: in out Integer) is
temp : Integer := a;
begin
a := b;
b := temp;
end fun1;
procedure Fun2(list: in out ArrayType; size: in Integer) is
m : Integer;
begin
for i in 1..size-1 loop
m := i;
for j in i+1..size loop
if list(j) < list(m) then
m := j;
end if;
end loop;
fun1(list(i), list(m));
end loop;
end fun2;
hello: times
1 to: times do: [:i | (Transcript show: 'Hello World') cr]
hello: times say: text
(times > 100)
ifTrue: [ Transcript show: 'You will get bored!']
ifFalse: [1 to: times do: [:i | (Transcript show: text) cr]]
x := 0.
[ (x < 10) ]
whileTrue: [Transcript show: (x) printString.
Transcript show: ' '.
x := x + 1.].
1 to: 10 by: 2 do: [:x | Transcript show: (x) printString.
Transcript show: ' '.].
bonus(Number) :- Number is 2 + 3.
?- bonus(3).
bonus(Number) :- Number is 2 + 3.
?- bonus(X).
tape(1,van_morrison,astral_weeks,madam_george).
tape(2,beatles,sgt_pepper,a_day_in_the_life).
tape(3,beatles,abbey_road,something).
tape(4,rolling_stones,sticky_fingers,brown_sugar).
tape(5,eagles,hotel_california,new_kid_in_town).
?- tape(5,Artist,Album,Fave_Song).
tape(1,van_morrison,astral_weeks,madam_george).
tape(2,beatles,sgt_pepper,a_day_in_the_life).
tape(3,beatles,abbey_road,something).
tape(4,rolling_stones,sticky_fingers,brown_sugar).
tape(5,eagles,hotel_california,new_kid_in_town).
?- tape(4,rolling_stones,sticky_fingers,Song).
fun(X) :- red(X), car(X).
fun(X) :- blue(X), bike(X).
bike(harley_davidson).
car(ford_escort).
car(vw_beatle).
red(vw_beatle).
red(ford_escort).
blue(harley_davidson).
?- fun(What).
hold_party(X):- birthday(X), happy(X).
birthday(tom). birthday(fred). birthday(helen). happy(mary).
happy(jane). happy(helen).
?- hold_party(Who).
function(X,[X|_]).
function(X,[_|T]) :- function(X,T).
?- function(X, [1,2,3])
fun function1 n = if n = 0 then 1 else n * function1 (n-1);
function1 3;
fun function2 [] = 1
| function2 (fst::rest) = fst * (fnction2 rest);
function2 [1,2,3];
fun function3 [] = []
| function3 (h::t) = function3(t)@[h];
function3 [1,2,3]
fun function4 [] = 0
| function4 (x :: xs) = 1 + function4 xs;
function4 [1,2,3]
(cdr (cdr (list 1 2 3)))
(define list-1 (list 1 2 3))
(define list-2 (cons 0 list-1))
(define function1 (lambda (a l)
(cond ((null? l) #f)
((equal? a (car l)) #t)
(else (function1 a (cdr l))))))
(function1 1 '(1,2,3))
(define (function2 a l)
(cond ((null? l) l)
((equal? a (car l)) (function2 a (cdr l)))
(else (cons (car l) (function2 a (cdr l))))))
(function2 1 '(1,2,3))