C代写:CS104-WordCount

Requirement 1

Write a program called wcount.c that counts all the words in a given file

  1. Name your executable wcount.out
  2. The name of the file to count the words in will be passed on the command line
  3. For this problem we will define a word as a series of 1 or more non-whitespace
    characters

Use isspace to determine if a character is white space or not
Examples
Assume we have file named fun.txt that contains the following:

Computer sciences classes are great!
Even though I spend all my time doing request :(

1
2
../wcount fun.txt
There are 15 word(s).

Requirement 2

Write a program called perimeter.c that calculates the perimeter of a polygon.

  1. Name your executable perimeter.out
  2. The points of the polygon will be stored in a file and this file will be passed on the command line arguments
  3. The file itself will be a binary file containing integers
  4. The first integer in the file is the number of points contained in the file
  5. The remaining integers are the points, with the first integer being the x coordinate and the second integer being the y coordinate.
  6. There is an edge between each adjacent point and between the first point and the last point
  7. Each file contains at least 3 points
  8. The perimeter of a polygon is the sum of the lengths of all of its edges
    Use a double to store your perimeter and report the perimeter to the nearest 2 decimal points.
    You MUST store your points in a struct to receive credit for this problem.
    As an aside the example tests do not form actual polygons but assume that they do.

Example. Assume that there is a file called example.txt. It will store the following information but in binary form. This example is just to give you a visualization of the data.

Requirement 3

Write a program called tail.c that prints out the last N lines of a given file

  1. Name your executable tail.out
  2. Arguments to your program will be passed on the command line in the following order
  3. For an additional challenge try to solve the problem where there is no limit on the length of a line
  4. My solution to dealing with any length lines involved using the functions ftell and fseek.
  5. There is no limit to the number of lines in a file
  6. Some lines may only contain the newline character, these still count as a line
    1
    2
    3
    4
    ../tail.out meme.txt 10
    It
    is
    over 9000!!!
1
2
3
../tail.out meme.txt 2
is
over 9000!!!