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:00
You receive an email from an impressive-sounding stranger, professor alexander rothschild renard iii, president of the american institute for scientific political statesmen. he urges you to vote for his presidential candidate choice. this social media red flag is known as
Answers: 1
question
Computers and Technology, 22.06.2019 23:00
Which factor is the most important when choosing a website host? whether customers will make secure transactions the number of email accounts provided the purpose of the website the quality of the host control panel
Answers: 3
question
Computers and Technology, 23.06.2019 19:00
Choose the correct citation for the case which established the "minimum contacts" test for a court's jurisdiction in a case. select one: a. brown v. board of education of topeka, 347 u.s. 483 (1954). b. international shoe co. v. washington, 326 u.s. 310 (1945) c. haynes v. gore, 531 u.s. 98 (2000). d. international shoe co. v. washington, 14 u.s. code 336.
Answers: 1
question
Computers and Technology, 23.06.2019 20:00
Me ajude por favor , coloquei uma senha e não consigo tira-la no chorme
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
Biology, 20.01.2020 08:31
Questions on the website: 13722367