c109f03f - CSE 109 Final Examination Thursday 11 December...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CSE 109 Final Examination Thursday 11 December 2003 7-10 PM >>>>>>>>>>>>>>>>>>>>>SUGGESTED ANSWERS<<<<<<<<<<<<<<<<<<<<<<<<<<<< 1. Write an LSAsm program that reads in three integers and then displays a 1 if the sum of the squares of the first two numbers is the square of the third number. Otherwise it displays a 0. Recall some of the BNF for LSAsm programs: <arith>::= { ADD | SUB | MULT | DIV } <reg>,<reg>,<reg> <if>::= [IF {LT | LE | EQ | NEQ | GT | GE } ] GOTO <label> <motion>::= { {LOAD | STORE | READ} { <label> | <reg> } } | WRITE <exp> | MOV <exp>, <label> <exp>::= <term> [ {+|-} <term> ]* <term>::= <factor> [ {*|/} <factor> ]* <factor>::= ( <exp> ) | <label> | <reg> >>>>>>>>>>>>>>>>>>>>>>>>>> READ R2 READ R3 READ R4 MOV R2*R2+R3*R3-R4*R4,X LOAD X IF EQ GOTO EQUAL WRITE R0-R0 HALT EQUAL WRITE ONE HALT X 0 ONE 1 END <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 2. Given the classes and program below, state the output of the program when it is executed. #include <fstream.h> class A {public: A(){x=0;} int one(){return two() + three();} virtual int two(){return x+42;} int three(){return x+17;} int x; }; class B:public A { public: B(){x=5;} int two(){return x+109;} int three(){return x+111;} }; int main() { A a; B b; cout<<a.one()<<" "<<a.two()<<" "<<a.three()<<endl; cout<<b.one()<<" "<<b.two()<<" "<<b.three()<<endl; cout<<b.A::two()<<" "<<b.A::three()<<endl; } >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 59 42 17 136 114 116 47 22 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 3. Assume that class Lex has a single public method called next(), that Lex is a lexical analyzer that uses cin for input, and that on each call to next() one of the integer constants A, B, C, D, E, EOLN, or JUNK is returned. Assume that only the default constructor, Lex(), is defined for Lex and that EOLN is returned when the end of the line is encountered. Write a class Parser that has a method parse() which returns true if and only if the
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
contents of the current line of text in cin obeys the syntax of <one> defined by the BNF statements: <one>::=
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/09/2008 for the course CSE 109 taught by Professor Kay during the Spring '08 term at Lehigh University .

Page1 / 5

c109f03f - CSE 109 Final Examination Thursday 11 December...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online