Computer Science 2530
Fall 2019
Programming Assignment 1

Assigned: Wednesday, September 4
Due: Friday, September 13, 11:59pm
Points: 250

Table of Contents

  1. Purpose of this assignment
  2. What you will submit
  3. Background
  4. The assignment
  5. Additional requirements
  6. A template
  7. A refinement plan
  8. Compiling and running your program on xlogin
  9. Issues to be aware of
  10. Submitting your work
  11. Late submissions
  12. Asking questions

Purpose of This Assignment

The purpose of this assignment is to familiarize you with basics of C++ and to give you an exposure to following the requirements of this course.

Pay attention to following the instructions and following the standards. Particular functions are called for. Define exactly those functions. Don't ad lib.


What You Will Submit

You will need to submit one file called points.cpp. Do not use a different name for that file.

Read the entire assignment before you start writing anything.

Because contracts are provided for you, the contract bonus is not available for this assignment.


Background

Suppose p1 = (x1, y1, z1) and p2 = (x2, y2, z2) are two points in 3-dimensional space. The distance between p1 and p2 is
(x1x2)2 + (y1y2)2 + (z1z2)2.


The Assignment

Write a complete C++ program called points.cpp that does the following.

  1. First it reads three points p1 = (x1, y1, z1), p2 = (x2, y2, z2) and p3 = (x3, y3, z3) from the standard input in the following format.

      x1 y1 z1
      x2 y2 z2
      x3 y3 z3
    
    There are three real numbers per line, giving the x-, y- and z-coordinate of a point in 3-dimensional space.

  2. The program should show, on the standard output,

    1. the three points that were read,
    2. two of the three points that are farthest apart, and
    3. the distance between those two farthest points.

    If two or more pairs of points are equally the farthests apart, your program should show all of those pairs. See the example below.

Example 1

If the input is

  1.0 3.0 3.0
  1.5 7.2 4.3
  4.0 2.0 1.0

then the output should be

The three points are:
     1.000      3.000      3.000
     1.500      7.200      4.300
     4.000      2.000      1.000

Two farthest points are:
     1.500      7.200      4.300
     4.000      2.000      1.000

The distance between them is:      6.647 

Example 2

If the input is

  0.0 0.0 0.0
  0.0 2.0 0.0
  3.0 1.0 0.0

the program should write

The three points are:
     0.000      0.000      0.000
     0.000      2.000      0.000
     3.000      1.000      0.000

Two farthest points are:
     0.000      0.000      0.000
     3.000      1.000      0.000

The distance between them is:      3.162 

Two farthest points are:
     0.000      2.000      0.000
     3.000      1.000      0.000

The distance between them is:      3.162 

Use output format %10.3lf for printf to write each real number. (The last two characters of the format are lower-case ell and lower-case eff.)


Additional Requirements

The next section lists functions that you must define. You are required to define exactly those functions. Do not add or remove parameters or change the intent of those functions.

Do not use any of the following. (You probably don't even know what most of them are. That is fine. You don't need them.)

A program that wholly ignores the instructions will receive a grade of 0, even if it works correctly.


A Template

Create a directory (folder) to hold assignment 1. Download

into that directory. Makefile and dotest help you compile and test your program.

File points.cpp is a template to get you going. Edit it to make your program. Replace **your name** with your name. If you use tabs, replace @@ by the spacing between tab stops. For example, if you replace @@ by 4, then you are saying there is a tab stop every 4 characters.


A Refinement Plan

Follow this plan to write this program. Do not ignore the plan and do this in a different way. If you do, you will not learn how to develop software, and that will hurt you on future assignments.

Development plan
1. Define function echo by filling in its body.

Edit points.cpp. Make echo show the three input points in a readable format, using %10.3lf for each number. Be sure that the output clearly labels the three points as the input points.

Echo must not read anything from the standard input. If it does, you will receive no credit for echo. (I am sorry for the need to repeat things like this, but I have found that some students ignore it unless I really stress it.)


2. Write part of main.

Make main read the 6 real numbers and show them on the standard output by calling echo. Test your program before continuing to the next step.


3. Define function distance.

Make distance do what its contract says it does. Distance must not read from the standard input or write to the standard output.

Note. Any time any function other than distance needs to know the distance between two points, it must use distance to get that information. Function distance is an expert on computing distances, and no other function needs to know how to do that.


4. Modify your main function.

Make main show the distance between (x1, y1, z1) and (x2, y2, z2). Test your program. Is the result correct? Do not countinue until it is correct.


5. Define farthest.

Make farthest do what its contract says it does. Be sure that it returns true or false. Farthest must not read from the standard input or write to the standard output.


6. Modify main again.

Remove the prior test in main. Make main show the result of farthest(x1,y1,z1,x2,y2,z2,x3,y3,z3). Test it. Look at the results. Are they correct? Test at least one case where the correct answer is true and another case where the correct answer is false.

Do not continue until farthest seems to be producing correct results.


7. Define ShowFarthest.

Make showFarthest do what its contract says it does. ShowFarthest must not read anything from the standard input.


8. Modify main again.

Make main show (x1, y1, z1) and (x2, y2, z2) as the farthest points by calling showFarthest. Don't be worried that those two points aren't necessarily farthest apart. That will come next.

Test your program. Does it show the first two points as the farthest?

9. Define ShowAllFarthest.

Make ShowAllFarthest do what its contract says it does. You will want to use if-statements to test all possible pairs of points that might be farthest apart. To show that a pair of points is farthest apart, ShowAllFarthest must use ShowFarthest. ShowAllFarthest must not read from the standard input.


10. Modify main again.

Remove the test prints from prior tests. Modify main so that the program is finished; it must do what the assignment asks it to do.

Test your program. (See make test below.) If your program does not work, fix it.


11. Submit your program.


Compiling and Running Your Program on Xlogin

Make sure that you have Makefile and dotest by doing command

  ls
which shows the names of the files in the current directory. Use exactly the names Makefile and dotest. Do not call the make-file MakeFile or Makefile.txt or anything except, exactly, Makefile. Command
  mv Makefile.txt Makefile
renames file Makefile.txt as Makefile.

The following commands will work now.

make
Just compile points.cpp and create an executable file called points. If there are errors, they are reported. No news is good news.

make run
Run executable file points (compiling it first if it needs compiling).

make test
Run executable file points (compiling it first if it needs compiling) on some examples that are provided. This is an example of automated testing. A directory containing the tests will be created.

Check the results. Are they correct?

make clean
Remove all machine-generated files. After you do this, the next time you do a make, points.cpp will be recompiled.

Issues to Be Aware of

  1. Avoid long lines. Limit lines to about 80 characters.

  2. Indent well throughout. A very poorly indented program will receive a failing grade.

  3. Use margin comments sparingly, if at all. Some students have learned to write comments in the right margin of each line explaining what that line does. Please do not do that.

  4. No function body (not counting the heading) should have more than 16 noncomment lines.

  5. Function farthest must not compute the distance between the same two points more than once. (Two separate calls to farthest can recompute distances, but there should be no duplicate calls within a single call to farthest.)

  6. Do not change the value of any parameter. If x1 is a parameter to a function then the function must not contain

      x1 = ...
    
    or any other kind of statement that changes the value of x1.

  7. The last character that your program writes on the standard output should be an end-of-line character ('\n'). That is true for all of your programming assignments.

  8. The true-body and false-body of every if-statement must be a compound statement. That is, it must be surrounded by braces.

    Each pair of matching braces must be in the same column, with the right brace immediately below the matching left brace, and with no characters on or to the left of a line segment between the matching braces. An if-statement that does not have an else-part should be something like the following.

      if(…)
      {
        …
      }
    

Submitting Your Work

To submit your program, log into xlogin and change to the directory contains your work. Run command

  ~abrahamsonk/2530/bin/submit 1 points.cpp
You should get a reply that the submission was successful. If you don't, something went wrong. Command
  ~abrahamsonk/2530/bin/submit 1
lists the names of the files that you have submitted for assignment 1.

You can do repeated submissions. New submissions will replace old ones.


Late Submissions

Late submissions will be accepted for 24 hours after the due date. If you miss a late submission deadline by a microsecond, your work will not be accepted. It is not a microsecond late. It is 24 hours plus a microsecond late.


Asking Questions

To ask a question about your program, first submit it, but use assignment name q1. For example, use command

  ~abrahamsonk/2530/bin/submit q1 points.cpp
Then send me an email with your question. Do not expect me to read your mind. Tell me what your question(s) are. I will look at the file that you have submitted as q1. If you have another question later, resubmit your new file as assignment q1 and send another email.