Lab 10 Answer Sheet

This lab is to be worked in a group.



Name:________________________Netid:_______________Section:_______

Part 1: Prelab



  1. ________________ ______________________

        
  2. ___________________________________

    ____________________________

    ___________________________________
    ___________________________________
        
  3.  
      _____________________________________________________ 
     
      


  4. _____________________________________________________



  5. }

    _____________________________________________________

  6. Complete the following program that prompts a user for her first name and then reads the name and responds with a personal greeting.
    For example:
    Enter your first name: Sue
    Hello Sue !

    #include <stdio.h>
    #include <string.h>

    void main(void)
    {
       char fname[72];
       char greeting[132];
       printf("Enter your first name: ");


       scanf("%s", ________________________________);
       strcpy(greeting , "Hello ");
       strcat(greeting , fname);
       strcat(greeting , " !");
       printf(" %s \n", greeting);
    }



  7. _____________________________________________________

  8. Circle the correct Answer

         a. int addTen(int x[ ]);
         b. int addTen(int y); 
         c. int AddTen( int); 
         d. void plus_ten( int);
        

  9. _______________________________________

    _______________________________________

    _______________________________________

    _______________________________________


    _______________________________________



Part 2: Function call (pass by value and pass by reference)

  1. To see how variables are modified in by functions in c, write the output when the following program executes.

#include <stdio.h>
void dosumpin(int a, double b[]); /* prototype */
int didsumpin(int d, double e[]); /* prototype */
void main(void)
{
int a = 1;
int c;
double b[2] = {2.0,1.0};

dosumpin(a,b);
printf("a = %i b[0] = %lf b[1] = %lf\n",a, b[0], b[1]);
dosumpin(a,b);
printf("a = %i b[0] = %lf b[1] = %lf\n",a, b[0], b[1]);
b[0] = 2.0;
b[1] = 1.0;
c = didsumpin(a,b);
printf("a = %i b[0] = %lf b[1] = %lf c = %i\n",a , b[0], b[1], c);
}

/* Note dosumpin assigns a value to the integer (a) (a = 8;), but the value of (a) in main is unmodified. However the changes to the array (b) are carried through to main*/
void dosumpin(int a, double b[])
{
b[0] = b[0] + a;
b[1] = b[1] + a;
a = 8;
}
int didsumpin(int d, double e[])
{
e[0] = e[0] + d;
e[1] = e[1] + d;
return 2*d;
}


a = ________________ b[0] = _______________ b[1] = _______________


a = ________________ b[0] = _______________ b[1] = _______________


a = ________________ b[0] = _______________ b[1] = _______________ c = _________________

    Part 3: String Matching and Statistics

  1. How many times does the word 'the' appear? (Exact Match)

    ___________________

  2. How many occurrence of 'the' are there? (Partial Match)


    ___________________

  3. What is the average length of the words in the file illini.txt ?


    ___________________