CS1030 -- Lab 5: Paragraph Class

Spring 2005
Objectives Addressed
Procedures

You should implement the class partially described in the following UML diagram.

+--------------------------------------------+
|                  Paragraph                 |
+--------------------------------------------+
|-numOfColumns : unsigned int = 40           |
|-wordlist : std::list<std::string>          | // each word should be a separate element
+--------------------------------------------+
|+Paragraph(words : std::string = "")        |
|+Paragraph(org : Paragraph)                 |
|+~Paragraph()                               |
|+operator=(rhs : Paragraph) : Paragraph     |
|+addWord(word : std::string) : void         | // Adds one word to the end of the wordlist.  If whitespace exists
|                                            | //  in word, everything after the first whitespace should be ignored.
|+addWords(words : std::string) : void       | // Clears current wordlist and adds each word (characters separated
|                                            | //  by whitespace) to the wordlist.
|+clear() : void                             | // Removes all words in the current wordlist.
|+size() : unsigned int                      | // Returns the number of words in the wordlist.
|+display(os : ostream) : void               | // Sends the wordlist to output stream passed to it.  The words
|                                            | //  should be formatted as described below.
|+setNumOfColumns(num : unsigned int) : void | // Sets the number of columns
|+getNumOfColumns() : unsigned int           | // Returns the number of columns
+--------------------------------------------+

The above UML diagram does not indicated references or const. You should pass in and return by reference when appropriate and make appropriate use of const.

Paragraph::display should use the following rules when sending the words to the output stream:

You should also implement the insertion operator so that it is possible to insert Paragraph objects into an output stream in the traditional way.

Sample results generator

Use the following program to generate sample output to be included with your submission.

// driver.cpp
// This program exercises the Paragraph class described in the Lab 5 assignment
//  for CS1030-002 Spring 2005.
// t a y l o r@msoe.edu, 4/20/2005

#include <fstream>
#include <string>
#include <vector>
#include <iomanip>
#include "Paragraph.h"
#include "Paragraph.h" // This duplicate is intentional

int main()
{
  const unsigned int numberOfTrials = 4;
  const unsigned int columnStartSize = 11;
  std::list<std::string> words;
  std::string line="Please plan on receiving a zero! For any assignment? in which you choose. ";
  words.push_back(line);
  line="I am interested in your feedback on how I can make\n";
  line += "this course better. Feel free to stop by my office, send me\n";
  line += "email, or drop an anonymous note in my department mailbox with\n";
  line += "suggestions on how I can make this a better class for you.\n";
  line += "Please don't wait until evaluation time because I won't see\n";
  line += "those comments until the quarter is over.";
  words.push_back(line);

  std::ofstream os("lab5sample.dat");
  std::list<std::string>::const_iterator itr = words.begin();
  while(itr!=words.end()) {
    Paragraph para(*itr);
    os << para << '\n';
    std::vector<Paragraph> paragraphs(numberOfTrials, para);
    unsigned int i=0;
    paragraphs[i].setNumOfColumns(columnStartSize);
    os << '|' << std::setw(paragraphs[i].getNumOfColumns()-1) << std::setfill('.') << '|' << std::endl;
    os << paragraphs[i] << '\n';
    for(++i; i<numberOfTrials; ++i) {
      paragraphs[i].setNumOfColumns(2*paragraphs[i-1].getNumOfColumns());
      os << '|' << std::setw(paragraphs[i].getNumOfColumns()-1) << std::setfill('.') << '|' << std::endl;
      os << paragraphs[i] << '\n';
    }
    ++itr;
  }
  return EXIT_SUCCESS;
}

Note: You may want to develop your own test program, since this program does not do a very thorough test of the class you are required to implement.

Lab submission (due at the end of lab)

Before you leave lab, you should submit your source code files as one zip file and the data file produced by the test program as the support file.

Late penalties: Every student is required to submit their Paragraph source files and sample output file at the end of lab. If a student wishes to submit a more complete solution at a later date, they should indicate this in the comment field of the initial submission. The schedule for penalties associated with resubmission are as follows: -2 by 11pm the day of lab, -7 by 11pm one day after lab, -10 for each additional day after lab. Additional points may be deducted if an initial submission fails to demonstrate significant progress towards the completion of the assignment.

Acknowledgment

This laboratory assignment was developed by Dr. Chris Taylor.

Last Updated: Thursday, 01-Jan-2015 14:32:37 EST