CISC105 Fall 2006 Lab04 CISC105 Fall 2006 Lab04

Programs

  1. Write a function that computes and prints the value of a number raised to an exponent. It will take two parameters (the double base number and the integer exponent) and use a loop to raise the number to the appropriate power. Call the function from main(). Test appropriately.

  2. Put the function call from problem 1 inside a loop so that the user can calculate as many exponentiations as they want. Design the loop to halt when the user enters a sentinel exponent of -1.

  3. Write a function called indent. It will be a void function and takes a single integer parameter called length. If the number is negative, the function prints "error" and returns. Otherwise, it prints length spaces (nothing else) and then returns.

  4. Write a program that uses indent to create the indents for a diagonal line. Your program will use a for loop that calls indent to print the following (based on user input):
    % ./a.out 
    Enter height: 5
    *
     *
      *
       *
        *
    % 
    
    


  5. Create a file called data1.txt. Put ten assorted hobbit heights1 (in meters) in it, separated by spaces, and save it. Now write a program that reads the ten numbers with a loop and prints them out.

  6. Modify 5 so that the same ten heights are read into a type double array of ten elements. After the array is full, use a separate loop to print the contents of the array on a single line.

  7. Modify 6 so that after you print the array, you call a function that takes the array and its size as a parameter, and computes and prints the average height.

  8. As you program, practice all of your Unix commands that have been introduced in lab and class: ls, pwd, cd, cp, rm, mv, and mkdir because they will be on the exams.

You should have a total of 7 programs named lab04.1.c to lab04.7.c. Make a single script file (see lab00 for the instructions) where you cat, compile, and run each one in its final form.

Submit all C files and your script on WebCT, and give the paper version of the complete script file only to your TA at the beginning of your next lab (all Friday labs) or in lecture Friday (Wednesday labs only). Note: Cat, compile, and run each program in order! Do not cat all programs, then compile, etc.

Footnotes:

1If you don't really know the height of a hobbit, check the article at wikipedia.org before writing your data file.


File translated from TEX by TTH, version 3.38.
On 26 Sep 2006, 22:58.