Lab 2: Getting Started With C

Objectives

The objectives of this lab are threefold:

  • to organize you EE 160 Team,
  • to begin working with the C compiler to get several small programs to compile and execute,
  • and to give you some more practice at navigating around in Unix.

Team Formation

The purpose of this task is to meet with your teammates for the semester and decide among yourselves the details of how your team will operate. All of the members of your team should sit at workstations in the same row in the lab, beginning with this lab and in the future. You should spend at least an hour of this lab period discussing team issues with the members of your team. In particular, you should:

  • Each individual should, print out this team exercise and spend about 10 minutes doing the "INDIVIDUAL TASK" described there.
  • Then, as a team, do the "TEAM TASK" described there.
  • Using your discussion from the above exercise, as a team, you should write up a list of 5 to 10 goals and expectations of your team for the semester. Your list should address ALL of the following issues:
      • What behavior do you expect from all members of the team? (come to meetings, labs, class on time, be prepared, etc.).
      • When and where will the team meet to work together? (teams are required to meet face-to-face at least once per week outside of class).
      • What does the team expect to get out of this course this semester? (grades, knowledge, skills).
      • How will the group assess how you are performing as a team?
  • Decide on a name for your team.

One member of the team should write-up the team goals and expectations, and your team name in a file, and send it to me (chris.uh.class@gmail.com) with copies to all members of the team and your TA.

Explore C program Creation & Compilation.

In the following problems you are asked to create five C program source files, compile them, and get them to work. You should do this lab individually; however, you can consult with your teammates and the TA to get help. Each individual should turn in all five files as described below by the end of your lab period.

  • Compile, link, and run the C program welcome.c. What does it produce as output?
  • Modify the program in myname.c to print your full name. You must compile and run your program to verify it works correctly.
  • Copy the program that prints your name into a new file named myinfo.c. Extend this program to also print out your complete e-mail address on a separate line after your name.
  • Enter the pay0.c program from Figure 2.1 (in Section 2.1.2 of the text, think about how you can get this file). Get it working. Change it to compute the pay for working 32 hours at a pay rate of $9.75. (This is a variation of Problem 3 in Section 2.9 of the text).

Task

Given the time an object falls,in seconds, compute the velocity of the object when it hits the ground using:

          • velocity = g * time

and the distance it fell using:

          • distance = g * t * t / 2

For this problem, setting the value of time in the program and processing one set of data is sufficient. My code for this program (with comments showing the algorithm) can be found in the file ~ee160/Labs/Lab2/gravity.c, but it contains some errors. Your job is to copy the file to your directory (use the cp command) and fix all of the errors so that the program compiles, runs and produces the correct answer.

More practice with Unix

You have created five ".c" files in your EE160 directory for Lab 2, but there will be many more files in future labs, so you should create a directory for these files as follows:

  • In your EE160 directory, create a directory Labs, and verify that it exists.
  • Move all five programs that you created during this lab into that directory, and verify that they have been moved. (Use the mv command (for move), which works like the cp command. You can look at the man page for mv by typing man mv).
  • Make a new directory Lab2 inside Labs. Move all of the files that you placed in Labs into that new directory and verify that they are there and are no longer in Labs.
  • Wiliki (UH Students) - users skip (1) below. Laulima (KCC Students) users - do (1) below for all submissions for the rest of this class and do not perform the grade command below. It will not work.

  • (1)If are doing Laulima submissions, The below "grade" command will not work for you. You must submit your lab (all future labs and homeworks as well) by using the following guide: Laulima Submissions.

Use the "grade" command to turn in these five programs (welcome.c, myname.c, myinfo.c, pay0.c and gravity.c). Your command will look like the following:

The format is 'grade -lab#s@,ee160 file1.c file2.c' -

(# = lab number, @ = section number) Make sure to replace # and @ accordingly.

The above command submits file1.c and file2.c

If you are in Section 001 use:

grade -lab2s1,ee160 welcome.c myname.c myinfo.c pay0.c gravity.c


If you are in Section 002 use:

          grade -lab2s2,ee160 welcome.c myname.c myinfo.c pay0.c gravity.c

If you are in Section 003 use:

          grade -lab2s3,ee160 welcome.c myname.c myinfo.c pay0.c gravity.c

If you are in Section 004 use:

          grade -lab2s4,ee160 welcome.c myname.c myinfo.c pay0.c gravity.c

You should verify that you turned in things successfully, which you can do with the grade command by simply leaving the file names off from the previous command:

          grade -lab2s1,ee160
          
          OR
          
          grade -lab2s2,ee160
          
          OR
          
          grade -lab2s3,ee160

          OR
          
          grade -lab2s4,ee160