Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

NEED HELP PLEASE!! 2 Project description As mentioned above, the project style guide handout describes what good programming style consists of for projects in this

NEED HELP PLEASE!!

2 Project description

As mentioned above, the project style guide handout describes what good programming style consists of for projects in this course. A significant part of your grade for this project will be based on your style. One aspect of style the handout describes is that none of your program lines should exceed the standard terminal or printer width of 80 characters. Although you could visually check the length of your program lines, having a program to determine this for you would be much more convenient. You will write that program in this project. To avoid losing credit for style you should run it on itself and on your code in all future projects as well.

In most projects in this course you will write functions that we will call from our main programs (our tests of your code), as in Project #1. This project is an exception you will write a standalone program for it. Actually, you will write two different standalone programs, warnlines.c and summary.c, which could be used separately or together.

2.1 The line length check program warnlines.c

As mentioned, this program will check for lines that are more than 80 characters. First, here are concepts and terminol- ogy involved. A line is a sequence of zero or more characters terminated with the special newline character. The size of a line refers to the number of characters in the line. The newline character indicates where the line ends, but it is not part of the lines contents, so it does not count towards its size. The length of a line refers to the number of spaces the line occupies when printed. If a line has no tab characters its length equals its size. The length of a line that contains tab characters is defined in Section 2.2 below.

Your warnlines.c program needs to do the following: Read one input line at a time and process it as described next. As each line is being read, store the characters of

the line into a onedimensional array that is large enough to store just one input line, then process that one line. Determine the length of the line, either during or after reading the line. For the line that was just read, print the following on one output line (with no additional spaces):

  • In the first column or character position print either a single blank space character if the length of the current line that was just read was 80 or less, or a single asterisk (*) if the lines length was more than 80.

  • Thenprintthenumberofthecurrentline,wherethefirstlinereadisline#1.Yourprogramsinputwillnever contain more than 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 it is trivial to do this in C using printf() formatting options that were explained in a recent discussion section.

  • Then print a colon, a single blank space, all of the characters of the line that was read, and a newline. 2021 L. Herman; all rights reserved 1

good programming style is considered to consist of for projects. Also carefully read the constraints in

(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 occupy the first eight positions.)

  • An additional line of output is to be printed only for input lines whose length is longer than 80. Immediately following the line that was read and printed, a second line must be printed that has exactly 88 blank spaces, then enough caret characters (^) so there is a caret underneath each character 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.)

  • Do this for all lines in the input, until the end of the input is reached.

    Your programs input could be anything it doesnt 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 lose credit for during grading. Here is an example of the output that should be produced for a single input line exactly 85 characters long, with blank spaces shown as . The public test outputs (discussed below) have more examples of the expected output format.

    *1:Thisisalinewith85characters.(Wordswerechosencarefullytohaveexactly85.) ^^^^^

    Note that lines cant just be printed as they are being read, because before a line that is too long is printed an asterisk has to be printed. So an entire line must be read so its length can first be determined, only then can it be printed.

2.2 Tab characters

As described above the program is straightforward, although you may encounter a few issues due to differences between C and Java that the project is intended to bring up. But tab characters make it slightly tricky, because a tab character occupies anywhere between 1 and 8 spaces when printed. Output devices act as if there is an invisible tab stop at every eighth character position (the eighth position, sixteenth, etc.) Printing a tab character causes the output to skip at least one space and stop just past the next tab position. A printable character immediately after the tab will appear at that position. The length of a line that has one or more tabs is the number of spaces the line would occupy when printed each tab would contribute between 1 to 8 spaces to the length, but only 1 to the size. Some examples:

  • Thesizeofthelinefat\tcat(where\tistheescapesequenceindicatingatabcharacter)is7butitslengthis11. When printed, fat occupies the first three positions and the tab character causes cat to begin at the ninth position and occupy the ninth through eleventh positions.

  • The length of the line hi\tgood\tbye is 19: hi occupies two positions, the tab advances to the next tab stop so it occupies six positions, good is four positions, the next tab occupies four positions, and bye occupies three positions.

  • The length of \t\toctopus is 23. The first tab advances to the eighth position, the second tab advances to the sixteenth position, and the o would be at the seventeenth position, the c at the eighteenth, etc.

  • A tab character always appears as if it occupies at least one space. Suppose a line has hedgehog\tZ. After hedgehog is 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 so the Z would be at the seventeenth position, and the lines length is 17.

    Note that although a tab character may appear to occupy multiple spaces in an output line, your program must print characters exactly as they were read from the input, so any tabs must be printed as tabs. Do not print spaces instead of tabs. (We could have said to do this but it would have involved some complexities that are not immediately apparent; in any event, the submit server is expecting all tabs to be printed as tabs to say that your output is correct.)

2.3 The summary program summary.c

The line length check program described above can give a user full information about which of their program lines are too long, and by how much. Sometimes though a user might want to see just a summary view of only the numbers of the lines that are too long, without any of the other information produced by the first program. You will also write a second program that reads the output of your first program and prints just the numbers of the lines that are too long (if any).

2021 L. Herman; all rights reserved 2

In particular, this program should read the output produced by the warnlines.c program and print only the numbers of the lines in the input of warnlines.c that were longer than 80 characters, in increasing line number order obviously. If one or more lines in the input of warnlines.c were longer than 80 characters this program should print all their numbers, on a single output line, ending in a newline. If more than one line number is printed they should be separated by a single blank space character, but there should not be any space at the beginning of the line before the first line number or any space after the last line number printed. If there were no lines that were longer than 80 characters this program will only print a newline (it always prints at least a newline).

Note that this program will print the numbers of the lines in the input of warnlines.c that were longer than 80 characters. warnlines.c can print more lines of output than the number of lines in its input because it prints a pair of lines for every input line that is longer than 80 characters, with the second one having spaces and caret characters; these caret lines will be ignored by summary.c.

Here is an outline of what summary.c should do:

  • It must read a single character, which will be the first character on a line. Since it is reading output produced by

    warnlines.c this character will either be an asterisk or a space.

  • Ifthecharacterreadwasaspacethenthisisalinethatwasnotlongerthan80characterswhenreadbywarnlines.c,

    so in this case summary.c must just skip the entire rest of the line whose first character was just read. To do this it should read characters (one at a time) until it sees a newline, then read the first character on the next

    line (if there is a next line), which will again be an asterisk or a space, and begin the process again.

  • If on the other hand the first character that summary.c read on a line was an asterisk, this means that the rest of

    the line was longer than 80 characters when read by warnlines.c.

    In this case summary.c must read a number after the character which will be the number of the line in the input ofwarnlines.c that was too long and print the number. Then it must skip the rest of the line, including its newline, just as in the case above, and also skip the entire next line (and its newline), which will be one containing carets. Then it ill read the first character on the next line (if there is a next line) and begin the process again.

    This outline omits details such as properly handling spaces between printed numbers. The last public test illustrates the results produced by summary.c when there is a line in the input of warnlines.c that was too long.

    summary.c is designed to read the output of your warnlines.c program. summary.c can be run on any other input such as an input data file as long as the file contents follow the output format produced by warnlines.c. If summary.c is run on input that does not follow the output format of warnlines.c then it can produce incorrect results, or crash, or have an infinite loop. (summary.c is only expected to work right on input of the proper format, and there is no expected behavior if its input does not follow that format.)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems X Special Issue On Database And Expert Systems Applications Lncs 8220

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Stephen W. Liddle ,Klaus-Dieter Schewe ,Xiaofang Zhou

2013th Edition

3642412203, 978-3642412202

More Books

Students also viewed these Databases questions

Question

How does a Denial of Service ( DoS ) attack work?

Answered: 1 week ago