All these questions are to be answered using the CSIF systems. If you use some other system, your answers may differ, and we will grade based on the CSIF systems.
Please do either of the two questions. You must pick one; you cannot do part of one and part of the other. In your submission, state which one you have done.
The interface of your program must look exactly like this (your input is in bold; what the computer types is in normal font):
Starting point: 5
Ending point: 30
Increment: 5
5 10 15 20 25 30
As another example:
Starting point: 5
Ending point: 12
Increment: 2
5 7 9 11
There is to be one space between each number, and no space trailing the final number in the output.
Errors arise when the starting point is less than the ending point and the increment is non-positive, or when the starting point is greater than the ending point and the increment is non-negative. In these cases, the error messages that you output must look exactly like this:
Increment must be > 0 if begin < endand
Increment must be < 0 if begin > endThey also must be written on the standard error. To do so, replace the printf you would normally write with the appropriate one of these:
fprintf(stderr, "Increment must be > 0 if begin < end\n");and
fprintf(stderr, "Increment must be < 0 if begin > end\n");
The program you write must be stored in a file called “iota.c”.
The relevant characters, and the C escape sequences to be printed when those characters are encountered, are:
character | print as | character | print as | |
---|---|---|---|---|
newline (^J) | \n | horizontal tab (^I) | \t | |
vertical tab (^K) | \v | backspace (^H) | \b | |
carriage return (^M) | \r | form feed (^L) | \f | |
bell (^G) | \a | NUL (^@) | \0 | |
backslash | \\ | anything else | \xxx |
Unfortunately, the program as saved in vis.c will not even compile, let alone run. And the programmer thoughtlessly left off all the comments. Hence, your mission: comment the program, and fix it so it works as described above! You are to turn in a corrected source program, with comments describing the changes you made to get it to work.
As an example of how to do this, let’s say the program contains the following:
x = 8;The error is clearly in the condition of the if statement, as that assigns 9 to x (and does not compare 9 to x), and so always evaluates to true. Here's the sort of comment we want:
...
if (x = 9)
printf("x is 9\n");
else
printf("x is %d\n", x);
x = 8;Note the comment says what the change was, and why it was made.
...
/*
* original line was:
* x = 9
* changed from an assignment to a test
* because the if statement meant to test
* the value of x, not change it
*/
if (x == 9)
printf("x is 9\n");
else
printf("x is %d\n", x);
You can also obtain a PDF version of this. | Version of October 8, 2015 at 12:13AM |