Docsity

Assignment 6: Computing Average Word Length in a Text File - Prof. Kristen Miller, Assignments of Computer Science

Toggle sidebar
bg1
CS 010 – Intro to Computer Science Fall - 2003
Assignment 6 – due by 10 p.m. Wednesday 11/19
Average Word Length
Due by 10 p.m. on Wednesday 11/19, by electronic turn-in
You MUST submit your work to the as6 folder corresponding to your lab class, or it will NOT be graded (e.g. if you
are in lab class 023, you must submit your work to the folder as6_023). Remember to include your name, SID or
SSN (last 4 digits), lecture & lab section numbers, lab login id, & ucr email address in the header of the file you
submit (write them as comments).
Write a program that will compute the average word length (average number of characters per word) for
a file that contains some text. A word is defined to be any string of symbols that is preceded and
followed by one of the following at each end: a blank, a comma, a period, the beginning of a line, or the
end of a line. Your program should define a function that is called with the input-file stream as an
argument.
Use the name “textfile.txt” as your input file or allow the user to enter their own file name.
Given this example input file:
You’re program should output:
Average word length: 3.5 characters
I’m trying to free your mind,
Neo. But I can only show you
the door. You're the one who
has to walk through it.
textfile.txt

Partial preview of the text

Download Assignment 6: Computing Average Word Length in a Text File - Prof. Kristen Miller and more Assignments Computer Science in PDF only on Docsity!

CS 010 – Intro to Computer Science Fall - 2003

Assignment 6 – due by 10 p.m. Wednesday 11/

Average Word Length Due by 10 p.m. on Wednesday 11/19, by electronic turn-in You MUST submit your work to the as6 folder corresponding to your lab class, or it will NOT be graded (e.g. if you are in lab class 023, you must submit your work to the folder as6_023). Remember to include your name, SID or SSN (last 4 digits), lecture & lab section numbers, lab login id, & ucr email address in the header of the file you submit (write them as comments). Write a program that will compute the average word length (average number of characters per word) for a file that contains some text. A word is defined to be any string of symbols that is preceded and followed by one of the following at each end: a blank, a comma, a period, the beginning of a line, or the end of a line. Your program should define a function that is called with the input-file stream as an argument. Use the name “textfile.txt” as your input file or allow the user to enter their own file name. Given this example input file: You’re program should output: Average word length: 3.5 characters I’m trying to free your mind, Neo. But I can only show you the door. You're the one who has to walk through it. textfile.txt