首页
编程语言
数据库
网络开发
Algorithm算法
移动开发
系统相关
金融统计
人工智能
其他
首页
>
> 详细
讲解CP264留学生、辅导C/C++程序语言、讲解Qutaiba Albluwi、辅导C/C++ 讲解Python程序|辅导R语言编程
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:
,
,
,
and
.
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 (
): Could not open file
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
is
and the area is
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
is
and the area is
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:
联系我们
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-21:00
微信:codinghelp
热点文章
更多
辅导 comm2000 creating socia...
2026-01-08
讲解 isen1000 – introductio...
2026-01-08
讲解 cme213 radix sort讲解 c...
2026-01-08
辅导 csc370 database讲解 迭代
2026-01-08
讲解 ca2401 a list of colleg...
2026-01-08
讲解 nfe2140 midi scale play...
2026-01-08
讲解 ca2401 the universal li...
2026-01-08
辅导 engg7302 advanced compu...
2026-01-08
辅导 comp331/557 – class te...
2026-01-08
讲解 soft2412 comp9412 exam辅...
2026-01-08
讲解 scenario # 1 honesty讲解...
2026-01-08
讲解 002499 accounting infor...
2026-01-08
讲解 comp9313 2021t3 project...
2026-01-08
讲解 stat1201 analysis of sc...
2026-01-08
辅导 stat5611: statistical m...
2026-01-08
辅导 mth2010-mth2015 - multi...
2026-01-08
辅导 eeet2387 switched mode ...
2026-01-08
讲解 an online payment servi...
2026-01-08
讲解 textfilter辅导 r语言
2026-01-08
讲解 rutgers ece 434 linux o...
2026-01-08
热点标签
mktg2509
csci 2600
38170
lng302
csse3010
phas3226
77938
arch1162
engn4536/engn6536
acx5903
comp151101
phl245
cse12
comp9312
stat3016/6016
phas0038
comp2140
6qqmb312
xjco3011
rest0005
ematm0051
5qqmn219
lubs5062m
eee8155
cege0100
eap033
artd1109
mat246
etc3430
ecmm462
mis102
inft6800
ddes9903
comp6521
comp9517
comp3331/9331
comp4337
comp6008
comp9414
bu.231.790.81
man00150m
csb352h
math1041
eengm4100
isys1002
08
6057cem
mktg3504
mthm036
mtrx1701
mth3241
eeee3086
cmp-7038b
cmp-7000a
ints4010
econ2151
infs5710
fins5516
fin3309
fins5510
gsoe9340
math2007
math2036
soee5010
mark3088
infs3605
elec9714
comp2271
ma214
comp2211
infs3604
600426
sit254
acct3091
bbt405
msin0116
com107/com113
mark5826
sit120
comp9021
eco2101
eeen40700
cs253
ece3114
ecmm447
chns3000
math377
itd102
comp9444
comp(2041|9044)
econ0060
econ7230
mgt001371
ecs-323
cs6250
mgdi60012
mdia2012
comm221001
comm5000
ma1008
engl642
econ241
com333
math367
mis201
nbs-7041x
meek16104
econ2003
comm1190
mbas902
comp-1027
dpst1091
comp7315
eppd1033
m06
ee3025
msci231
bb113/bbs1063
fc709
comp3425
comp9417
econ42915
cb9101
math1102e
chme0017
fc307
mkt60104
5522usst
litr1-uc6201.200
ee1102
cosc2803
math39512
omp9727
int2067/int5051
bsb151
mgt253
fc021
babs2202
mis2002s
phya21
18-213
cege0012
mdia1002
math38032
mech5125
07
cisc102
mgx3110
cs240
11175
fin3020s
eco3420
ictten622
comp9727
cpt111
de114102d
mgm320h5s
bafi1019
math21112
efim20036
mn-3503
fins5568
110.807
bcpm000028
info6030
bma0092
bcpm0054
math20212
ce335
cs365
cenv6141
ftec5580
math2010
ec3450
comm1170
ecmt1010
csci-ua.0480-003
econ12-200
ib3960
ectb60h3f
cs247—assignment
tk3163
ics3u
ib3j80
comp20008
comp9334
eppd1063
acct2343
cct109
isys1055/3412
math350-real
math2014
eec180
stat141b
econ2101
msinm014/msing014/msing014b
fit2004
comp643
bu1002
cm2030
联系我们
- QQ: 99515681 微信:codinghelp
© 2024
www.7daixie.com
站长地图
程序辅导网!