c109s04t2 - CSE 109 Test 2 Wednesday 14 April 2004...

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

View Full Document Right Arrow Icon
CSE 109 Test 2 Wednesday 14 April 2004 >>>>>>>>>>>SUGGESTED ANSWERS 1. Write a Simple Language Program that reads in an integer and writes out the largest square less than or equal to the absolute value of the number. For example, if the number is 29 then the program would write out 25; if the number is -16 then the program would write out 16. ======================================================= READ N IF N>0 GOTO POSITIVE N=0-N POSITIVE: SQUARE=1 LOOP: IF SQUARE*SQUARE>N GOTO FINISH SQUARE=SQUARE+1 GOTO LOOP FINISH: WRITE (SQUARE-1)*(SQUARE-1) HALT end e 2. Write Simple Machine code that corresponds to the following Simple Language Program. (Recall Simple Machine operators: halt(0), read(1), write(2), load(3), store(4), add(5), sub(6), mul(7), div(8), branchle(9), branchge(A), branch(B)). b READ X IF X<=2 GOTO ONE WRITE 5 ONE: HALT end =========================================== 100 40B 30B 309 600 908 30A 200 0 2 5 3. Assume class Lex is a lexical analyzer that reads input from cin and returns one of the following (distinct) int constants: Lex::A, Lex::B, Lex::C, Lex::ENDOFLINE, and Lex::JUNK when the instance method next() is called.
Image of page 1

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

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ 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