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 02:20
The reset circuit used on the four 3-bit counters analyzed in this activity reset the counts to zero (000). it makes sense for the up-counters to start at zero (000), but the down-counters should start at seven (111). what would you need to change so that the 3-bit binary down counter with j/k flip-flops you just created would reset to seven (111)?
Answers: 1
question
Computers and Technology, 23.06.2019 04:31
Type the correct answer in the box. spell all words correctly. the managing director of a company sends a christmas greeting to all his employees through the company email. which type of network does he use? he uses an
Answers: 1
question
Computers and Technology, 23.06.2019 17:00
What are the 12 colors of the spectrum called?
Answers: 1
question
Computers and Technology, 23.06.2019 18:00
Apunishment or the threat of punishment used to enforce conformity. select the best answer from the choices provided t f
Answers: 1
You know the right answer?
This programming assignment will consist of a C++ program. Your program must compile correctly and p...
Questions
question
Mathematics, 12.08.2020 06:01
question
Mathematics, 12.08.2020 06:01
question
Mathematics, 12.08.2020 06:01
question
Chemistry, 12.08.2020 06:01
question
Mathematics, 12.08.2020 06:01
Questions on the website: 13722363