CPS 6 Spring 2000: Assignment #2

Due: Thursday, Feb. 10 by midnight

20 points

Setup

In your cps006 directory, you should create an assign2 directory to work in. You'll then copy files into this directory to help you get started. That is, type the following unix commands from your account after you login (don't forget the trailing dot on the last line).

cd cps006 mkdir assign2 cd assign2 cp ~ola/cps006/assign2/* .

If you did these commands correctly, typing pwd should show that you are in your assign2 directory, and typing ls should show the file Makefile.

You might want to refer to lab1 for information on editing, compiling and running programs.

Note that 20% of your program grade is based on the readability of your program. This includes things like style, comments, and the naming of variables and functions. Make sure you include a comment at the top of each program with your name, course and purpose of the program specified.

// Name: YOUR NAME HERE // // Course: CPS 6 // // Purpose: purpose of program here //

Problems

  1. Write a program called printname.cpp that prints a program that prints your name. Note that the output of your program should be a complete C++ program. If the output from your program was then saved in a file, compiled and run, it would print your name.

  2. Write a program called webpage.cpp that prints a simple web page in html with your name, cps 6 and assignment 2 on it. Here is an example of what the output of your program might look like. If you don't know html, you can just output what is below with YOUR NAME HERE changed to your name.

    <TITLE>CPS 6 - Spring 2000 LAB 2 </TITLE> <html> <body bgcolor="white"> <Center> <h1> CPS 6- Spring 2000 - Assignment 2 <p> YOUR NAME HERE </h1> </center> </body> </HTML>

    To print a double quote you'll need to use an escape character, i.e., \" prints a quote, so that

    cout << "\"hello\"" << endl; will print "hello" (the quotes are printed).

  3. Write a program called sight.cpp that generates the following output (excerpts from a book by Marten and Carle). The words after the colon on each line, which are in italics, are entered by the user

      enter color and animal: brown bear
      enter another color and animal: red bird
    
      brown bear, brown bear, what do you see?
      I see a red bird looking at me.
    
      enter another color and animal: purple cat
    
      red bird, red bird, what do you see?
      I see a purple cat looking at me.
    
      enter another color and animal: blue horse
    
      purple cat, purple cat, what do you see?
      I see a blue horse looking at me.
    

    Note that the color and animal at the end of the second line of a verse is the same color and animal on the first line of the next verse. Also note the blank lines around each verse.

    If you don't include any functions other than main in your program you'll be duplicating a lot of code. In general it's not a good idea to duplicate code so you should almost certainly include functions to generate the output. Your program must prompt the use for four different animals as shown in the example run above. User-entered strings are separated by white space so two variables are needed to store "brown" and "bear" in the example above.

  4. Write a program named seconds.cpp that prompts the user for a number of seconds and prints how many hours, minutes, and seconds the number represent, e.g.,
      prompt> enter number of seconds:  20000
      20000 seconds = 5 hours, 33 minutes, and 20 seconds
    

    You'll probably want to use the operators / and % to make your calculations. Extra credit if your program prints the number of days whenever the hours are more than 24 (you'll need to peek into chapter four for help with this).

Submit

When all your programs compile and produce the correct output, create a file named README (please use all capital letters in naming the file). In the file include your name, section number, the date, and an estimate of how long you worked on the assignment . You must also include a list of names of all those people with whom you consulted on the assignment.

To submit your programs electronically type:

    submit_cps006 assign2 printname.cpp webpage.cpp sight.cpp seconds.cpp README

The executables are accessible from /usr/local/bin/submit_cps006 on CS machines and /afs/acpub/project/cps/bin/submit_cps006 on the acpub system. You should receive a message telling you that the programs were submitted correctly.

To see that the programs were submitted correctly, type

    submit_cps0066 assign2

with no arguments and a list of the files submitted will be shown.