c109s05t1 - CSE 109 Test 1 Wednesday 2 March 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 1 Wednesday 2 March 2005 >>>>>>>>>>>>>>>>>>>>>>>SUGGESTED ANSWERS<<<<<<<<<<<<<<<<<<<<<<<<<<< 1. Assume that the file code.h contains the following three lines void test1(); void test2(); void test3(); and assume that the file code.cc contains the code for the three fucntions declared in code.h. Write a program that enables the entry of 1, 2, or 3 on the command line and then calls either test1(), test2(), or test3(), depending on whether 1, 2, or 3 is entered. Your program should assume that the file code.cc is compiled separately. If the executable code is stored in myProg, a legitimate call might be myProg 1 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #include <fstream.h> #include "code.h" void check(bool b,char *mess); int main(int ct,char *arg[]) {check(ct==2,"Usage: myProg <digit>"); check(arg[1][0]>='1' && arg[1][0]<='3' && arg[1][1]=='\0', "Argument should be '1', '2', or '3'"); switch(arg[1][0]) {case '1': test1(); break; case '2': test2(); break; case '3': test3(); break; } return 0; } void check(bool b, char*mess) {if(!b) {cout<<mess<<endl; exit(1); } } <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 2. Write a makefile that assumes the program in question 1 is stored in prog.cc, that creates an executable file based on separate compilations of prog.cc and code.cc, and that stores the executable file in myProg.
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