CS 165 Final Project – December 12, 2017
Cs 165 02final Project50 Pointsduetuesday December 12 2017 No Late
Write a program that determines prime numbers, identifies emirps, displays the first 100 emirps in a ListBox, and includes user interaction through a TextBox to check for emirps. The program must contain methods for checking primality, reversing integers, and writing output to a file, with accompanying comments and an extra credit option of outputting the emirps to a file in addition to the ListBox.
Paper For Above instruction
The current project is designed to develop proficiency in programming with C# and understanding of number theory concepts like prime and emirp numbers. This involves writing functions to check if a number is prime, reversing integers, generating emirps, and displaying results in a user interface. The project also emphasizes code clarity and proper documentation, including comments at the beginning of the program that specify the developer’s name, class details, section, assignment description, due date, and a brief overview of program functionality.
The first core function required is a method to verify whether a given positive integer is prime. Since 2 is the only even prime, the function efficiently checks divisibility by 2 and then tests odd numbers up to the square root of the number. This optimization reduces unnecessary calculations, especially useful when generating a sequence of prime numbers. The method returns true if the number is prime and false otherwise.
The second method involves reversing an integer. The process converts the number to a string, reverses the string, and then converts it back to an integer. This can be achieved efficiently by iterating over the string characters from the end to the beginning, appending each character to a new string. The reversed integer is then used to check for emirps.
An emirp is defined as a prime number whose reversal is also prime, and it is different from itself (i.e., not palindromic). The program must generate and list the first 100 emirps, displaying these in a ListBox control within a graphical user interface. This requires iterating through numbers, checking their primality, reversing them, and verifying if both the original and reversed numbers are prime to qualify as emirps.
Additionally, the program must include a feature allowing the user to input a positive integer in a TextBox. When the user submits the input, the program should determine whether this number is an emirp, displaying the result accordingly. This interactive component enhances usability and demonstrates the application's flexibility.
To facilitate extra credit, the project requires writing the first 100 emirps to an output file in addition to displaying them in the ListBox. This involves creating a method that extracts the ListBox values and writes them to a text file, ensuring the output includes the same sequence of emirps generated for display.
Overall, this project integrates fundamental programming concepts such as loops, conditionals, string manipulation, file I/O, and user interface programming, providing a comprehensive learning experience. Proper commenting, efficient code structure, and correct implementation of algorithms are critical for success.
References
- Crandall, R., & Pomerance, C. (2005). Prime Numbers: A Computational Perspective. Springer.
- Knuth, D. E. (1997). The Art of Computer Programming, Volume 2: Seminumerical Algorithms. Addison-Wesley.
- Lehmer, D. H. (1931). On the distribution of primes. Annals of Mathematics.
- Miller, G. L. (1976). Riemann's hypothesis and tests for primes. Journal of the American Mathematical Society.
- Rivest, R. L., Shamir, A., & Adleman, L. (1978). A method for obtaining digital signatures and public-key cryptosystems. Communications of the ACM.
- Silverman, J. H. (2004). The Arithmetic of Elliptic Curves. Springer.
- Hamming, R. W. (1986). Coding and Information Theory. Pearson Education.
- Hoffstein, J., Pipher, J., & Silverman, J. H. (2008). An Introduction to Mathematical Cryptography. Springer.
- Schneier, B. (2015). Applied Cryptography: Protocols, Algorithms, and Source Code in C. Wiley.
- Lehmann, D., & Casella, G. (1998). Theory of Point Estimation. Springer.