Machine Problem 1, due at the end of Sept 16

Part of the homework for CS:2630, Fall 2019
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

Framework: Your program must begin and end as follows:

/* mp1.c by Your Name Here */
#include <stdio.h>
#include "/mnt/nfs/clasnetappvm/fs3/dwjones/2630mp1.h"

int main() {
    ... your code here ...
    return 0;
}

Obviously, where it says Your Name Here put your name, and where it says ... your code here ... put C code to solve the problem.

Details: The second header file above, ...2630mp1.h defines two arrays:

Specifically, to output the required text, you need to look at successive elements of key. If key[i] is non-negative, the next character to output is text[key[i]].

If key[i] is less than -1, it indicates the negative of the number of successive characters from text that must be output, starting with the most recent character output. Thus, if text is "abcdef", and the key contains the sequence 2,-3, then the output for that part of the key would be text[2], text[3], text[4] (3 consecutive elements starting with 2), which gives "cde".

There will never be consecutive elements of key that will be negative except that the -1 at the end can follow anything. The first element of key will never be negative.

Top Level Specification: Write a C program that outputs the text described by the header file, as described above, and nothing else. If you get it right, the output should be in coherent English.

Grading: 5 points. Correct output is worth 2.5 points. The remaining credit will be offered only for those who have correct output.

Failing to handle negative keys correctly will be penalized 0.5 for off-by-one errors and 1.0 for more serious errors. Errors for positive keys are more serious because they are the easy case.

Code that does not compile will not earn any credit.

Stylistically clean code is important; that is why half the credit is reserved for style, but only if the code works. Bad indenting will be penalized up to 1 point from the 2.5 style points. Excessive or inadequate white space within and between lines will be penalized, again, up to 1 point. Excessive or inadequate comments will be judged similarly.

Note: Comments should not repeat the assignment. Assume that the reader of your code has read the assignment. Assume that the reader knows how to program, so commenting i++ with /*increment i*/ would be stupid. Comments should help the reader when the code is hard to follow.

Submission: To submit your work, it must be in a file named mp1.c in your current directory on the CLAS Linux system, and you must know your section number. In the following, what you type is shown in bold face. Begin at the linux command-line prompt:

   [HawkID@fastx?? ~]$ submit mp1.c

The system will respond by prompting you for the course number:

   Course (for CS:1210 use CS1210): CS2630

The system will respond by listing the places you can submit. Pick the one that corresponds to your section and the machine problem number. Note, section 0A02 is abbreviated a2, and so on.

   Possible submit directories for /group/submit/CS2630 are:

   mp1/a3
   mp1/a2
   mp1/a4
   mp1/b11
   mp1/b12
   mp1/b13

   Choice:   mp1/a2

The system will respond with a confirmation that your submission has been accepted (unless you made a mistake), and then it will return to the command-line prompt:

   * File/directory mp1.c has been 
   *  copied to /group/submit/CS2820/mp1/a2/mp1.c.HawkID.
   [HawkID@fastx?? ~]$

The confirmation message saying that the file has been copied tells you that the submission was successful. You may resubmit as many times as you want; each time you resubmit, your previous submission of that file will be replaced, so we will only see your final submission. The completed dialogue on your screen will look like this when you are done:

   [HawkID@fastx?? ~]$ submit mp1.c
   Course (for CS:1210 use CS1210): CS2630
   Possible submit directories for /group/submit/CS2630 are:
   
   mp1/a3
   mp1/a2
   mp1/a4
   mp1/b11
   mp1/b12
   mp1/b13

   Choice:   mp1/a2
   * File/directory mp1.c has been 
   *  copied to /group/submit/CS2820/mp1/a1/mp1.c.HawkID.
   [HawkID@fastx?? ~]$

The output saying "File ... has been copied ..." is your confirmation of successful submission. In the event of insurmountable trouble, do not delete or edit files you have submitted. Keep them around. It is safe to make copies if you want to keep playing with them. Keep the original on the CLAS Linux system until your graded work is returned. This way, the time stamp marking the time of last edit is a trustworthy indicator of whether you did the work on time.

Historically, students unable to successfully complete MP1 for this course have an extraordinarily low chance of success in the course. If this assignment proves daunting, seek help early.