CPTR-141 HW # 20 Due Friday Definition As Handed Out: Write A

Total Page:16

File Type:pdf, Size:1020Kb

CPTR-141 HW # 20 Due Friday Definition As Handed Out: Write A CPTR-141 HW # 20 due Friday Definition as handed out: Write a program that prompts the user to input the name of a text file and then outputs the number of words in the file. You can consider a “word” to be any text that is surrounded by whitespace (for example, a space, carriage return, newline) or boarders the beginning or end of the file. For testing you can use the data.txt and hw19.txt files that are on the class web page. Before jumping into writing code, write a pseudo-code outline of the logic for this program. Then do the coding. Statement made during class: Turn in your pseudo-code outline in addition to the hardcopy of your program. Upload the source file to D2L. Additional comments, information, and modification of the problem statement The initial problem statement is interesting but leaves some unanswered questions such as “what is a word”? Does a single punctuation character surrounded by spaces count as a word? How about a string of punctuation characters with a blank before or after? How about a number which could be a single digit or multiple digits? If the simplistic way is taken, meaning that words are identified only by finding white space (i.e. when isspace returns true), you end up counting isolated punctuation characters or sequences as words. I think you can do better. First a bit more information. The isspace function returns true for these characters: space (i.e. blank), newline, carriage return, tab, vertical tab, or form feed. It returns false for punctuation characters. Both the isalpha and isdigit functions return false for punctuation characters. Thus it is possible to distinguish between punctuation and alphanumeric characters. THEREFORE by definition for this assignment: a) a single punctuation mark with one or more spaces before or after it is not a word. b) a string of punctuation marks with one or more spaces before or after it is not a word. c) a single numeric character or sequence of numeric only characters with one or more spaces before or after it is not a word. d) a sequence of mixed alpha and numeric characters, such as Base16, will be considered a word. e) a sequence of mixed alpha and numeric and punctuation, such as instream.get, would be considered a word. Two levels of success for this homework The minimum, passing, homework will count punctuation and numeric characters as words or part of words. Higher level success will implement the a to d definitions above. Ideas for keeping track of when/or if a word has been found In programming there is the concept of a flag. A flag is a variable that you place a value in to represent some condition or the presence/absence of some condition. Sometimes a flag is a variable of type bool in which case the variable would have true or false in it. For example in the context of the current problem, assume you have a flag named WordStart of type bool and that alpha and numeric characters can be found together in a word. As you start reading characters from the file you would test for alpha characters and numeric characters and if the current character is either then put true in the WordStart variable. Then you would read additional characters until you find a whitespace character. When you find a white space character, if WordStart flag is true you know that you just ended a word, not just a space, a word has been found and you would increment the word count and put false in WordStart. The flag is how the program “remembers” what came before the current statement or operation in a program..
Recommended publications
  • Bbedit 13.5 User Manual
    User Manual BBEdit™ Professional Code and Text Editor for the Macintosh Bare Bones Software, Inc. ™ BBEdit 13.5 Product Design Jim Correia, Rich Siegel, Steve Kalkwarf, Patrick Woolsey Product Engineering Jim Correia, Seth Dillingham, Matt Henderson, Jon Hueras, Steve Kalkwarf, Rich Siegel, Steve Sisak Engineers Emeritus Chris Borton, Tom Emerson, Pete Gontier, Jamie McCarthy, John Norstad, Jon Pugh, Mark Romano, Eric Slosser, Rob Vaterlaus Documentation Fritz Anderson, Philip Borenstein, Stephen Chernicoff, John Gruber, Jeff Mattson, Jerry Kindall, Caroline Rose, Allan Rouselle, Rich Siegel, Vicky Wong, Patrick Woolsey Additional Engineering Polaschek Computing Icon Design Bryan Bell Factory Color Schemes Luke Andrews Additional Color Schemes Toothpaste by Cat Noon, and Xcode Dark by Andrew Carter. Used by permission. Additional Icons By icons8. Used under license Additional Artwork By Jonathan Hunt PHP keyword lists Contributed by Ted Stresen-Reuter. Previous versions by Carsten Blüm Published by: Bare Bones Software, Inc. 73 Princeton Street, Suite 206 North Chelmsford, MA 01863 USA (978) 251-0500 main (978) 251-0525 fax https://www.barebones.com/ Sales & customer service: [email protected] Technical support: [email protected] BBEdit and the BBEdit User Manual are copyright ©1992-2020 Bare Bones Software, Inc. All rights reserved. Produced/published in USA. Copyrights, Licenses & Trademarks cmark ©2014 by John MacFarlane. Used under license; part of the CommonMark project LibNcFTP Used under license from and copyright © 1996-2010 Mike Gleason & NcFTP Software Exuberant ctags ©1996-2004 Darren Hiebert (source code here) PCRE2 Library Written by Philip Hazel and Zoltán Herczeg ©1997-2018 University of Cambridge, England Info-ZIP Library ©1990-2009 Info-ZIP.
    [Show full text]
  • DFDL WG Stephen M Hanson, IBM [email protected] September 2014
    GFD-P-R.207 (OBSOLETED by GFD-P-R.240) Michael J Beckerle, Tresys Technology OGF DFDL WG Stephen M Hanson, IBM [email protected] September 2014 Data Format Description Language (DFDL) v1.0 Specification Status of This Document Grid Final Draft (GFD) Obsoletes This document obsoletes GFD-P-R.174 dated January 2011 [OBSOLETE_DFDL]. Copyright Notice Copyright © Global Grid Forum (2004-2006). Some Rights Reserved. Distribution is unlimited. Copyright © Open Grid Forum (2006-2014). Some Rights Reserved. Distribution is unlimited Abstract This document is OBSOLETE. It is superceded by GFD-P-R.240. This document provides a definition of a standard Data Format Description Language (DFDL). This language allows description of text, dense binary, and legacy data formats in a vendor- neutral declarative manner. DFDL is an extension to the XML Schema Description Language (XSDL). GFD-P-R.207 (OBSOLETED by GFD-P-R.240) September 2014 Contents Data Format Description Language (DFDL) v1.0 Specification ...................................................... 1 1. Introduction ............................................................................................................................... 9 1.1 Why is DFDL Needed? ................................................................................................... 10 1.2 What is DFDL? ................................................................................................................ 10 Simple Example ......................................................................................................
    [Show full text]
  • Notetab User Manual
    NoteTab User Manual Copyright © 1995-2016, FOOKES Holding Ltd, Switzerland NoteTab® Tame Your Text with NoteTab by FOOKES Holding Ltd A leading-edge text and HTML editor. Handle a stack of huge files with ease, format text, use a spell-checker, and perform system-wide searches and multi-line global replacements. Build document templates, convert text to HTML on the fly, and take charge of your code with a bunch of handy HTML tools. Use a power-packed scripting language to create anything from a text macro to a mini-application. Winner of top industry awards since 1998. “NoteTab” and “Fookes” are registered trademarks of Fookes Holding Ltd. All other trademarks and service marks, both marked and not marked, are the property of their respective ow ners. NoteTab® Copyright © 1995-2016, FOOKES Holding Ltd, Switzerland All rights reserved. No parts of this work may be reproduced in any form or by any means - graphic, electronic, or mechanical, including photocopying, recording, taping, or information storage and retrieval systems - without the written permission of the publisher. “NoteTab” and “Fookes” are registered trademarks of Fookes Holding Ltd. All other trademarks and service marks, both marked and not marked, are the property of their respective owners. While every precaution has been taken in the preparation of this document, the publisher and the author assume no responsibility for errors or omissions, or for damages resulting from the use of information contained in this document or from the use of programs and source code that may accompany it. In no event shall the publisher and the author be liable for any loss of profit or any other commercial damage caused or alleged to have been caused directly or indirectly by this document.
    [Show full text]
  • Sample Chapter 3
    108_GILLAM.ch03.fm Page 61 Monday, August 19, 2002 1:58 PM 3 Architecture: Not Just a Pile of Code Charts f you’re used to working with ASCII or other similar encodings designed I for European languages, you’ll find Unicode noticeably different from those other standards. You’ll also find that when you’re dealing with Unicode text, various assumptions you may have made in the past about how you deal with text don’t hold. If you’ve worked with encodings for other languages, at least some characteristics of Unicode will be familiar to you, but even then, some pieces of Unicode will be unfamiliar. Unicode is more than just a big pile of code charts. To be sure, it includes a big pile of code charts, but Unicode goes much further. It doesn’t just take a bunch of character forms and assign numbers to them; it adds a wealth of infor- mation on what those characters mean and how they are used. Unlike virtually all other character encoding standards, Unicode isn’t de- signed for the encoding of a single language or a family of closely related lan- guages. Rather, Unicode is designed for the encoding of all written languages. The current version doesn’t give you a way to encode all written languages (and in fact, this concept is such a slippery thing to define that it probably never will), but it does provide a way to encode an extremely wide variety of lan- guages. The languages vary tremendously in how they are written, so Unicode must be flexible enough to accommodate all of them.
    [Show full text]
  • Pdflib API Reference 9.0.1
    ABC PDFlib, PDFlib+PDI, PPS A library for generating PDF on the fly PDFlib 9.0.1 API Reference For use with C, C++, Cobol, COM, Java, .NET, Objective-C, Perl, PHP, Python, REALbasic/Xojo, RPG, Ruby Copyright © 1997–2013 PDFlib GmbH and Thomas Merz. All rights reserved. PDFlib users are granted permission to reproduce printed or digital copies of this manual for internal use. PDFlib GmbH Franziska-Bilek-Weg 9, 80339 München, Germany www.pdflib.com phone +49 • 89 • 452 33 84-0 fax +49 • 89 • 452 33 84-99 If you have questions check the PDFlib mailing list and archive at tech.groups.yahoo.com/group/pdflib Licensing contact: [email protected] Support for commercial PDFlib licensees: [email protected] (please include your license number) This publication and the information herein is furnished as is, is subject to change without notice, and should not be construed as a commitment by PDFlib GmbH. PDFlib GmbH assumes no responsibility or lia- bility for any errors or inaccuracies, makes no warranty of any kind (express, implied or statutory) with re- spect to this publication, and expressly disclaims any and all warranties of merchantability, fitness for par- ticular purposes and noninfringement of third party rights. PDFlib and the PDFlib logo are registered trademarks of PDFlib GmbH. PDFlib licensees are granted the right to use the PDFlib name and logo in their product documentation. However, this is not required. Adobe, Acrobat, PostScript, and XMP are trademarks of Adobe Systems Inc. AIX, IBM, OS/390, WebSphere, iSeries, and zSeries are trademarks of International Business Machines Corporation.
    [Show full text]
  • Locale Database
    International Language Environments Guide Part No: 817–2521–11 November 2010 Copyright © 2005, 2010, Oracle and/or its affiliates. All rights reserved. This software and related documentation are provided under a license agreement containing restrictions on use and disclosure and are protected by intellectual property laws. Except as expressly permitted in your license agreement or allowed by law, you may not use, copy, reproduce, translate, broadcast, modify, license, transmit, distribute, exhibit, perform, publish, or display any part, in any form, or by any means. Reverse engineering, disassembly, or decompilation of this software, unless required by law for interoperability, is prohibited. The information contained herein is subject to change without notice and is not warranted to be error-free. If you find any errors, please report them to us in writing. If this is software or related software documentation that is delivered to the U.S. Government or anyone licensing it on behalf of the U.S. Government, the following notice is applicable: U.S. GOVERNMENT RIGHTS Programs, software, databases, and related documentation and technical data delivered to U.S. Government customers are “commercial computer software” or “commercial technical data” pursuant to the applicable Federal Acquisition Regulation and agency-specific supplemental regulations. As such, the use, duplication, disclosure, modification, and adaptation shall be subject to the restrictions and license terms setforth in the applicable Government contract, and, to the extent applicable by the terms of the Government contract, the additional rights set forth in FAR 52.227-19, Commercial Computer Software License (December 2007). Oracle America, Inc., 500 Oracle Parkway, Redwood City, CA 94065.
    [Show full text]
  • C++ Reading a Line of Text
    C++ Reading a Line of Text Because there are times when you do not want to skip whitespace before inputting a character, there is a function to input the next character in the stream regardless of what it is. The function is named get and is applied as shown. cin.get(character); The next character in the input stream is returned in char variable character. If the previous input was a numeric value, character contains whatever character ended the inputting of the value. There are also times when you want to skip the rest of the values on a line and go to the beginning of the next line. A function named ignore defined in file <iostream> allows you to do this. It has two parameters. The first is an int expression and the second is a character. This function skips the number of characters specified in the first parameter or all the characters up to and including the character specified in the second parameter, whichever comes first. For example, cin.ignore(80, '\n'); skips 80 characters or skips to the beginning of the next line depending on whether a newline character is encountered before 80 characters are skipped (read and discarded). As another example, consider: cin.ignore(4,’g’); cin.get(c); cout << c << endl; If the input to this program is “agdfg” then the input is ignored up to and including the ‘g’ so the next character read is ‘d’. The letter “d” is then output. If the input to this program is “abcdef” then the input is ignored for the first four characters, so the next character read is ‘e’.
    [Show full text]
  • The XSB System Version 2.4 Volume 1: Programmer's Manual
    The XSB System Version 2.4 Volume 1: Programmer’s Manual Konstantinos Sagonas Terrance Swift David S. Warren Juliana Freire Prasad Rao Baoqiu Cui Ernie Johnson with contributions from Steve Dawson Michael Kifer July 13, 2001 Credits Day-to-day care and feeding of XSB including bug fixes, ports, and configuration man- agement has been done by Kostis Sagonas, David Warren, Terrance Swift, Prasad Rao, Steve Dawson, Juliana Freire, Ernie Johnson, Baoqiu Cui, Michael Kifer, and Bart Demoen. In Version 2.4, the core engine development of the SLG-WAM has been mainly imple- mented by Terrance Swift, Kostis Sagonas, Prasad Rao, and Juliana Freire. The break- down, roughly, was that Terrance Swift wrote the initial tabling engine and builtins. Prasad Rao reimplemented the engine’s tabling subsystem to use tries for variant-based table access while Kostis Sagonas implemented most of tabled negation. Juliana Freire revised the table scheduling mechanism starting from Version 1.5.0 to create a more efficient engine, and implemented the engine for local evaluation. Starting from XSB Version 2.0, XSB includes another tabling engine, CHAT, which was designed and developed by Kostis Sagonas and Bart Demoen. CHAT supports heap garbage collection (both based on a mark&slide and on a mark&copy algorithm) which was developed and implemented by Bart Demoen and Kostis Sagonas. Memory expansion code for WAM stacks was written by Ernie Johnson and Bart De- moen, while memory management code for CHAT areas was written by Bart Demoen and Kostis Sagonas. Rui Marques improved the trailing of the SLG-WAM and rewrote much of the engine to make it compliant with 64-bit architectures.
    [Show full text]
  • Text Preprocessing in Programmable Logic
    Text Preprocessing in Programmable Logic by Michał Jan Skiba A thesis presented to the University of Waterloo in fulfillment of the thesis requirement for the degree of Master of Applied Science in Electrical and Computer Engineering Waterloo, Ontario, Canada, 2010 ©Michał Jan Skiba 2010 I hereby declare that I am the sole author of this thesis. This is a true copy of the thesis, including any required final revisions, as accepted by my examiners. I understand that my thesis may be made electronically available to the public. ii Abstract There is a tremendous amount of information being generated and stored every year, and its growth rate is exponential. From 2008 to 2009, the growth rate was estimated to be 62%. In 2010, the amount of generated information is expected to grow by 50% to 1.2 Zettabytes, and by 2020 this rate is expected to grow to 35 Zettabytes[IE10]. By preprocessing text in programmable logic, high data processing rates could be achieved with greater power efficiency than with an equivalent software solution[VAM09], leading to a smaller carbon footprint. This thesis presents an overview of the fields of Information Retrieval and Natural Lan- guage Processing, and the design and implementation of four text preprocessing modules in programmable logic: UTF–8 decoding, stop–word filtering, and stemming with both Lovins’[Lov68] and Porter’s[Por80] techniques. These extensively pipelined circuits were implemented in a high performance FPGA and found to sustain maximum operational frequencies of 704 MHz, data throughputs in excess of 5 Gbps and efficiencies in the range of 4.332 – 6.765 mW/Gbps and 34.66 – 108.2 µW/MHz.
    [Show full text]
  • CS151.02 2007S : Character Values in Scheme
    Fundamentals of Computer Science I (CS151.02 2007S) Character Values in Scheme Summary: We consider characters, one of the important primitive data types in many languages. Characters are the building blocks of strings (which we cover in a subsequent reading). Procedures and Constants Covered in This Reading: Constant notation: #\ch (character constants) "string" (string constants). Character constants: #\a (lowercase a) ... #\z (lowercase z); #\A (uppercase A) ... #\Z (uppercase Z); #\0 (zero) ... #\9 (nine); #\space (space); #\newline (newline); and #\? (question mark). Character conversion: char->integer, integer->char, char-downcase, and char-upcase Unary character predicates: char?, char-alphabetic?, char-numeric?, char-lower-case?, char-upper-case?, and char-whitespace?. Character comparison predicates (warning: reference links do not yet work): char<?, char<=?, char=?, char>=?, char>?, char-ci<?, char-ci<=?, char-ci=?, char-ci>=?, and char-ci>?. Contents: Introduction Characters in Scheme Collating Sequences Handling Case More Character Predicates Appendix: Representing Characters ASCII Unicode Introduction A character is a small, repeatable unit within some system of writing -- a letter or a punctuation mark, if the system is alphabetic, or an ideogram in a writing system like Han (Chinese). Characters are usually put together in sequences called strings. Although early computer programs focused primarily on numeric processing, as computation advanced, it grew to incorporate a variety of algorithms that incorporated characters and strings. Some of the more interesting algorithms we will consider involve these data types. Hence, we must learn how to use this building blocks. 1 Characters in Scheme As you might expect, Scheme needs a way to distinguish between many different but similar things, including: characters (the units of writing), strings (formed by combining characters), symbols (which are treated as atomic and also cannot be combined or separated), and variables (names of values).
    [Show full text]
  • Emeditor Manual
    Greeting Thank you for choosing EmEditor Professional. EmEditor has been used and favored by many users because of its extremely high standard of quality and reliability. EmEditor has become my masterpiece, and I put all my effort into it. I highly recommend this software to all users. EmEditor can be evolved much more with your feedback. I would appreciate it if you would consider EmEditor for long term use and contact me anytime, by e-mail or on the forums, if you have questions or comments. Yutaka Emura President, Emurasoft, Inc. November 2011 E-mail: [email protected] Web: http://www.emeditor.com/ ii Contents Contents Greeting ............................................................................................................................................... i Contents ............................................................................................................................................. ii Getting Started ................................................................................................................... 1 About License .................................................................................................................................................. 1 About Support ................................................................................................................................................. 1 Premium Support............................................................................................................................................. 1 Getting
    [Show full text]
  • X Locale Database Definition
    XLocale Database Definition Yoshio Horiuchi IBM Japan Copyright © IBM Corporation 1994 All Rights Reserved License to use, copy, modify,and distribute this software and its documentation for anypurpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of IBM not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. IBM DISCLAIMS ALL WARRANTIES WITH REGARD TOTHIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY,FITNESS, AND NONINFRINGEMENT OF THIRD PARTY RIGHTS, IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DAT A OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CON- NECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. Copyright © 1994 X Consortium Permission is hereby granted, free of charge, to anyperson obtaining a copyofthis software and associated documenta- tion files (the ‘‘Software’’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Soft- ware. THE SOFTWARE IS PROVIDED ‘‘ASIS’’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOTLIMITED TOTHE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTIC- ULAR PURPOSE AND NONINFRINGEMENT.INNOEVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,WHETHER IN AN ACTION OF CONTRACT,TORTOROTH- ERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    [Show full text]