

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Assignment; Class: DATA STRUCTURES; Subject: Computer Science; University: Rensselaer Polytechnic Institute; Term: Spring 2006;
Typology: Assignments
1 / 2
This page cannot be seen from the preview
Don't miss anything!


A moir´e pattern is a visible distortion that can result from a variety of interference conditions. The term comes from the French “moirer” (to water) and is used to describe a rippled, water-like look, which is often a desired artistic effect. The effect can be seen when two geometrically regular patterns (such as two sets of parallel lines or two halftone screens) are superimposed, especially at an acute angle. Definitions from http://webster.com and http://answers.com. Unintentional, distracting moir´e patterns can be seen in computer games and other graphical applications when intricate textures (such as a checkerboard below) are displayed in perspective on a computer screen. Various signal processing techniques can be used to reduce the appearance of Moir´e patterns.
In this homework you will work with command line arguments, file input and output, and the C++ string class to create ascii art with simple moir´e patterns! Please read the entire handout before beginning to program the assignment.
You will read string patterns from a input text file. Each line of the file will have first a string (of 1 or more non-whitespace characters) followed by a non-negative integer, n, which indicates the size of the finished moir´e polygon. Here is a sample input file, in patterns.txt:
abcde 9 hi! 21
Your program will expect 3 command line arguments. The first is the name of the input file. The second is the name of the output file where the program should output the finished moir´e imagery. The third argument will be a string (square, right triangle, or isosceles triangle) specifying which type of polygon should be created. Here are examples of valid command lines for your program:
moire.exe in_patterns.txt out_square.txt square moire.exe in_patterns.txt out_right_triangle.txt right_triangle moire.exe in_patterns.txt out_isosceles_triangle.txt isosceles_triangle
Implement very simple error checking to ensure that 3 arguments are provided and that the input and output file streams are successfully opened. Your program should exit gracefully with a useful error message sent to std::err if there is a problem with the arguments.
The output from your program will be stunning ascii art. For each string pattern in the input file, you will create one of three different outline polygons (as specified on the command line) and fill the interior of that polygon with the pattern string.
Each polygon is bordered by asterisk characters, similar to the greeting boxes we saw in lecture and the textbook (Koening & Moo, Chapter 1). The overall height of each polygon including the border is equal to the input n that accompanies each string pattern in the input file.
The interior of each polygon is filled with the string pattern from left to right. When you run out of characters in the string pattern, start at the beginning of the string pattern, leaving no white space. When you reach the right edge of the polygon remember where you left off so that you can start with that character on the next line.
Here is the output (3 different files) that should be produced by your program for the sample input file and sample command line arguments above:
square.txt right triangle.txt isosceles triangle.txt
abcdeab cdeabcd eabcdea bcdeabc deabcde abcdeab cdeabcd
__hi!____hi!____hi! ____hi!____hi!____h i!____hi!____hi!___ hi!____hi!____hi! ___hi!____hi!____hi !____hi!____hi!____ hi!____hi!____hi!__ __hi!____hi!____hi! ____hi!____hi!____h i!____hi!____hi!___ hi!____hi!____hi! ___hi!____hi!____hi !____hi!____hi!____ hi!____hi!____hi!__ __hi!____hi!____hi! ____hi!____hi!____h i!____hi!____hi!___ hi!____hi!____hi! ___hi!____hi!____hi
** a bc dea bcde abcde abcdea
** _ _h i!_ ___h i!___ hi!_ hi! hi!_ _hi!____h i!____hi!_ ___hi!____h i!____hi!___ hi!____hi!_ hi!____hi! hi!____hi!_ _hi!____hi!____h i!____hi!____hi!_ ___hi!____hi!____h
a bcd eabcd eabcdea bcdeabcde abcdeabcdea bcdeabcdeabcd
_ _hi !____ hi!____ hi!____hi !____hi!___ hi!____hi!_ hi!____hi!_ _hi!____hi!____hi !____hi!____hi!____ hi!____hi!____hi!____ hi!____hi!____hi!____hi !____hi!____hi!____hi!___ hi!____hi!____hi!____hi!_ hi!____hi!____hi!____hi!_ _hi!____hi!____hi!____hi!____hi !____hi!____hi!____hi!____hi!____ hi!____hi!____hi!____hi!____hi!____ hi!____hi!____hi!____hi!____hi!____hi
The sample input and output test files are available on the course webpage.
For extra credit, try other shapes. Write about your extensions in a plain text file named README.txt.
Do all of your work in a new folder named hw2 inside of your CSII homeworks directory. Name your project moire and put the code in a file moire.cpp. Use good coding style when you design and implement your program. Be sure to make up new test cases and don’t forget to comment your code! If you have any notes you want the grader to read, write them in a plain text file named README.txt. When you are finished please zip up your hw2 folder exactly as instructed for the previous assignment and submit it through the course webpage.