subject

This programming assignment will consist of a C++ program. Your program must compile correctly and produce the specified output.

Please note that your programs should comply with the commenting and formatting described in the Required Program Development Best Practices document that has been discussed in class and is posted to eLearning. Please see this descriptive file on eLearning for more detailsFor purposes of discussion, let’s specify that inputted number as num.

This program asks you to determine a set of prime numbers, given some input from the user. Your program should ask the user to enter an integer between the range of 1 and 100 inclusive.

If num is outside that range, your program should display an error message and re-prompt (ask) for another number (i. e., have an input validation loop, that has been lectured on in class, described in the book and used in previous program assignments).

Your program should then calculate the set of prime numbers less than and equal to num and display this set of prime numbers to the screen and to an output file named PrimeOut. txt.

All your output, both displayed and to the file, must be neatly formatted, 10 numbers per line, and must look like the following examples.

Use a 5-character output field size for the same input and output manipulator for the output display and out file output to the text file. Since the largest candidate prime in a range for the prime set is a three-digit number (100), this should work well.

For the first example, let’s assume the inputted num is a 20.

The display and the output text file must look like:

The primes that are <= 20 are:
2 3 5 711131719

or if the inputted num is 100:
The primes that are <= 100 are:

2 3 5 7111317192329 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97

To solve this problem, your program should have a function called isPrime() that takes an integer as an argument and returns true if the argument is prime or false otherwise. This is an example of a boolean returning function as described in the book in Section 6.9. Note that

taking in a number and determining if it is prime is all this function should do. It should contain no displaying or output to a file statements at all.

The prototype for this function is:

bool isPrime (unsigned number);
Using a function like this can significantly simplify the processing loop in the main program.

It is an example of functional decomposition, also called modular programming. In modular programming, we move the solution of a specific task (in this case: determining if an individual number is prime or not) to a function and then use that function to create the overall solution to our problem.

Functional decomposition is an excellent programming technique and should be used in all of your programs from now on. (Note: for another example of a boolean returning function and how to use it, see p.333 of the book. There the boolean returning function is isEven(int), and you’ll note that it is called inside an "if" statement. You can use your isPrime(int) function in the same way.)

For this problem, it is particularly important to develop your pseudocode before you start programming. Your pseudocode for the main() function might begin as follows:

Open file PrimeOut. txt and verify that it was opened correctly.
Get an unsigned max range number from the user
Verify that number is between 1 and 100 inclusive
for( unsigned number starts at 2; number less than or equal to max range ;

increment number)
If number is prime (call function here)

display number and output number to file End if



End for
Close PrimeOut. txt

You should develop pseudocode for the isPrime(int) function as well. bool isPrime(unsigned number)

{

for (unsigned i starts at 2; i less than or equal to number divided by 2 ; increment i){ if (number modulo i equals 0) {

return false; }

}
return true;

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 11:40
Design a pos circuit that displays the letters a through j on a seven-segment indicator. the circuit has four inputs w, x, y, and z which represent the last 4 bits of the uppercase ascii code for the letter to be displayed. thus, if wxyz = 0001 then "a" will be displayed. (any answer with 22 or fewer gates and inverters, not counting any for the inputs, is acceptable)
Answers: 2
question
Computers and Technology, 23.06.2019 04:31
Which of the following is not a way in which trees benefit the environment? a. they remove a significant amount of carbon dioxide from the atmosphere. b. they remove a significant amount of oxygen from the atmosphere. c. their roots hold soil in place, reducing rates of erosion. d. they remove ozone and particulates from the atmosphere. select the best answer from the choices provided a b c d
Answers: 1
question
Computers and Technology, 23.06.2019 13:30
Font size, font style, and are all aspects of character formatting.
Answers: 2
question
Computers and Technology, 23.06.2019 14:30
Select the correct answer. andy received a potentially infected email that was advertising products. andy is at risk of which type of security threat? a. spoofing b. sniffing c. spamming d. phishing e. typo-squatting
Answers: 2
You know the right answer?
This programming assignment will consist of a C++ program. Your program must compile correctly and p...
Questions
question
English, 17.09.2021 22:00
question
Mathematics, 17.09.2021 22:00
question
Biology, 17.09.2021 22:10
question
Mathematics, 17.09.2021 22:10
question
History, 17.09.2021 22:10
Questions on the website: 13722359