Thread: I need someone to help me with my program, just get me started

  1. #1
    Registered User
    Join Date
    Apr 2012
    Posts
    2

    I need someone to help me with my program, just get me started

    Hello, I am new to c++, I am having trouble implementing my book index program, here are the requirements:

    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:


    <html> <head> <title>BookTitle</title> </head> <body> <p> <a href="page0001.html">First</a>, <a href="page0023.html">Prev</a>, <a href="page0025.html">Next</a>, <a href="indexPage.html">Index</a> </p> <hr/> Lines of text from the book appear here, exactly as they appear in the text file. </body> </html> 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:".
    This is the first stage in a semester project that will challenge you to design and develop a larger and more complicated program than you have been accustomed to in the past. Generating an Index

    The final page generated by the program will be stored in "indexPage.html". This page will look like:

    <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> The main portion of the page has a section for each letter from A..Z. Each section has an <h2> header and a <ul>...</ul> list. Inside that list will be one <li>...</li> entry for each index term beginning with the corresponding letter. Each such entry will contain the index term followed by a list of <a>...</a> 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


    Here is my driver so far:

    Code:
    #include <iostream>
    #include <sstream>
    #include <fstream>
    
    
    using namespace std;
    
    /*
     *This program run only with one command line parameter which is:
        1) The name of the bookfile to be generated into webpages
     */
    
    int main (int argc, char** argv)
    {
      if (argc != 2)
        {
          cerr << "Usage: " << argv[0] << " textFileName" << endl;
          return -1;
        }
    
     istringstream bookIn (argv[1]);
    
      
    
    
      return 0;
    }
    here is indexConstants.cpp:

    Code:
    #include<iostream>
    // Special constants controlling the indexing program  extern const 
    
    int PAGE_THRESHOLD = 25; 
    extern const int MAX_LINES_PER_PAGE = 75;

  2. #2
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    I suggest adding more code.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  3. #3
    Registered User
    Join Date
    Apr 2012
    Posts
    2
    Quote Originally Posted by oogabooga View Post
    I suggest adding more code.
    Thats the thing, I am a beginner and I need some one to help me on this project. How do you input a book in ASCII.txt format and then split the book into HTML webpages?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Look at this part of your instructions:
    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.
    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.

    At this point you would not have anything to do with printing a web page, but it gets you closer to your goal. You have code that works, and then you can build on it.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Quote Originally Posted by and7777 View Post
    Thats the thing, I am a beginner and I need some one to help me on this project. How do you input a book in ASCII.txt format and then split the book into HTML webpages?
    Well now that's an actual question. Better than just dumping an entire assignment description and expecting people to read it. That just gives the impression that you're not putting in any effort.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    A development process
    Read this and learn about making small manageable steps, and reorganising code as you make progress.

    Start with something simple, say just counting the number of lines in the file.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with getting started on a small C++ program
    By coder02 in forum C++ Programming
    Replies: 4
    Last Post: 01-15-2012, 11:54 PM
  2. Bug in my barely-started text-based game program
    By linkofazeroth in forum C++ Programming
    Replies: 18
    Last Post: 08-30-2005, 01:32 AM
  3. Want to run .dll when a program is started
    By mayhem in forum Windows Programming
    Replies: 3
    Last Post: 06-24-2005, 08:18 AM
  4. Help Me Get Started On A program
    By rainmanddw in forum C++ Programming
    Replies: 2
    Last Post: 08-20-2004, 05:05 PM
  5. Replies: 5
    Last Post: 06-15-2003, 11:20 AM