Assignment #0 Part B

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.

  1. Get the Visual C++ project containing the starter version of the program from the CSE142 web. (If you are using a different system, retrieve the C source program from the web pages.)
  2. Use Visual C++ to compile and run the program as is.
  3. Make a small modification to the program as described below, run it, and test that the modified program works properly.
  4. Submit your program electronically over the web, then print the "receipt" you got when you submitted it, and hand it in for grading. Without the official receipt, you won't get credit.

Get the Starter Version of the Program

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.

Study the Program

Although the purpose of this assignment is to learn the mechanics of using the software, it's not too early to start looking at the code and get an idea of what's going on. This first program previews several topics that will be covered in the first couple of weeks of the quarter. By the end of the first week of class, you will have seen most of these things. Here are some things to look for, especially if you're getting started earlier. You do not have to understand all of this immediately.

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.

Run the Original Program

Before you can actually run the program, you must compile it. To do this, simply pull down the Build menu and select Build hw0.exe. Watch the window pane at the bottom of the MSVC window. First, you'll see MSVC compilelink it. You'll learn what these terms mean later in the course, but for now you should just watch for the a message saying " hw0.exe - 0 error(s), 0 warning(s)" This is your cue that the program compiled successfully. Now, you can run your program. Like most things, there are several ways to do this, but the best is to pull down the Build menu and select Execute hw0.exe. A black console window will open, and the program that you just compiled will ask you to enter two numbers. It will print out their product, and then it will be finished. A message asking you to "Press any key to continue" is the compiler's way of giving you time to see the results before closing the window. Hit a key, and the window will close.

Modify the Program

Once you've been able to successfully build and run the original program, modify it so that in addition to printing out the the product of the two numbers, it also prints out their difference (the result of subtracting the second number from the first).   That is, after printing "The value of the product...", your program should next say "The value of the difference..." with the correct numbers.  By Wednesday you will have seen enough C code to figure out how to do this.  You can also ask questions about it in quiz section on Thursday and at one of the optional tutorial sessions.

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.

Saving your work

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.

Hand in the Program

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.

Copy your work to your floppies

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.

Experiments (optional but highly recommended)

After you've completed the assignment, here are suggestions for experimenting with the C source program and Visual C++. Don't worry about damaging anything. At worst, you might need to load a fresh copy of the program from the web and start over.

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.