C代写:CS104 Word Count

Introduction

很基础的C程序,实现统计输入文件中的单词总数,此外还需要写一个计算多边形的小程序,以及一个打印行尾的小程序。

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

  1. 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 homework :(

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
    The first integer in the file is the number of points contained in the file
    The remaining integers are the points, with the first integer being the x coordinate and the second integer being the y coordinate.
    There is an edge between each adjacent point and between the first point and the last point
    Each file contains at least 3 points
  4. The perimeter of a polygon is the sum of the lengths of all of its edges
  5. Use a double to store your perimeter and report the perimeter to the nearest 2 decimal points.
  6. You MUST store your points in a struct to receive credit for this problem.
  7. 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.

3
287 422
283 -981
781 647

1
2
./perimeter example.txt
The perimeter is 3648.30

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
    Name of the file
    N
  3. N will always be at least 1
  4. If N is greater than the number of lines in the file, all of the lines in the file should be displayed
  5. You may assume that no line is longer than 100 characters
    For an additional challenge try to solve the problem where there is no limit on the length of a line
    My solution to dealing with any length lines involved using the functions ftell and fseek.
  6. There is no limit to the number of lines in a file
  7. Some lines may only contain the newline character, these still count as a line
  8. My editor automatically added 1 newline character to the end of most of the test files but does not display them. Your editor may or may not display them but do be aware that they are there.

Example. Assume the file meme.txt contains the following

It
is
over 9000!!!

1
2
../tail.out meme.txt 1
over 9000!!!
1
2
3
../tail.out meme.txt 2
is
over 9000!!!
1
2
3
4
../tail.out meme.txt 10
It
is
over 9000!!!