CS1440 - Extra Lab (1)

Objectives:
Objectives of this extra Lab are:

Preparations:
First, login to cs. Once logged in, create the directory extra1 under directory 1440, change to that directory, and complete your work there.

Activity (1): Electronic mail

One of the wonders of computer communications is electronic mail, or "email". If you haven't used email before, you'll soon find yourself hooked. You can send your thoughts almost immediately and you can mail as easily to 10 people as one. The email you receive is saved (until you explicitly delete it) and can serve as a transcript of your life (or part of it). Also, if you have questions about the class, your instructor can answer your questions by email.

 At the UNIX prompt, type the name of the email program we'll be using:

pine
If this is the first time you've ever used pine, it will ask you if you want to send an anonymous letter to the developers to help them keep track of their users. Choose yes or no.

 Now that we've started pine and have replied to the request to send the author's email, go here to read more about pine.  Before we start working with pine, I will walk you through some steps to set up a printer in pine, so you can print your emails on the printer in the PC-Lab in room 439 only.
    Step 1: in pine move to Setup or press s to bring up the Setup screen
    Step 2: press p to get the printer setup
    Step 3: in the new screen, use the down arrow to move to (highlight) the last option "Personally selected print command"
    Step 4: press a for adding a printer, this will give you "Enter printer name :"  type pclab, then press Enter
                A new line appears as "Enter command for printer :" type enscript -Ppclab, then press Enter
    Step 5: Press s to select that printer, then E to exit setup.  This will bring you back to the Main Menu.

This enables you to print your emails in the pclab.

 Make sure to perform the exercises described in the above pine manual where:

Activity (2): More Unix Commands

Many, many commands are included with the Unix (Tru64Unix on cs) operating system. We have already been using quite a few of them including: cd, ls, mkdir, pico, and g++. In this activity, we will look at some other useful and/or interesting Unix commands. Make sure to try each of the commands. Just enter the command name at the Unix prompt.

 Do you ever wonder which other users are on the cs machine at the same time as you? To find out, try out the who command. The w command is like who but provides information on what the user is running.  To see even more, try the finger command (or just f). This command can also be used to find someone's account name (maybe a friend you know has an account on cs). Say your friend's name is Robert. If you enter, "finger robert", all users whose names contain "Robert" will be displayed.

 When you tried finger, you might have noticed that the name displayed for you is not your "normal" one. For example, it might list your legal name including first, middle and last name. You can use chfn (change finger) to set it to whatever you prefer. Since what you enter will also appear in emails you send, it is probably best to just enter your first and last names ("cute" and/or "nicknames" should not be used!).  You should also keep in mind that your instructor and others may delete your email if they don't recognize the name.  This is a very common practice to avoid unwanted emails and viruses.  So before you change that name, think about it carefully.

 Another useful command is the date command (try it!). You might be concerned that you're having so much fun that you'll be late to your next class. With date, you will always know what time it is. Speaking of dates, how might you use Unix to determine the date of next Saturday? This is a good use of the cal (calendar) command. Try it! By default it shows the current month. If you'd like to see a calendar for the entire year, enter "cal 2003".

Finally, there is a command that might be used more than any other. Why is it so common? Because it provides us with a convenient way to see the contents of our files -- something we do very often. Though it would be possible to start pico to view files, it is better to use a command that is faster and prohibits us from (accidentally) changing the file's contents.

 We'll use the less command to view the contents of files. It always requires at least one argument following its name. Try the following: "less /etc/passwd". Hitting the "space bar" moves forward by one window; entering "b" move back one window. There are other less sub-commands. To see a summary of the many less sub-commands, just enter a "h" (help).

Activity (3): Another Simple C++ Program

First, make sure you are in the "extra1" directory within your "1440" class directory. In order to make sure you are in the right directory, you can run the pwd command which will print (display) the current working directory name.

 Shown below is a program to compute a sales tax amount for a purchase. It will ask the user to enter the price of an item, compute the sales tax, and then display both the price and tax.

Please use pico to type the following program into a file called "salestax.C". This will provide you more experience with the editor. The sooner you become familiar with pico (or another editor) the better. Practice makes perfect!

OK, go ahead and type the following into pico:

//
//  salestax.C:  Compute and display the amount of sales tax
//

#include<iostream>

int main () {

  double price;

  // Obtain the price of an item
  cout << "Purchase price? ";
  cin >> price;
  cout << endl;  

  // Compute and output the sales tax amount
  cout << "The sales tax on $" << price << " is ";
  cout << "$" << price * 0.065 << endl;

  return 0;

}
Once you are sure you have entered the above accurately, go ahead and compile it. But this time, let's use a slightly different g++ command. Here's what to enter: "g++ -o salestax salestax.C".

 What does the "-o" do? This option to g++ allows us to override the default name ("a.out") of the executable file. Once the source file has been successfully translated, a new file ("salestax") should appear in the current directory. Use the ls command to verify that it has, in fact, been created.

You can run the program by just entering "salestax" at the Unix prompt. Go ahead and run it now.

What to submit for this activity:
You are required to submit a hard-copy of this program.  In order to print a copy, at the Unix prompt type:

enscript -Ppclab  salestax.C

Please DO NOT print the file name salestax without the .C.   Also, never print an a.out file.  

Follow-up Activity
Now that you ran that program and were able to display the result, go through the program line-by-line and try to understand everything in it.  If there is something you are not clear ask your instructor or a classmate to explain it to you. Once you are absolutely sure about all details, complete the following assignment.

Edit the above program such that in addition to the price it asks the user to input the tax rate and then displays:
    1) the sales tax, and
    2) the total cost (price+sales tax)

You may want to save the new program with a different name (for example: newsalestax.C or salestax2.C).  Compile and run the program and make sure it produces the correct results.

What to submit for the follow-up activity:
You are required to submit a hard-copy of this program.  In order to print a copy, at the Unix prompt type:

enscript -Ppclab  filename.C

Please DO NOT print the file name without the .C.

Post Lab: Due: At the Start of Next Lab
Complete Problem (5) at the end of Chapter (1) on Page 38. Use the program that you have completed in the follow-up activity of Activity (3) as the base for your program.