Lab #1 Assignment

CSE 1320-001

Summer 2011

Due Date:         See class website for due date

(see instructions on website for how to turn this in - “lab submission info”)

Grade value:    6% out of 100% for all grades

                        Lab #1 has three parts, I, II, and III – each part is worth 2% of the total 6%

 

Objective:  The goal for this lab is to provide an opportunity for practice of C program development and the C programming topics covered in Chapters 1–4 and parts of later chapters in Foster and Foster as covered in class.  It is assumed that the student is familiar with the programming concepts but not the C syntax.  This assignment is designed to  help student practice the skills they will need for all the labs in this class.  The three parts of the assignment are:

 

Part I: Practice in accessing and using the omega Unix operating system including creating a secure shell, transferring files to omega, creating directories and navigating in them, compiling a C file that was transferred to omega, running the compiled program, and recording it all in a script file.

 

Part II: Practice in editing a C program file that I give you using a line based editor on the Unix system, compiling the C file, running the program and then debugging it.  This program will have intentional errors that you must fix.

 

Part III: Adding to the program from Part II by writing additional functions that will allow the program to do more actions.

 

Every lab assignment allows students to practice program development, debugging, and testing.  All of these skills are crucial to success in Dr. T’s class.  The format of this assignment is not similar to the assignments that will be required for the rest of the semester but labs from previous semesters may be reviewed to get an idea. A student who is unsure of their skills should start early and should plan to ask the instructor or TA about any concepts they are unsure of. 

 

Topics: 

            Program design

            Modular programming structure

            Error checking

            Programming style

            Compiling code,

Executing code,

Debugging and testing.

 

Plan:  Dr. T gives an overall problem that students work on all semester.  Each lab assignment implements specific concepts.  Succeeding assignments will modify and extend previous assignments. 

 

Part I Assignment:

 

In this part of Lab #1 you are going to practice using the tools you need for the rest of the semester.  After Lab #1 is complete, you will not be required to use ONLY these tools but you are expected to ALWAYS use some of them.  (More on this later.)  For Part I, here are the steps you must complete:

 

1.  On whatever computer you are planning use for your programming assignments during the semester you must have a way to securely connect to “omega” which is the Unix-based system that you will be running your programs on.  If you will be using a PC, you must download SSH Secure Shell Client from the UTA OIT software download page.  If you are using a Mac, you can connect to omega using Terminal to create an secure shell connection.

2.  Once you have ssh downloaded (or Terminal open) you should open an ssh connection window to your account on omega.  You should be able to log in with your 7 character NetID (abc1234) and the you will be asked for your password.  If you have a problem with this, check with the OIT Help Desk in the main library.

3.  Once you are logged in to omega you should list your directory (type: ls) to show the files that are in your top level directory. 

4.  Now start a script file session to capture the rest of the actions that you do for Part I. See the “lab submission info” on the class website for instructions on how to do this. Your script file will be turned in as your proof that you did Part I. 

5.  Now that the script file session is running, list your directory with details (ls -l) .

6.  Back on your PC or Mac use WordPad or TextEdit or some similar simple editor to type the example 1-3 from pages 12-13 in the book into a plain text file.  You may shorten the comments but you must include the same number of comment lines.  You should print out another statement instead of   “C by Discovery”  but put your own statement in double quotes and do not add any lines.  DO NOT use MS Word. (It makes your life complicated for this lab assignment.) Save the file with the name Lab1output.c and make sure it is saved on your desktop.

7.  Now using the ssh (or Terminal) open an sftp (secure file transfer protocol) connection window to omega.  Keep the ssh window open too.  You’ll see your computer’s files on the left and the omega directory on the right in the sftp window.  In the left window, make sure you are showing the files on the desktop – you should be able to see Lab1output.c in the list.  Drag Lab1output.c from the left window to the right window to transfer (copy) the file from your computer to omega.

8.  Go back to the ssh window now and do ls again.  You should see that the file Lab1output.c is now in the directory.

9.  Just for practice now we are going to create a subdirectory on omega.  This is just the same as making a subfolder inside a folder on a PC or Mac.  To make the subdirectory, we will use the command to make a directory (mkdir) and we’ll call the directory C1320.  So in the ssh window type: mkdir C1320   to create a new subdirectory. 

10.  Do ls again to see that C1320 is now listed.

11.  We’ll move the Lab1output.c file to the new subdirectory with the command:  mv Lab1output.c C1320/  (The slash tells Unix that C1320 is a directory)

12.  Do ls one more time and you’ll see that Lab1output.c has disappeared from the current directory.

13.  Now let’s change our location from the current directory to the subdirectory.  We do that with the change directory commend (cd).  So type: cd C1320

14.  Do ls again and now you’ll see that we only have Lab1output.c in this directory.

15.  Two more tasks and we’re done with Part I.  We are ready to compile our little C program.  I hoped you typed it very carefully so that it will compile right the first time.  Before you compile it, let’s just take a look at what you typed in.  Unix has a command that will print out a file to the screen.  For various reasons the command is called the concatenate command but you only have to type cat.  To see what your Lab1output.c file has in it type: cat Lab1output.c   This will print the entire file to the screen.

16,  To compile a C program on omega you will be using the GNU C Compiler (gcc).  The compiler will only work with files that have the extension .c so if you try to compile something else it won’t like it.  To compile your program type: gcc Lab1output.c   If you get some sort of message, that means it did not work and you had an error.  If it works, it does not give any message.  (I’ll get back to the error case.)  [NOTE:  All programs in Dr. Tiernan’s 1320 class all semester MUST be compiled on omega using gcc and must compile and run without errors or warnings.]

17.  Do ls again.  If the compilation worked you should now have a file called a.out in your directory.  This is the executable file the gcc creates that has your program in it ready to run. 

17error.  If you got a message from gcc and/or there is no a.out, go back to your original file on your PC/Mac and make sure you typed it exactly as it shows in the book (except for your own statement replacing” C by Discovery”.  Fix anything that needs it, eliminate any blank lines at the bottom of the file, and do the same steps again.

18.  Once you get an a.out file then you need to run your program.  The a.out file is the executable file so you run it by just typing its name: a.out   Once you do this, the program should print C by Discovery or whatever message you substituted.

19.  When that is done, you should end your script file session and you are done with Part I.

 

Part II Assignment:

 

In this part of Lab #1 you are going to practice using one of the editors on omega.  You must use this editor for this lab but you will not be required to do so for the remaining labs.  The editors on omega that you will access through ssh are line oriented editors.  You will use the keypad to do your editing tasks rather than the mouse.  There are many Unix editors but the most common ones are vi, pico, and emacs.  You will find links to manuals for all of these editors on the class website.  You will not be able to guess your way through using these editors so I highly recommend having a webpage open with some reference info or doing a tutorial online before you do this part of Lab #1. 

 

The goal here is twofold: practice in editing a C program file that I give you using a line based editor on the Unix system and then debugging the program that will have intentional errors that you must fix.  So here are you steps to follow:

 

1.  I will e-mail to everyone a file called CL1P2err.c  (‘C’ ‘L1’ for lab 1 ‘P2’ for part II ‘err’ for errors)  The file will be an attachment to the e-mail that you should save to your PC/Mac desktop.  Don’t open the file on the PC/Mac.  Use the same process as part I above to transfer the file to omega with sftp and open an ssh window to omega. 

2.  Start a script file session on omega and do ls to show the CL1P2err.c file in your directory.

3.  Since it is a C file try compiling it with gcc just like before.  If everything went as expected, you should have two lines of warnings and four lines of errors.  So now you’re going to do some debugging.

4.  First figure out how many things it is really complaining about.  Is it six things or are there six lines of info but really less things to deal with?  What does the first warning say?  “Incompatible implicit declaration of…” – OK, incompatible means it doesn’t agree with you, “implicit declaration” means that you tried to use it yourself without telling C where you got this thing.  And what doesn’t it like?  “built-in function ‘printf’ “ – hmm, it liked printf before so what did we do before that is missing in this program?  Go look at output.c and see if there is some info that would tell C where we want it to find ‘printf’  <You can check the book to help you too.>  OK, I know you’ve figured out what is missing for the printf problem so let’s go put it in the program.

5.  Now instead of editing the program on the PC/Mac and moving it each time, we are going to edit it on omega directly.  Now, I want you to edit this and then go back and fix the other errors before you recompile so you should open a second ssh window and use that window to do your editing.  Open the second ssh window connected to omega and then open CL1P2err.c in the editor you wish to use.  For example, to use emacs I would type: emacs CL1P2err.c

6.  Once your editor opens you will see the contents of the file CL1P2err.c and you can edit it.  Use the arrow keys to move the cursor to the location you want to edit.  Use your reference manual to figure out the editing commands.  When you have added what you need to fix the printf warning from step 4, then save the edited file but keep it open in the editing window so you can make more changes for the other errors.

7.  OK, back to the ssh window with the gcc errors.  Check out the second warning.  Do you think you will have fixed this one too?  Edit the file if you think you need to.

8.  Now the first error – “‘prod’ undeclared” on line 12.  So if ‘prod’ is undeclared and that causes an error, what will fix it?  Where should that fix go?  Go to the editing window and make that change.

9.  The next error line – “(Each undeclared identifier is reported only once”  followed by “for each function it appears in)” .  It also refers to line 12.  Is this a new error or a message about something that it already told us?  Do we need to do anything else to fix this?

10.  The last error line – at line 13 “expected ; before sum”  If you look at ‘sum’ in line 13, what comes right before it?  Is anything missing, like maybe a ‘;’?  Remember that C doesn’t care about the physical line something is on, it looks for the right symbols to tell it when things end.  Decide what needs to be done to fix this and go make that change in the edit window.  Don’t forget to save the file after you edit it.

11.  Once you’ve made the changes you think you need and saved the file, what do you have to do to see if your changes worked?  Do that. 

12.  If you changes worked, then run the program.

13.  Once the program has run successfully, then see if you can enter numbers that will make the program break (not give correct results or crash). This is called ‘testing’. J  After you’ve broken it (or tried three times and didn’t figure out how to) then end the script session and you are done with Part II.

 

 

Part III Assignment:

 

See other part of assignment for Part III.

 

 

Grading Scale:  TBD

 

Part I:

 

Part II:

 

Part III -

Code:  (%)

 

Output:              (%)

 

Miscellaneous: