

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: Fall 2006;
Typology: Assignments
1 / 3
This page cannot be seen from the preview
Don't miss anything!


Before starting this homework, make sure you have read and understood the CSII Academic Integrity Policy.
In your main CSII directory on your laptop, create a subdirectory for homeworks and within that directory create a subdirectory hw1 for this assignment. Create and open a plain text file named part1.txt and write your solutions for Part 1 in this file.
#include
int main() { int x=5, y=4; float a[3] = { 1.0, 2.0, 3.0 };
if (x > y) { float y = 1.0; int a = 6; cout << "x = " << x << ", y = " << y << ", a = " << a << endl; x = 2; }
cout << "x = " << x << ", y = " << y << ", a[0] = " << a[0] << endl; return 0; }
// Count the number of entries in an array that have // both an even index (subscript) and an even value. int count_evens(int arr[], int n) { int count = 0; for (unsigned int i=0; i<n; i+=2) if (arr[i] % 2 == 0) ++count; return count; }
// Given an array of floats, form an array of sums. // Entry i is the sum of the values in locations i..n-1. void subsequence_sum(float arr[], int n, float sums[]) { for (int i = 0; i < n; ++i) { sums[i] = 0.0; for (int j=i; j<n; ++j) sums[i] += arr[j]; } }
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 rest of the assignment before starting to program.
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
You should 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.
You must follow the specifications for the command line, input file, and output file exactly to aid the TAs in grading and ensure you receive full credit. We have provided sample input & output files on the course website, and the validation script on the submission server will also help you check your work.