update hw1
This commit is contained in:
@@ -1,75 +1,26 @@
|
||||
# Homework 1 — Text Justification
|
||||
# Homework 1 — Spotify Playlists
|
||||
|
||||
Before starting this homework, make sure you have read and understood the Academic Integrity Policy.
|
||||
|
||||
This homework assignment is a programming exercise involving simple text manipulation to format input
|
||||
text into a framed column with a specified width. You will work with command line arguments, file input
|
||||
and output, and the C++ Standard Template Library string and vector classes. Please read the entire
|
||||
assignment before starting to program.
|
||||
In this assignment you will develop a program to manage music playlists like Spotify does, let's call this program New York Playlists. Please read the entire handout before starting to code the assignment.
|
||||
|
||||
Your program will read words from an input file and greedily pack the words one at a time onto each line,
|
||||
making sure not to exceed the specified width. Your program will support three different methods for dealing
|
||||
with any extra, unused space on each line. The first, **flush left**, simply positions each word as far to the left as
|
||||
possible, leaving a gap of spaces (if any) on the right. The second, **flush right**, does the opposite, pushing all
|
||||
the words to the right, and puts the extra spaces on the left. In the final mode, **full justify**, the extra spaces
|
||||
are distributed evenly between the words. If the number of extra spaces on the line do not divide evenly into
|
||||
those “between” slots, the slots on the left will be assigned more spaces that the slots on the right.
|
||||
## Learning Objectives
|
||||
|
||||
Let’s look at a simple example. Here is a sample input file, named example.txt:
|
||||
- Practice handling command line arguments
|
||||
- Practice handling file input and output
|
||||
- Practice the C++ Standard Template Library string and vector classes.
|
||||
|
||||
*Here is an example of text justification.*
|
||||
## Background
|
||||
|
||||
And here’s the output produced for that input file for the three different justification modes, for the specified
|
||||
text width of 16:
|
||||
On Spotify, users can create and manage playlists. On the Spotify app or website, users can navigate to the "Your Library" section and click on the "+" sign to create a playlist. When creating a playlist, users can add music tracks to the playlist.
|
||||
|
||||
**flush left**
|
||||
```txt
|
||||
--------------------
|
||||
| Here is an |
|
||||
| example of text |
|
||||
| justification. |
|
||||
--------------------
|
||||
```
|
||||
After a playlist is created, users can add new tracks to this playlist, or remove tracks from this playlist. Users can also re-order tracks within a playlist. The following two images show the re-order process:
|
||||
|
||||
**flush right**
|
||||
```txt
|
||||
--------------------
|
||||
| Here is an |
|
||||
| example of text |
|
||||
| justification. |
|
||||
--------------------
|
||||
```
|
||||
Before re-ordering, track 1 is "Perfect Duet", track 2 is "Always Remember Us This Way", track 3 is "Million Reasons", and track 4 is "I'll Never Love Again".
|
||||
|
||||
**full justify**
|
||||
```txt
|
||||
--------------------
|
||||
| Here is an |
|
||||
| example of text |
|
||||
| justification. |
|
||||
--------------------
|
||||
```
|
||||
Next, we drag track 4 up to right above track 2.
|
||||
|
||||
First note that the output includes a simple ascii art line box drawn around the text, but those characters
|
||||
do not count towards the specified line width of the text. In other words, each line of final output is actually
|
||||
4 characters longer, in this example, 20 total characters. Notice that the same words appear on each line
|
||||
in all three cases. The only difference is where the “extra” spaces appear. The top line has 6 extra spaces
|
||||
(16 - # of characters in “Here is an” = 6). In full justify mode, these spaces are evenly divided into the 2
|
||||
slots between the 3 words. The second line has 1 extra space (16 - # of characters in “example of text”
|
||||
= 1). This extra space (still in full justify mode) is assigned to the leftmost of the two slots on the second line. Also note a typical
|
||||
convention for full justify formatting: The last line of a block of text formatted with full justify is not forced
|
||||
to stretch all the way to the right edge. No extra space is inserted between words on the last line – it should
|
||||
be flush left justified only.
|
||||
|
||||
## File I/O
|
||||
|
||||
You will read the words to format from an input text file. You should not make any assumptions about the
|
||||
formatting of this file, except that the words will be separated by at least one whitespace character. Remember
|
||||
that whitespace characters include spaces, tabs, and newlines. Any punctuation in the file (including periods,
|
||||
commas, apostrophes, etc.) should be treated as part of the word if it is not separated from the word by
|
||||
spaces. The basic iostream string input operator, >>, will work perfectly for this assignment. The output of
|
||||
your program will be written to a file, and should follow the specifications in this handout and match our
|
||||
examples. Reading and writing files in C++ is very similar to std::cin and std::cout. See examples of
|
||||
STL file streams on the course webpage [Programming Information](https://www.cs.rpi.edu/academics/courses/fall23/csci1200/programming_information.php).
|
||||
After this dragging action, now, track 1 is still "Perfect Duet", track 2 is "I'll Never Love Again", track 3 is "Always Remember Us This Way", and track 4 is "Million Reasons".
|
||||
|
||||
## Command Line Arguments
|
||||
|
||||
@@ -79,9 +30,10 @@ fourth argument will be a string (flush_left, flush_right, or full_justify) spec
|
||||
mode should be used. Here are examples of valid command lines for your program:
|
||||
|
||||
```console
|
||||
./justify.exe example.txt example_16_flush_left.txt 16 flush_left
|
||||
./justify.exe example.txt example_16_flush_right.txt 16 flush_right
|
||||
./justify.exe example.txt example_16_full_justify.txt 16 full_justify
|
||||
./nyplaylists.exe playlist1.txt output.txt add
|
||||
./nyplaylists.exe playlist1.txt output.txt remove
|
||||
./nyplaylists.exe playlist1.txt output.txt reorder old new
|
||||
./nyplaylists.exe playlist1.txt output.txt skip count
|
||||
```
|
||||
|
||||
You should implement very simple error checking to ensure that 4 arguments are provided and that the
|
||||
@@ -94,6 +46,17 @@ receive full credit from the Submitty homework submission autograder. We have pr
|
||||
output files on the course website. Examples of using command line arguments can be found on the course
|
||||
webpage: [Programming Information](https://www.cs.rpi.edu/academics/courses/fall23/csci1200/programming_information.php).
|
||||
|
||||
## File I/O
|
||||
|
||||
You will read the words to format from an input text file. You should not make any assumptions about the
|
||||
formatting of this file, except that the words will be separated by at least one whitespace character. Remember
|
||||
that whitespace characters include spaces, tabs, and newlines. Any punctuation in the file (including periods,
|
||||
commas, apostrophes, etc.) should be treated as part of the word if it is not separated from the word by
|
||||
spaces. The basic iostream string input operator, >>, will work perfectly for this assignment. The output of
|
||||
your program will be written to a file, and should follow the specifications in this handout and match our
|
||||
examples. Reading and writing files in C++ is very similar to std::cin and std::cout. See examples of
|
||||
STL file streams on the course webpage [Programming Information](https://www.cs.rpi.edu/academics/courses/fall23/csci1200/programming_information.php).
|
||||
|
||||
## Corner Cases
|
||||
|
||||
So now you understand the core requirements for this assignment, but you may already have thought of a
|
||||
@@ -1,34 +0,0 @@
|
||||
HOMEWORK 1: TEXT JUSTIFICATION
|
||||
|
||||
|
||||
NAME: < insert name >
|
||||
|
||||
|
||||
COLLABORATORS AND OTHER RESOURCES:
|
||||
List the names of everyone you talked to about this assignment
|
||||
(classmates, TAs, ALAC tutors, upperclassmen, students/instructor via
|
||||
LMS, etc.), and all of the resources (books, online reference
|
||||
material, etc.) you consulted in completing this assignment.
|
||||
|
||||
< insert collaborators / resources >
|
||||
|
||||
Remember: Your implementation for this assignment must be done on your
|
||||
own, as described in "Academic Integrity for Homework" handout.
|
||||
|
||||
|
||||
|
||||
ESTIMATE OF # OF HOURS SPENT ON THIS ASSIGNMENT: < insert # hours >
|
||||
|
||||
|
||||
|
||||
EXTRA CREDIT SHAPES:
|
||||
Describe your new shapes, include example files of the output with
|
||||
your submission, and provide the command line used to create the these
|
||||
examples.
|
||||
|
||||
|
||||
|
||||
MISC. COMMENTS TO GRADER:
|
||||
Optional, please be concise!
|
||||
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
Here is an example of text justification.
|
||||
@@ -1,5 +0,0 @@
|
||||
--------------------
|
||||
| Here is an |
|
||||
| example of text |
|
||||
| justification. |
|
||||
--------------------
|
||||
@@ -1,5 +0,0 @@
|
||||
--------------------
|
||||
| Here is an |
|
||||
| example of text |
|
||||
| justification. |
|
||||
--------------------
|
||||
@@ -1,5 +0,0 @@
|
||||
--------------------
|
||||
| Here is an |
|
||||
| example of text |
|
||||
| justification. |
|
||||
--------------------
|
||||
@@ -1,5 +0,0 @@
|
||||
Four score and seven years ago our fathers brought forth on this continent a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.
|
||||
|
||||
Now we are engaged in a great civil war, testing whether that nation, or any nation, so conceived and so dedicated, can long endure. We are met on a great battlefield of that war. We have come to dedicate a portion of that field, as a final resting place for those who here gave their lives that that nation might live. It is altogether fitting and proper that we should do this.
|
||||
|
||||
But, in a larger sense, we can not dedicate... we can not consecrate... we can not hallow this ground. The brave men, living and dead, who struggled here, have consecrated it, far above our poor power to add or detract. The world will little note, nor long remember what we say here, but it can never forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to be here dedicated to the great task remaining before us that from these honored dead we take increased devotion to that cause for which they gave the last full measure of devotion that we here highly resolve that these dead shall not have died in vain that this nation, under God, shall have a new birth of freedom and that government: of the people, by the people, for the people, shall not perish from the earth.
|
||||
@@ -1,24 +0,0 @@
|
||||
--------------------------------------------------------------------------
|
||||
| Four score and seven years ago our fathers brought forth on this |
|
||||
| continent a new nation, conceived in Liberty, and dedicated to the |
|
||||
| proposition that all men are created equal. Now we are engaged in a |
|
||||
| great civil war, testing whether that nation, or any nation, so |
|
||||
| conceived and so dedicated, can long endure. We are met on a great |
|
||||
| battlefield of that war. We have come to dedicate a portion of that |
|
||||
| field, as a final resting place for those who here gave their lives |
|
||||
| that that nation might live. It is altogether fitting and proper that |
|
||||
| we should do this. But, in a larger sense, we can not dedicate... we |
|
||||
| can not consecrate... we can not hallow this ground. The brave men, |
|
||||
| living and dead, who struggled here, have consecrated it, far above |
|
||||
| our poor power to add or detract. The world will little note, nor long |
|
||||
| remember what we say here, but it can never forget what they did here. |
|
||||
| It is for us the living, rather, to be dedicated here to the |
|
||||
| unfinished work which they who fought here have thus far so nobly |
|
||||
| advanced. It is rather for us to be here dedicated to the great task |
|
||||
| remaining before us that from these honored dead we take increased |
|
||||
| devotion to that cause for which they gave the last full measure of |
|
||||
| devotion that we here highly resolve that these dead shall not have |
|
||||
| died in vain that this nation, under God, shall have a new birth of |
|
||||
| freedom and that government: of the people, by the people, for the |
|
||||
| people, shall not perish from the earth. |
|
||||
--------------------------------------------------------------------------
|
||||
@@ -1,24 +0,0 @@
|
||||
--------------------------------------------------------------------------
|
||||
| Four score and seven years ago our fathers brought forth on this |
|
||||
| continent a new nation, conceived in Liberty, and dedicated to the |
|
||||
| proposition that all men are created equal. Now we are engaged in a |
|
||||
| great civil war, testing whether that nation, or any nation, so |
|
||||
| conceived and so dedicated, can long endure. We are met on a great |
|
||||
| battlefield of that war. We have come to dedicate a portion of that |
|
||||
| field, as a final resting place for those who here gave their lives |
|
||||
| that that nation might live. It is altogether fitting and proper that |
|
||||
| we should do this. But, in a larger sense, we can not dedicate... we |
|
||||
| can not consecrate... we can not hallow this ground. The brave men, |
|
||||
| living and dead, who struggled here, have consecrated it, far above |
|
||||
| our poor power to add or detract. The world will little note, nor long |
|
||||
| remember what we say here, but it can never forget what they did here. |
|
||||
| It is for us the living, rather, to be dedicated here to the |
|
||||
| unfinished work which they who fought here have thus far so nobly |
|
||||
| advanced. It is rather for us to be here dedicated to the great task |
|
||||
| remaining before us that from these honored dead we take increased |
|
||||
| devotion to that cause for which they gave the last full measure of |
|
||||
| devotion that we here highly resolve that these dead shall not have |
|
||||
| died in vain that this nation, under God, shall have a new birth of |
|
||||
| freedom and that government: of the people, by the people, for the |
|
||||
| people, shall not perish from the earth. |
|
||||
--------------------------------------------------------------------------
|
||||
@@ -1,24 +0,0 @@
|
||||
--------------------------------------------------------------------------
|
||||
| Four score and seven years ago our fathers brought forth on this |
|
||||
| continent a new nation, conceived in Liberty, and dedicated to the |
|
||||
| proposition that all men are created equal. Now we are engaged in a |
|
||||
| great civil war, testing whether that nation, or any nation, so |
|
||||
| conceived and so dedicated, can long endure. We are met on a great |
|
||||
| battlefield of that war. We have come to dedicate a portion of that |
|
||||
| field, as a final resting place for those who here gave their lives |
|
||||
| that that nation might live. It is altogether fitting and proper that |
|
||||
| we should do this. But, in a larger sense, we can not dedicate... we |
|
||||
| can not consecrate... we can not hallow this ground. The brave men, |
|
||||
| living and dead, who struggled here, have consecrated it, far above |
|
||||
| our poor power to add or detract. The world will little note, nor long |
|
||||
| remember what we say here, but it can never forget what they did here. |
|
||||
| It is for us the living, rather, to be dedicated here to the |
|
||||
| unfinished work which they who fought here have thus far so nobly |
|
||||
| advanced. It is rather for us to be here dedicated to the great task |
|
||||
| remaining before us that from these honored dead we take increased |
|
||||
| devotion to that cause for which they gave the last full measure of |
|
||||
| devotion that we here highly resolve that these dead shall not have |
|
||||
| died in vain that this nation, under God, shall have a new birth of |
|
||||
| freedom and that government: of the people, by the people, for the |
|
||||
| people, shall not perish from the earth. |
|
||||
--------------------------------------------------------------------------
|
||||
@@ -1,4 +0,0 @@
|
||||
Supercalifragilisticexpialidocious!
|
||||
Even though the sound of it is something quite atrocious!
|
||||
If you say it loud enough, you'll always sound precocious,
|
||||
Supercalifragilisticexpialidocious!
|
||||
@@ -1,16 +0,0 @@
|
||||
-------------------
|
||||
| Supercalifragi- |
|
||||
| listicexpialid- |
|
||||
| ocious! Even |
|
||||
| though the |
|
||||
| sound of it is |
|
||||
| something quite |
|
||||
| atrocious! If |
|
||||
| you say it loud |
|
||||
| enough, you'll |
|
||||
| always sound |
|
||||
| precocious, |
|
||||
| Supercalifragi- |
|
||||
| listicexpialid- |
|
||||
| ocious! |
|
||||
-------------------
|
||||
@@ -1,35 +0,0 @@
|
||||
This is just from last semester, and it may be slightly different from the one we eventually will use, because before they grade the homework, our graders will discuss whether or not to add or remove some of these items. Therefore you should just use this as a reference.
|
||||
|
||||
20 pts
|
||||
- README.txt Completed (3 pts)
|
||||
- Missing # of hours or collaborators (-1)
|
||||
- Collaborators too vague or not specific enough (-1)
|
||||
- You did not edit README file (-3)
|
||||
- Missing your name (-1)
|
||||
- STL Vector & String (5 pts)
|
||||
- did not use STL vector (-3)
|
||||
- Uses strings ineffectively: e.g. by parsing through spaces manually (-2)
|
||||
- Poor use of vectors (-2)
|
||||
- Inefficient program: did not use const/reference where copy was not needed or used a reference on immutable primitive types like int (-2)
|
||||
- Program Structure (12 pts)
|
||||
- Contains only the main function and no other functions at all. (-4)
|
||||
- Uses multiple functions, but most alignment logic is in the main function or one function. It's better to create separate functions for flush_left, flush_right and full_justify. (-3)
|
||||
- Code contains irrelevant comments like terminal commands, large amounts of commented out code, or large amounts of TODO comments (-1)
|
||||
- Almost total lack of helpful comments. (-4)
|
||||
- Too few comments. (-2)
|
||||
- Functions aren't well-commented. Each function should explain its purpose, algorithm, inputs, and outputs. (-2)
|
||||
- Excessive comments, especially those that focus on what the code is doing rather than why (e.g. "creates a string"). (-1)
|
||||
- Many comments are on same line as code. (-1)
|
||||
- Overly long lines, in excess of 100 or so characters. It's recommended to keep all lines short and put comments on their own lines. (-1)
|
||||
- Poor program structure: overly complex nested loops and if statements (-2)
|
||||
- Code is clumped together or too dense, or has excessive whitespace. (-1)
|
||||
- Poor formatting and/or spacing (-2)
|
||||
- Poor choice of variable names: non-descriptive names (e.g. 'vec', 'str', 'var'), single-letter variable names (except single loop counter), variable shadowing, etc. (-2)
|
||||
- Lacks error checking (num of args, invalid file names, invalid width limit, etc.) (-1)
|
||||
- Redundant code: unnecessary method extracting, unused variable/method, unused value/result, unreachable code, etc (-1)
|
||||
- Duplicated code: same code fragments or code fragments with only tiny differences (-1)
|
||||
- Use of global variables (-1)
|
||||
|
||||
Extra Credit (3 pts) (+1-3 for new shapes (by difficulty), described in the README.txt and sample output included with submission.)
|
||||
- Non-trivial attempt made (+1)
|
||||
- Great Job! (+2)
|
||||
Reference in New Issue
Block a user