代做CP264留学生作业、代写C/C++程序语言作业、代做Qutaiba Albluwi作业、代写C/C++实验作业

代做CP264留学生作业、代写C/C++程序语言作业、代做Qutaiba Albluwi作业、代写C/C++实验作业
CP264 Fall 2018 A4: Files
Qutaiba Albluwi 2018
A4: C Files
Due Date: Monday, October 15th, 2018 at 11:55 pm.
Instructions:
1- Download the file: “cp264_fall2018_A4_template.zip”
2- Extract the above archived file, and you should find the following six files:
1) “main.c”
2) “files.h”
3) “chistory.txt”
4) “cIntro.txt”
5) “Ontario.txt”
6) “Quebec.txt”
3- Create a C project in eclipse with the following suggested name: “cp264_ A4”
4- Copy (or import) the above files into the project
5- Create a file called: “files.c” file and Insert the following comment on top of the file:
/**
* ---------------------------
* CP264: Fall 2018
* Student Name:
* Student ID (9 digits):
* Assignment 4 (A4: Files)
* ---------------------------
*/
6- Create a folder called: “output” (should be in the same level to where the above files were
placed. This folder will contain the output files that would be generated by your solution.
7- You should not edit any file except “files.c” or the “main.c” function in order to make
the proper testing call.
8- You can only import the following standard libraries: <stdio.h>, <stdlib.h>, <math.h>,
<ctype.h> and <string.h>.
9- Testing functions are provided for you. You need to produce outputs that EXACTLY match
the given output.
Submission Instructions:
Submit ONLY one .c file, which is you’re your “files.c”. Remember to have your name and ID
listed on the top comment.
Each of the following violations will result in a 2 points penalty:
1- Forgetting to complete the top comment with your name and ID
2- Submitting the wrong file format (any file other than files.c) or submitting more than one file
3- Including a library other than the five standard libraries defined above.
4- Failing to compile for any syntax error. If the error takes time to fix, the submission is
rejected. If you decide not to implement a function, then create the function with a simple
print statement like: “I could not implement this function”. If you have done some coding
but you have bugs that you were unable to correct, then comment your code and print a
statement describing what you have done and where was your issue.
CP264 Fall 2018 A4: Files
Qutaiba Albluwi 2018
5- Having more than one eclipse warning. (Just ensure that your code does not generate
warnings).
6- If any of your functions change or update the original input files
7- If any of the testing functions is tampered with.
General Comments:
You may assume that the length of any line in the input files will not exceed MAX, which is 200. This
applies to the other tasks too.
You need to perform error checking for every file that you try to access. If accessing the file fails,
then your program should print the following error statement:
"Error (<functionName>): Could not open file <filename> for reading.\n”
Task1: Analyzing a file
Create the following function:
void analyzeFile(char* filename)
The function inspects the contents of a given file and analyze it to get the following information:
- Number of paragraphs
- Number of lines
- Number of words
- Number of alphabetical characters
- Number of numerical characters
- Number of non-alphanumerical characters.
In order to find the number of paragraphs, the function should look for an empty line that separates
two portions of text.
For the number of lines, the function should count both the empty and non-empty lines.
For the number of words, the function should look for any two strings that separated by a space
character.
For the number of alphabetical characters, the function should count the number of alphabets from
a to z, both upper and lower case.
For the numerical characters, the function should count the number of characters denoting a
numerical value, i.e. 0,1,2,3,4,5,6,7,8 and 9.
The non-alphanumerical characters are defined as any character that is not alpha or numerical. This
includes punctuations and special symbols, but excludes the space and new line characters.
The function should print the above statistical findings using the format given below.
To test your function execute the command test_analyzeFile( ) in the main function. Your output
should look like the following:
CP264 Fall 2018 A4: Files
Qutaiba Albluwi ? 2018
Task2: Formatting a File I
Create the following function:
void format1(char* fileName1, char* fileName2)
The first input string represent the name of the input file, while the second input string represent
the output file. The function returns void.
The function reads the contents of the first file, format it and produce the output onto the second
file. The following two formats are performed:
1- The paragraph structure is removed. This means, there should not be any empty line
between the lines of texts
2- Every four words should appear in a separate line.
Formatting the file “cIntro.txt” and “chistory.txt” should produce the output depicted below.
The two files should be generated if the command test_format1( ) in the main function is executed.
Remember, your output files will show up in the folder: “output”.
You can notice that each line has a variable length, but has exactly four words. Also, the punctuations
are preserved, while there are no empty lines in the whole file.
CP264 Fall 2018 A4: Files
Qutaiba Albluwi ? 2018
Task3: Formatting a file II:
Create the following function:
void format2(char* fileName1, char* fileName2)
The first input string represent the name of the input file, while the second input string represent
the output file. The function returns void.
The function reads the contents of the first file, format it and produce the output onto the second
file. The following two formats are performed:
1- All non-alphanumerical characters are deleted (except the space and newline characters).
2- The first word of every line is capitalized
3- Every line should end with a period.
Formatting the file “cIntro.txt” and “chistory.txt” should produce an output similar to the
screenshots shown below.
Note how the paragraph structure is preserved. Notice also how the beginning of each line is an
upper case character and the line ends with a period.
Finally, you can observe an extra newline at the end of two output files. You may choose to add or
remove that extra line.
CP264 Fall 2018 A4: Files
Qutaiba Albluwi ? 2018
Task4: Extracting Data from Files:
The two input files: “Ontario.txt” and “Quebec.txt” contain information on the population and area
of the major cities in the above two provinces.
Each line is formatted as the following:
Population of <cityName> is <population> and the area is <area>
The first line in the file represent information on the province. Below is the contents of the file:
“Ontario.txt”:
Note how the values are separated by the thousands comma, and the population is an integer while
the area is float.
Write the following function:
void getCityDetails(char* fileName1, char* city, char* logFile);
CP264 Fall 2018 A4: Files
Qutaiba Albluwi ? 2018
The first input string represent the name of the input file, the second is a city name and the last is
file name which will store the output.
The function searches for the record that matches the given city, and then print the province name,
population and area. For instance, if the city: “Toronto” is passed as an input parameter, then the
output should be:
Searching for Toronto in "ontario.txt":
Province = Ontario
Population = 2,731,571
Area = 630.20
If the city is not found, then an error message should be printed. For instance, searching for
“Sherbrooke” in “Ontario.txt” should return:
Searching for Sherbrooke in "ontario.txt":
Could not find Sherbrooke in "ontario.txt"
The above outputs should not be printed into the console. Instead, they should be channeled to the
given log file. The outputs should be appended, not over-writing the previous data.
Running the command test_getCityDetails( ) in the main function should produce the following
contents in the “cityDetails.txt” file:
Note that since you will be using the “append” mode, when testing your function several times, the
output will keep accumulating. Therefore, you would need to delete the file, whenever you need to
conduct another test.
Task5: Editing a File:
Create the following function:
void replaceIs(char* fileName, char* newStr)
The first input string represent the name of the input file, while the second represent a string to
replace the string “is”.
CP264 Fall 2018 A4: Files
Qutaiba Albluwi ? 2018
The function reads a given file, and replaces every “is” with the given string.
In this task, we assume that a file formatted similar to “Ontario.txt” and “Quebec.txt” files will be
used. This means that we know that each line is formatted as the following:
Population of <cityName> is <population> and the area is <area>
You can assume that the given newStr is going to always contain only two characters, e.g. “==”.
In order to achieve the above, you need to use the fseek command. The command should be used
twice as the string “is” is repeated twice in each line. It is up to you to use any suitable computation
to find the position of both “is” in each line.
Note that for the purposes of this task, we are not looking for any ‘i’ that is followed by an ‘s’. Instead
we are looking for an “is” which is preceded by a space and proceeded by a space character.
Since, this function changes the contents of the files, the test function creates a copy of “Ontario.txt”
and “Quebec.txt” under the names of “ontario2.txt” and “Quebec2.txt”. A new version is created,
every time the test function is called. This ensures that the original files are not corrupted during
your testing.
Running the testing function would produce the following:

http://www.daixie0.com/contents/13/1876.html

因为专业,所以值得信赖。如有需要,请加QQ99515681 或邮箱:[email protected] 

微信:codinghelp

猜你喜欢

转载自www.cnblogs.com/helpingmips/p/9826198.html