CS 331, Spring 2008 Assignment #10 (Extra Credit): 10 points Due Date: Wednesday, 5/07/08. This assignment is worth a maximum of 10 points of extra credit. The Chapman Lab computers have a variety of languages available in both Linux and Windows. Other compilers and interpreters can be downloaded as referenced in the textbook and class presentations. All programs must be well documented with comments and complete test results must be provided to support your answers. (5) 1. Since the dawn of the computer age, Real Programmers have dreamt of creating self-replicating programs as an analogue to the process of DNA replication in living organisms. A quine is a type of self-replicating program which prints out an exact copy of its source code using no input data. Unlike viruses or worms, which replicate executable code by using system functions or applications, a quine merely replicates its source code. Write a self-replicating quine program in C/C++ and explain how it works. Hand in the source code and the output from running the program. Partial credit will be given for demonstrating an existing program if you explain how it works and provide complete references to the original source.** (5) 2. Write a self-replicating (quine) program in any language studied in class other than C/C++ and explain how it works (See #1 above). Comments are not required in the source code for this program. Hand in the source code and the output from running the program. Partial credit will be given for demonstrating an existing program if you explain how it works and provide complete references to the original source.** (5) 3. The following program was the subject of Problem 2, HW #8: #include using namespace std; main() { int I=0; cout << I++ << endl << --I << endl << I-- << endl << (I=5) << endl; return 0; } Depending on the C++ compiler used and the options selected, a variety of outputs may be obtained including: "0 0 0 5", "3 3 5 5", "3 4 5 4", and "4 5 5 4". Which of these, if any, is the correct result according to the C++ standard? Explain your answer by citing the relevant section numbers of the standard which support your answer and explain how the standard applies to this particular program to produce the result conforming to the standard. Your answer should include an explanation of how the result is produced, including an analysis of the assembly code. For Visual Studio, assembly code can be obtained by disassembling the machine code using: Debug->Step Into followed by Debug->Windows->Dissasembly. Every compiler has a similar means to view symbolic assembly code. For GNU command line users, use the -S option to produce an assembly listing and use gdb to step into the executable in debug mode. See the course website References for a link to the C++ standard.** (5) 4. Consider the C++ operators for addition (+), multiplication (*), boolean AND (&&) and boolean OR (||). Write a C++ test program which determines the ACTUAL relative precedences of these 4 operators by the evaluation of a series of test expressions. The program output should clearly state the order of precedence for the operators as determined by the evaluation of the test expressions in the program. Hint: Each test expression must produce different results if the precedence between two operators is reversed. Does the output of your program agree with the normal precedences of the C++ operators.** (5) 5. Develop a test program in any language studied in class (other than C/C++) to determine whether the language uses short-circuit evaluation of boolean expressions. (See Problem 5, HW #7). If short-circuit evaluation is used, determine whether the language also supports a full evaluation of boolean operators and demonstrate their use. Hand in source program and results of test runs and state what compiler was used.** (5) 6. Using any of the functional languages studied in class, write and test a function that returns the union of two simple list parameters that represent sets. Set union differs from list concatenation because the elements in a set are unique.** (5) 7. Write a simple Piglatin program in any language studied in class except C/C++. The program should prompt for a word, translate it to Piglatin and output the Piglatin word. Hand in the source program and test output that you use to verify the correct operation of the translator. There are many Piglatin dialects. The simple dialect used for this problem translates an English word to Piglatin as follows: (1) move all consonants preceding the first vowel (a,e,i,o,u) to the end of the word and append "ay"; (2) if the word contains no vowels, e.g. "rhythm", treat 'y' as a vowel; (3) if the word contains neither vowels nor a 'y', simply append "ay" to the end of the word.** (5) 8. Create a simple web survey form displaying your name and a list of your 5 favorite programming languages. Provide an input mechanism for a user to input their favorite language, which need not be from your list. Respond to the user's choice in one of two ways according to whether the language is on your list or not. If the language is on your list, the response should be "L is AWESOME!", where L is the language. Otherwise, reply with "L is lame." Hand in the browser output along with the URL and source file(s) for your web page. To access the survey online, it must reside on a web server. Ask your instructor if you need help finding a place to set up a web page.** **For full credit, hand in well commented source listings and clearly labelled output from test runs exactly as produced by the program.