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

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

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
Image of page 1

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

contents of the current line of text in cin obeys the syntax of <one> defined by the BNF statements: <one>::=
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.
  • Spring '08
  • Kay
  • int j=0, Lex Lex

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern