Apply the techniques of stepwise refinement and top-down design to prepare a pre
ID: 3680459 • Letter: A
Question
Apply the techniques of stepwise refinement and top-down design to prepare a preliminary design. (Preliminary because, as the semester progresses, you will learn more about how to improve your design process.)
You may not be able, yet, to take this all the way down to the level where all the functions or pseudocode statements can be obviously rendered into code, but you should strive to reach a level of detail that convinces the graders that you
understand the problem
have described all the major functional behaviors required for this problem (i.e., each kind of input that must be treated differently and each distinct kind of output that you must produce
have identified the major collections of data that will be required (but have not necessarily chosen the data structure for them)
have identified the “hard parts” that you might not yet know how to solve
Each distinct function in your design should be accompanied by a brief paragraph of comments indicating what it does, what its inputs are, and what its outputs will be.
Problem Description:
Since 1971, Project Gutenberg has collected the texts of public-domain books and made them available in electronic form.
Although some titles are available in html, EPUB, or other richer formats, Project Gutenberg started by collecting books as simple ASCII text files. Your semester project for this course is aimed at providing these files in a more web-friendly format.
There are two components to converting a text file into the desired “paged” format: generating html versions of the pages and preparing an index of the pages.
Splitting the Book into Pages
Input to the system will be a book in ASCII .txt format, such as this one. The name of the file containing this book will be supplied as a command line parameter (the only one required by this program.)
The first step in preparing this for the web will be to split this text into web pages, each page but the last containing MAX_LINES_PER_PAGE lines.
The generated web pages will be written to files named “pageNNNN.html”, where NNNN is a 4 digit number starting at 0001, then 0002, and so on.
Each generated page will consist of an html “wrapper” around the selected lines of text. The wrapper includes the book title (extracted from the Gutenberg text file) and links to the previous page, the next page, and the index page. For example, page 0024 of a book would look like:
BookTitle
First, Prev, Next, Index
The first page will not have the “Prev” link. The final page will not have the “Next” link. The book title can be extracted from the earliest line in the text file that begins with “Title:”.
Generating an Index
The final page generated by the program will be stored in “indexPage.html”. This page will look like:
BookTitle
First
A B C ... Z
Index
A
angle 1 3 23
arcs 25 26
B
bars ...
The main portion of the page has a section for each letter from A..Z. Each section has an
header and a
...
list. Inside that list will be one
...
entry for each index term beginning with the corresponding letter. Each such entry will contain the index term followed by a list of links to pages where that term occurs.
Details:
The index terms will be listed in alphabetical order.
An index term is a word occurring in the book. It consists of consecutive alphabetic characters an must either occur at the beginning of a line or must be preceded by a blank.
Words of 3 letters or less will not be used as index terms.
All index terms will be converted to lower case before being inserted into the index. Words in the text that differ only in the upper/lower case of their letters will be considered to be instances of the same index term.
For an index term to be useful, it must direct one to a limited portion of the book. Consequently, any word that occurs on more than PAGE_THRESHOLD percentage of the total pages will not be treated as an index term.
The constants MAX_LINES_PER_PAGE and PAGE_THRESHOLD will be declared in a header file indexConstants.h
Explanation / Answer
Project Gutenberg
You know that you will have to read up to MAX_LINES_PER_PAGE lines from a file. then write them out as a web page. So, try doing this part. Write a program that reads lines from a file whose name is given as a command line argument, and prints the lines to standard output. Then modify your program to read the lines into an array of MAX_LINES_PER_PAGE std::string objects, cutting off if the number of lines in the file exceeds MAX_LINES_PER_PAGE, and then print the contents of the array to standard output
<html>
<head>
<title>BookTitle</title>
</head>
<body>
<p>
<a href="page0001.html">First</a>
</p>
<hr/>
<p>
<a href="#A">A</a>
<a href="#B">B</a>
<a href="#C">C</a>
...
<a href="#Z">Z</a>
</p>
<hr/>
<h1>Index</h1>
<h2 id="A">A</h2>
<ul>
<li>angle
<a href="page0001.html">1</a>
<a href="page0003.html">3</a>
<a href="page0023.html">23</a>
</li>
<li>arcs
<a href="page0025.html">25</a>
<a href="page0026.html">26</a>
</li>
</ul>
<h2 id="B">B</h2>
<ul>
<li>bars
...
</body>
</html>
entry for each index term beginning with the corresponding letter. Each such entry will contain the index term followed by a list of ... links to pages where that term occurs.
Details:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.