CPSC 121 Third Project Character Pictures

download CPSC 121 Third Project Character Pictures

of 4

Transcript of CPSC 121 Third Project Character Pictures

  • CPSC 121::Third Project Character Picturesdue 13 April 2014

    Background: A CharacterPicture is a rectangular array of characters that can be printed, with or without a frame. For example, given the following strings:

    char* init[] = { Miami, in the, Autumn };

    The unframed CharacterPicture would look like this:Miami // unframed picturein theAutumn

    and the framed CharacterPicture would look like this:+------+|Miami | // framed picture|in the||Autumn|+------+

    To make this task more interesting, we should be able to horizontally concatenate CharacterPictures:Miami +------+in the|Miami | // horizontal Concat. Of framed and unframedAutumn|in the| |Autumn| +------+

    and vertically concatenate them:+------+|London||in the| // vertical concat. of framed picture and (horiz. concat. Of unframed and framed)|Fall |+------+Miami +------+in the| Miami |Autumn|in the| |Autumn| +------+ and of course, we should be able to frame the resulting pictures, without restriction (other than eventually running out of screen space)+--------------+|+------+ |||London| | // FRAME of (vert. Concat. Of framed picture||in the| | // and (horiz. Concat of unframed and framed)||Fall | ||+------+ ||Miami +------+||in the|Miami |||Autumn|in the||| |Autumn||| +------+|+--------------+

    CPSC 121::Third project: Character Pictures due 13 April 2014 at midnightDr. Will McCarthy page 1 of 4

  • Task: Your task is to write a SINGLE class to implement this functionality.

    Your class MUST include dynamic memory allocation (to store an array of char* 's, each pointer of whichpoints to one of the lines in the character picture. Because your class allocates dynamic memory, it MUSThave a copy constructor, assignment operator, and destructor to manage this memory properly.

    Your class must allow character pictures to be printed out as in the example on page 1 of this project description: (1) unframed(2) framed (using '+' for the corners, '' for the top/bottom, and '|' for the sides of the frame)friend Picture frame( Picture const& p );(3) horizontally concatenated (using operator|())friend Picture operator|( Picture const& p1, Picture const& p2 );(4) vertically concatenated (using operator&()), friend Picture operator&( Picture const& p1, Picture const& p2 );

    and must allow these operations (framing, horizontal concatenating, and vertical concatenating) to be combined without limit.

    The following (private) function is recommended to help you implement this project.// copies all characters from other (starting at 0, 0) to this picture, but starting at r, c void blockcopy( int r, int c, Picture const& other );Remember, you are using a block of memory accessed by a 1-d pointer to manipulate the 2-d array

    Test program const char* init[] = { "Miami", "in the", "Autumn" };

    int main() { Picture p( init, 3 ); cout

  • Example Output (comments are not part of the output)Miami in the // this is pAutumn

    +------+|Miami | // this is p_framed = frame( p )|in the||Autumn|+------+

    +--------------+|+------+ |||Miami | | // this is q = frame( p_framed & (p | p_framed) )||in the| |||Autumn| ||+------+ ||Miami +------+||in the|Miami |||Autumn|in the||| |Autumn||| +------+|+--------------+

    +------++--------------+|Miami ||+------+ ||in the|||Miami | | // this is r = (p_framed & p) | q|Autumn|||in the| | +------+||Autumn| |Miami |+------+ |in the |Miami +------+|Autumn |in the|Miami || |Autumn|in the|| | |Autumn|| | +------+| +--------------+

    +------------------------+|+------++--------------+|||Miami ||+------+ || // this is r_framed = frame( r )||in the|||Miami | ||||Autumn|||in the| |||+------+||Autumn| |||Miami |+------+ |||in the |Miami +------+|||Autumn |in the |Miami |||| |Autumn |in the|||| | |Autumn|||| | +------+||| +--------------+|+------------------------+

    Due date:This project is due in approximately two weeks, on Sunday, 13 April 2014, at midnight. It involves designing, implementing, and testing a substantial program for the subset of C++ that we are studying in this course, from start to finish. Your submission will be a written project report, including your C++ source code and

    CPSC 121::Third project: Character Pictures due 13 April 2014 at midnightDr. Will McCarthy page 3 of 4

  • output, submitted electronically to TITANium as a single PDF file. Note: You may work in pairs on this project. Should you work with a partner, please turn in one report with both names.

    Important! The following types of submissions are impermissible, and will receive a score of zero. Late submissions Email submissions Source code that will not compile without errors Falsified input/output or that doesn't match the source code. Submissions that are plagiarized or that violate the below collaboration guidelines.

    Late submissions: No late homework, labs, or project assignments will be accepted under any circumstances (score of 0). Don't be late.

    When working in labs or when working on projects, you will work in a collaborative environment, optionally with one partner. Partners may work together freely. Each group should complete their own work themselves, with very limited help from other individuals or sources. The following guidelines apply to collaboration with any person or resource _other than your partner_.

    You should be able to explain any part of your submission, and be able to explain why you wrote what you did. If working in a group, each member of the group should be able to explain any part of the submission, and not just be able to explain "his or her" subset.

    You may help each other understand the assignment and brainstorm general solutions, but must separateto develop your own detailed solution to the problem, and must individually type in your source code and project report.

    You may, of course, give each other technical support, for instance troubleshooting installing Visual Studio or logging into TITANium.

    You can share documented facts, such as the return value of a particular library function.

    Given these requirements, any submissions with identical excerpts, or excerpts that are identical up to superficialrearrangements, will be considered highly suspect of plagiarism.

    CPSC 121::Third project: Character Pictures due 13 April 2014 at midnightDr. Will McCarthy page 4 of 4