c109f05t2 - CSE 109 Test 2 Wednesday 16 November 2005...

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 16 November 2005 <<<<<<<<<<<<<<<<<<<SUGGESTED ANSWERS>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 1. Write the MACH1 code that corresponds to the VE program below. Recall MACH1 operators: read(0), write(1), load(2), store(3), clear(4), add(5), sub(6), mult(7), div(8), addi(9), subi(10), multi(11), divi(12), jumpl(13), jumpg(14), halt(15). x begin read x write 10 if x<=15 goto g write x g: halt end <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 0 0 0 3 10 read x 1 2 11 2 1 0 write 10 3 2 10 4 6 12 x-15 5 13 9 6 2 10 7 1 0 write x 8 15 0 halt 9 0 0 x 10 0 10 11 0 15 12 E >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 2. Write a program that lists the strings entered on the command line and then states which correspond to an existing file. Thus, if the executable file for the program is stored in a.out and the files a, b, and c exist in the directory, then the command a.out a d p q would display something like The file 'a' exists The file 'd' does not exist The file 'p' does not exist The file 'q' does not exist <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< #include <fstream.h> int main(int ct,char **arg) {ifstream f; for(int j=1; j<ct; j++) {f.open(arg[j]); cout<<"The file '"<<arg[j]<<"'"; if(f.good()) {f.close(); cout<<" exists\n"; } else cout<<" does not exist\n"; } } >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
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