244: PRIMES

PRIMES: Generate & Recognize Primes & Palindromic Primes Efficiently & Use a Library

- The solution folder and solution should be called "PRIMES" (this is the folder you hand in).
      It contains THREE projects:
        1. The console project (and project folder) should be called "PRIMECON".
        2. The windows project (and project folder) should be called "PRIMEWIN".
        3. The library project (and project folder) should be called "PRIMELIB".

- Code for Readability!(guidelines) (readability ==> maintainability ==> $$)
- Follow these directions to SUBMIT a folder called "PRIMES" to your class account
- Follow these directions to create a C# console program.  


Use methods and refactoring to make your code modular and understandable.

Use arrays NOT lists.



GRAY - PART a: Create a SOLUTION called "PRIMES". PRIMES will contain THREE projects: In solution Explorer: right-click on solution Add => Create a library called 'PRIMELIB' Create a console project called 'PRIMECON' Create a windows project called 'PRIMEWIN' Set Startup Project => Current Selection (makes selected project in solution explorer the active project to execute)
In PRIMELIB class library: ------------------------- Create a method called "IsItPrime" IN: value to evaluate OUT: true/false return Determine if a value is prime and returns true or false. Should be efficient and documented to explain its efficiency. ** (make it work correctly first - can improve efficiency in part 2) Should be callable from either Console or Windows program.
primes

In PRIMECON Project ---------------------------- In Main - Prompt the user for a number, n (1 to 10 million) (fully error, range check - TryParse) - Prompt the user for a number, r (2 to 10 thousand) (fully error, range check - TryParse) - Create a loop that will generate n random numbers (0 - r inclusive), and, using your library method, determine if the random number is prime. - Place each generated prime in an array. (how big?) - Time it and report # of generated primes and how long it took to generate. - While user keeps wanting to print results from the generated array Prompt for start and stop index. - tell user the valid range - error check request - print out the indicated subset of the array. - more? Until user says No (0 No, 1 Yes)




BLUE - PART b: In PRIMELIB class library: ------------------------- Create a method called "GeneratePrimes" IN: size of array, n OUT: array filled with first n primes Create an array of size specified & fill with n primes Use YOUR library method you created in part 1 -- if you modify, DOCUMENT CHANGES -- regression test CONSOLE!! Create a method called "IsItPalindromic" -- Assume base 10 ! IN: value to evaluate OUT: true/false return Determine if a value is palindromic and returns true or false. Should be efficient and documented to explain its efficiency. Should be callable from either Console or Windows program. In PRIMEWIN Project ------------------------------------ Make the form's Text Property = LASTFM (name) TextBoxes, Buttons, ListBoxes and controls as needed - Create UI, appropriately named objects and appropriate property values - btnPrime click gets "n" (number of primes - check? disable button until text input?) and call library method that you create to generate first n prime numbers and store in array that is returned. The execution time should be reported. - btnListPrimes click gets range of index values from user (check? disable button?), and prints that range (use array indexes - tell user legal range) of primes to the list box with its index - On btnListPalPrimes click gets range of index values from user (check? disable button?) and and prints that range(use array indexes - tell user legal range ) of primes to the list box IF THEY ARE PALINDROMIC along with the index. Uses your library method that you created. - btnClear clears all - btnExit exits with confirmation


First 168 primes (all primes < 1000) (palindromes in red) are:
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 619 631 641 643 647 653 659 661 673 677 683 691 701 709 719 727 733 739 743 751 757 761 769 773 787 797 809 811 821 823 827 829 839 853 857 859 863 877 881 883 887 907 911 919 929 937 941 947 953 967 971 977 983 991 997 20 palindromic primes under 1000... next palindromic prime: 10301 (1,263rd prime)

Prime number lists   ||   Big Primes - Lists   ||   The Prime Pages   ||   Wikipedia Primes   ||   Wikipedia PalPrimes