Goal: The purpose of this part of the assignment is to learn how to use the software needed to run a program and submit it for grading. You don't have to do much programming for this assignment. But this is the time to start reading and tinkering with some code and learn the software tools we will be using. When the next assignment comes along, which will require programming on your part, you should be able to concentrate on the programming and not on the supporting software.
As with any assignment in CSE142, you may use any computer you wish. However, we suggest you do this assignment in the CRC to become familiar with that lab. If you have not used Windows or Visual C++ before, we recommend that you attend one of the tutorials offered during the first week of class. You should be able to do this part of the assignment during the tutorial, and course staff will be there to help you.
Due: The printed part of the assignment is due Monday, June 25. But Web submission is due the previous day -- Sunday, June 24, by 10pm sharp. You should bring the printed receipt to lecture on Monday. If for some reason you cannot bring it then, you may place it, in a properly labeled envelope, in the Homework Box in Sieg Hall by 5 pm on Monday.
What to do -- Overview: Do the following tasks, in this order. Details are given in the following sections.
You might find these instructions incredibly long-winded and complicated! But after you've used the system for a time, it will become easy and natural. Just be prepared for a little frustration now and then along the way.
You will need two floppy disks. Your disks will need to be formatted if they weren't already at some time. On Windows, open My Computer. Click the icon labeled 3 1/2 Floppy [A:] to select the floppy drive. From the File menu, select Format.... It is a really a good idea to label your disks, both electronically and physically, with your name, e.g., "J. Doe 142" and "J. Doe 142 Backup", rather than something generic like "disk 1" or "my disk". Enter your electronic label in the box labeled Volume Label and click Start to format your floppy.
Click on the PC self-extracting archive: here. (If this doesn't work, or you are not using a Windows machine, you can obtain the individual source file here) This will initiate a file transfer operation. The goal is to copy the file called hw0stuff.exe onto your floppy. At a certain point in the operation, you'll be asked where to put the file; save it to the desktop (normally the default location), where you'll use it temporarily before moving it to your floppy disk.
You should now see an icon labeled "hw0stuff.exe" on your desktop. This is a "self-extracting archive," that is, it contains several files compressed and packaged together. To extract the files, you run the archive by double-clicking it. This causes the WinZip Self-Extractor to appear on your computer. Click the Unzip button and it will automatically create a HW0 folder for you and place the files you need in the new folder. When it has finished, it will tell you that seven files were unzipped successfully. Tell it OK and then click the Close button.
Open the new HW0 folder on your desktop by double-clicking it. Most of these files are used and maintained by the compiler (MSVC), and you will only be editing one of them directly. To start the compiler and load your program, double-click the hw0.dsw file in the HW0 folder. (If you double- clicked the hw0_orig.c file, you did it wrong. Close the compiler and do it over.) The compiler should open and load the simple C program we have given you for this assignment. The program will be displayed in the largest part of the MSVC window. You'll see lots of other buttons and window panes; ignore them for now, and just look at the program.
There are two kinds of text in a C program: the program code, and comments. Comments are text surrounded by /* and */. They have no actual effect on the operation of the program, but they are essential documentation for someone who is trying to understand how the code works. The remaining text is the actual C code.
A C program is made up of a collection of functions that either compute a value (like sqrt(2), which yields 1.414 when it is executed) or perform some action, like the function main in this program which reads and writes some numbers on the screen.
The lines of code in a function are called statements, and, in a simple program like this, they are executed one after the other from top to bottom. In this program, all of the statements either print something on the screen, or read a number that the user types on the screen. Look at the last line in the program, which is a printf statement. Simplifying the details, it is
printf("control string", i, j, i*j);This says, print the values of the three expressions i, j, and i*j, using the layout specified by the control string - the text surrounded by double quotes. The control string gives text to be printed with the values of the three expressions, and shows where in that text the expression values should be placed. The detailed incantations aren't important now; we will get to them in the next few lectures.
There is one line of code that is not an actual statement. The directive
#include <stdio.h>at the beginning of the program allows the program to use scanf for input and printf for output. Again, the details will be covered in a few days, or you can read ahead in the text or course packet to get a better idea of how this works.
Build and run your modified program and test it to be sure it works properly.
After making this addition, feel free to extend the program to compute something more complicated, or add additional variables to the program along with scanf statements to read their values, or anything similar. This is just for fun; it's not required and doesn't earn extra credit.
After you have made your changes to the program, it is important to save your changes. Pull down the File menu and select Save (be sure the editor window is active before you do this-- click anywhere in the editor to make it active). This write your changes onto your diskette in the file named "hw0_orig.c". It is important that you do this often in the future to avoid losing your work.
When your work is saved, you should hand it in. This will always be done on the web in this course, so you should be sure that you know how it works. Go to the turnin page. Fill out the form (click on the words "help" if you don't understand something). At the bottom of the form, you will need to specify the name of your file. Use the Browse button to find it: navigate to the desktop, open the HW0 folder, and choose the hw0_orig.c file (not the hw0.dsw file that you clicked to open the compiler). Click the turn in button at the bottom when you're done. Your program will be checked to be sure that it compiles. If all is well, you'll get a receipt back showing what we received. Read carefully through the receipt in case there are error messages or other important information. If everything looks good, print out and turn in this receipt. You will hand in this receipt in class on the date given above.
If you were to log off of the computer you're working on right now, all of your work would be lost. You need to make TWO copies. Place your first floppy in the disk drive and drag the HW0 folder from the desktop onto the A: drive icon (also on the desktop). A box will pop up showing the progress of the copying operation, and will disappear when the computer is finished. Repeat this process with your other diskette so you will have a backup copy of your work.
Experiment #1. What happens if there are errors in the program? Delete a quote mark (") somewhere or add in an extra one. What sort of messages do you get when you try to run the program after this change? Fix the quotes, then get rid of the #include directive at the beginning of the program. What happens? Fix that, but then misspell one of the identifiers or keywords in the program. What do you see? What happens if you take the original program and remove a & mark in one of the scanf statements?
We encourage you to post the most interesting (as in weird) things you discover to the CSE142 general newsgroup. But be sure the version of the program you hand in does not have any errors.
Many C programming environments are infamous for producing obscure, confusing, misleading, obtuse, and bizarre errors in response to even simple punctuation errors. Visual C++ is no exception. Everyone makes punctuation and spelling errors. It will save you much time and grief later if you start now to get an idea of what you might see when this happens.
Experiment #2. Another experiment is to see what happens if you (as the user) deliberately type in bad data when running the program. Suppose what you enter is not an integer? Or is extremely large, etc. Does the program run but give bad results? Can you make it crash?
It's actually rather tricky to write a program that is completely immune from a user who enters bad data maliciously or in ignorance. We'll learn a few things about this as the quarter progresses.