Question: USING C++ LANGUAGE. Please follow given knowledge and given example of output To convert an algorithm to code in your language of choice. An algorithm

USING C++ LANGUAGE. Please follow given knowledge and given example of output

USING C++ LANGUAGE. Please follow given knowledge and given example of outputTo convert an algorithm to code in your language of choice. An

To convert an algorithm to code in your language of choice. An algorithm is a finite sequence of steps to solve a problem. Algorithms should not be expressed in a specific programming language, but can use common language constructs, such as if, switch, for, while, etc. Here is an algorithm to print the prime factorization of a number. Because prime numbers are defined as positive integers greater than 1 that are divisible only by 1 and themselves, we must restrict the values we use. The algorithm describes reading the number, checking for a valid number, and then printing out the prime factors. - Read in an integer num - If num is negative, print an error message and exit - Set k equal to num - for i=2 to the square root of num - While the k modulo i equals zero - print out i - divide k by i and save the result back k - if k is greater than one, print k Here I've used very English like language. Often you will see more programming language like expressions called pseudocode. YOUR JOB Convert the algorithm above into C,C++, or Java. Add a short menu to see if someone wants to print the prime factorization for another number. Here is a pseudocode representation what that might look like: repeat print "Please enter an integer to determine the prime factorization of: " read into num if ( num 1) print k print "Factor another number?" read into answer until answer == no As you can see, psuedocode is closer to a programming language, but may have some constructs that your language doesn't have (such as a repeat-until... which is the same as a do-while). In addition, we still have a bit to do. We haven't declared variables, we also haven't included any external I/O libraries. We also didn't really say how "no" should be entered... a character, a number, a string... We have decisions to make in our implementation, but that doesn't change the algorithm. Sample output: This program prints the prime factorization of positive integers Please enter a positive integer for prime factorization: 8 The prime factorization of 8 is: 2,2,2 Would you like to try another number (N for no, anything else is yes): y Please enter a positive integer for prime factorization: 121 The prime factorization of 121 is: 11,11 Would you like to try another number ( N for no, anything else is yes): y Please enter a positive integer for prime factorization: 5003 The prime factorization of 5003 is: 5003 Would you like to try another number (N for no, anything else is yes): y Please enter a positive integer for prime factorization: 12345678 The prime factorization of 12345678 is: 2,3,3,47,14593 Would you like to try another number ( N for no, anything else is yes): n

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!