Project description • It will have to read data from its input until the end of the input is seen. It will need to
c/c++代写,java代写,python代写,matlab代写,作业代写,留学生作业代写
1 2 Project description • It will have to read data from its input until the end of the input is seen. It will need to do this one line at a time, because it will need to count the characters in each line. A line is just an abstraction; it is a sequence of zero or more characters followed by the special newline character, so your program must look for a newline to determine where a line that it is reading ends. • It will need to print the characters in each line that was read, but before that it will have to store the characters of each line into a one–dimensional array as they are being read. The program can’t just print the characters as they are read, because before each line is printed an indication has to be displayed if the line is too long (i.e., if it has more than 80 characters). Consequently, an entire line must be read so its length can first be determined, then it is printed. Note that its terminating newline indicates where an input line ends, but it is not part of the line’s contents, so it does not count towards its length. Each line’s length can be determined either during the process of reading it, or after it has been read. • The first thing printed on each output line, in the first column or character position, must either be a single blank space character if the current line that was just read is 80 characters or less, or a single asterisk () if the line read is longer than 80 characters. • The next thing printed on each output line must be the number of the current line (the first line read is line #1). Your program’s input will never contain more than 2 99999 lines, so the line number should be printed in a field of exactly 5 places, padded on the left with blank spaces if it is less than 5 digits. (Note that this formatting can trivially be performed in C with the right printf() formatting options, explained in a recent discussion section.) • Following the line number a colon should be printed, followed by a single blank space, then the characters of the line that was read, followed by a newline. The actual input line as printed will always begin in the ninth column or output position, because the space or asterisk, line number, colon, and following space all occupy the first eight positions. • An additional line of output is to be printed only for input lines longer than 80 characters. Immediately following the line a second line must be printed, having exactly 88 blank spaces, then enough caret characters (^) so there is a caret underneath each position of the line that is beyond the 80th position. See the example below. (88 blank spaces includes 80 for the characters of the line that are within the first 80 positions, plus as mentioned 8 for the asterisk or space, line number, colon, and space.) Note that the input to your program could be anything – it doesn’t even have to be a C program. But if you run it reading its own code, it will tell you whether it has any lines longer than 80 characters, which you would definitely lose credit for during grading. Here is an example of the output that should be produced for a single input line that is exactly 85 characters long, with blank spaces shown as ␣: ␣␣␣␣1:␣This␣is␣a␣line␣with␣85␣characters.␣␣(Words␣were␣chosen␣carefully␣to␣have␣exactly␣85.) ␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣^^^^^ 3 2.1 Tab characters As described above the program is straightforward, although you may encounter a few issues due to differences between C and Java that this project is intended to bring up. But a slightly tricky issue is the effect of any tab characters in the input. When we said that program lines longer than 80 characters should be indicated we were really referring to how they would appear on the screen or printer, not how many characters they actually contain, because a tab character appears to occupy anywhere between 1 and 8 positions. Output devices act as if there was an invisible tab stop at every eighth character position (the eighth position, sixteenth, etc.) The effect of printing a tab character is to cause output to skip just past the next tab position. (Consequently, a character in the input immediately following a tab will appear right after the next tab position.) Because your program has to determine how long each input line would appear when displayed, tabs in its input have to be counted as the equivalent of however many spaces would be necessary to skip over to the next tab stop, given the contents of the line before the tab character (which may itself contain tabs). For example: • If an input line contained the three characters cat followed by a tab character and then bat, it would appear to be 11 characters when printed, even though there are actually only seven real characters in the line. cat would obviously be printed in the first three positions of the output device, then the tab character would cause the rest of the output to begin at the ninth position, so bat would be in the ninth through eleventh positions. In this case we will refer to 11 as the size of the line. 4 • If a line contained hi followed by a tab followed by 216 followed by another tab and then bye, its size would be 19 – hi is two characters, the tab advances to the next tab stop so it would appear as if it were six characters, 216 is three characters, the next tab would appear as if it were five characters, and bye is three characters. • And if a line contained two consecutive tab characters followed by the characters hamster, the first tab would advance to the eighth position and the second tab would advance to the sixteenth position, so the h would be at the seventeenth position, the a at the eighteenth, etc., and its size is 23. Size is only different from the actual number of characters in a line when the line contains tabs. A tab character always appears as if it occupies at least one space. Suppose a line had eight characters, a tab, and a Z. After the first eight characters are printed the output device will be at the ninth position, but the Z cannot appear there, because if it did the tab would not be visible at all. Instead the tab causes printing to advance eight spaces, and the Z would be at the seventeenth position. For lines with size longer than 80, consecutive caret characters should be printed from the 81st position up through the line’s size. For example, if a line had 80 Xs followed by two tabs its effective length would be 96, so 88 spaces then 16 carets would be printed on the line underneath it. Note lastly that although a tab character may appear to occupy multiple spaces in an output line, your program should print the characters of lines exactly as they were read from the input, so any tab characters should be printed as tabs. Do not replace them by spaces. (We could have said to replace tabs by spaces, but it would involve some complexities that are not immediately apparent; in any event, the submit server is expecting all tabs to be printed as tabs in order to say that your output is correct.) 2.2 5 • Notes, constraints, and allowable language features You are guaranteed that every line in your program’s input, even the last one, will always end with a newline character. When you create input data files of your own with Emacs to test your program with, be sure to press return at the end of the last line you type, so they will also end in a newline. Our input data may contain any printable characters appearing on a standard US keyboard, but for simplicity we will avoid nonprintable or whitespace characters other than tabs and newlines. Any line in the input may have more than than 80 characters, but you may assume there will be no more than 1000 characters (any of which may be tabs) prior to the terminating newline character of any line. As above, there will be no more than 99999 lines in the program’s input. Since there can be up to 99999 lines in your program’s input, it would use a lot of memory to try to read the entire input in at once. (In fact, your program may crash if you do that, due to using too much memory.) Just read and process one line (up until its trailing newline) at a time. All of your code must be in the single file linecheck.c. Do not create any new source or header files for the project. You must implement this project using only the features of C that have been covered so far in class this semester. We want you to practice using these features before going on to new ones. The project can probably be written more easily using features we haven’t covered yet, but one purpose of the project is to get experience with some of the differences between Java and C that the project will illustrate if written as specified. In particular: – The only library header file your program can include is stdio.h, – The only C library functions your program can call are printf(), scanf(), and feof(), 6 – The only format specifiers that your program can use are the ones covered so far in class (%d, %c, %f, %o, %u, and %x), – Even if you know something about using strings in C already, do not attempt to use strings in C (which also have not been covered), and – Even though Chapter 1 in the Reek text uses various C features that have not been covered in class yet, you may not use them if they were not also covered in class. You will lose significant credit when your project is graded if you use C features that weren’t covered yet. The project can be written in a small number of lines of code using just features covered so far.
留学生作业代写,cs作业代写,cs代写,作业代写,北美cs作业代写,澳洲cs作业代写,加拿大cs作业代写,cs作业代写价格,靠谱cs作业代写,程序代写