Question: Implement a C + + library of functions Write a program using your library Understand the difference between a library and a program Implement some
Implement a C library of functions Write a program using your library Understand the difference between a library and a program Implement some more advanced loop structures Declare, initialize, and manipulate primitive arrays Use primitive arrays with functions, including appropriate use of const and passbyreference parameters Pass a filename as a command line argument and write to it Note: This assignment is not to be Implement a C library of functions Write a program using your library
main.cpp: Your main program that uses your library
asciigen.cpp and asciigen.h
Do not modify the functions declared in asciigen.h This defines the interface for your library, so to make it work with multiple main programs, it must remain consistent.
The canvas for your artwork is assumed to be a DIM x DIM D array of characters. The origin is in the top left corner, with index positions as shown:
To keep things simple, the array size is the same in both dimensions and is defined as a constant in asciigen.h as DIM Note that there are also constants defined for the empty character and the fill character. You should use these constants in your implementation.
The asciigen library should implement a set of functions for generating and manipulating basic shapes. Ive defined some of the trickier ones for you, but youll need to implement the rest. Heres a list of the functions in asciigen.h:
print: Write the ASCII art to the given output stream, with a frame around it and title below see the sample ASCII art for examples A space should be printed after each character to make it appear more or less square, while the frame should be made of and characters for the sides, topbottom and corners, respectively.
init: Fill the canvas with the empty character.
drawcircle: Draw a filled circle on the canvas. Ive implemented this one for you to get you started, no need to change it
drawrectangle: Draw a filled rectangle on the canvas. The starting point should be included in the widthheight eg drawrectangleart should draw a x square starting at the top left corner Example: drawrectangleart should fill the array as follows:
@@@@@ @@@@@ @@@@@
drawequilateral: Draw a filled equilateral triangle on the canvas with the given side length and vertex position, oriented as shown below:
Again, the vertex coordinate should be included in the triangle. For example, drawequilateralart should fill the array as follows yes its a pretty sad approximation of an equilateral triangle:
@ @ @@@ @@@ @@@@@
Hint: Youll probably need some trig functions to calculate whether a given point is inside the triangle! These are already included in
calcunion: Calculate the union or logical or of two canvases, storing the result in the first one lhs Ive also implemented this one for you.
calcintersection: Calculate the intersection or logical and of two canvases, storing the result in the first one lhs
calccomplement: Calculate the complement or logical not of a canvas.
rotate: Rotate a canvas at an arbitrary angle, given in radians. This one is a bit tricksy so Ive also implemented it for you.
translate: Shift a canvas by a given amount in the x and y directions. Recall that positive x is right, while positive y is down.
For any command that might result in drawing out of the bounds of the grid eg a request to draw a circle centred at with radius of fill in the pixels that are in the grid and ignore the rest.
Finally, Ive implemented some private helper functions that I found useful you might find them useful too! Feel free to add additional private functions as needed.
main.cpp
This one is quite a bit less prescriptive. It should:
Check that the user has provided an output file name, and exit with a usage message if not, eg:
$ a Usage: a
Try to open the output file, and exit with an error message if it cant eg:
$ a tests Could not open tests, try again.
Use the functions in asciigen.h to create different pieces of ASCII art. Do not try to recreate mine be creative! Show off the functionality in your library. You can create just about whatever you want, provided that you use all of the functions in your library at least once.
Write each piece of artwork to the output file using the print function in asciigen.h and inform the user that all was successful, eg:
$ a output.txt ASCII art successfully written to output.txt
The starter code contains my example output, but again, yours should be different artwork.
Hint: If youre working on this before we cover file IO you can pass cout to print as the output stream to display the art on the console, eg:
printart "Double Rainbow", cout;
This is also a handy way to repeatedly display your artwork as youre tweaking things to save the writing to file step.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
