Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

Draw a flowchart, using Microsoft Visio or LucidChart, to document the logic required to complete this program. Save the flowchart as a PDF file.

Draw a flowchart, using Microsoft Visio or LucidChart, to document the logic required to complete this program. Save the flowchart as a PDF file.
• Develop a C++ program, following the logic in your flowchart, to find, display, and save the first N prime numbers.
• Prime numbers are positive whole numbers that are evenly divisible only by 1 and themselves. The smallest prime number is 2, and the largest is yet to be discovered.
• Identify and list the first N prime numbers, starting with 2 (2 is a prime number), where N is a number obtained from the user. This number N must be in the range of 30 to 2000, inclusive.
• Develop a function to test whether a number is prime or not. The function should accept a single whole number to test and return a value of true if the number is prime, and false if it is not. Within the function, test the number’s primeness by attempting to divide it by all positive integers between 2 and half of itself (e.g. divide 15 by 2,3,4,5,6,7). If any of the divisions are even (having no remainder), then the number is NOT prime. If NONE of the divisions are even, then the number IS prime. Note that negative numbers, zero, and one are NOT prime. The prototype for this function should be “bool isPrime( int x );”
• Display the first 20 prime numbers on the console, and save all N prime numbers to a file named “primes.txt”.
• Develop a separate function to format the output for a single prime number. Use this function to format the output going to the console as well as the output going to the data file. The function must accept two whole numbers: a sequence number and the prime number. The prototype for this function should be “string formatPrime(int sequence, int prime);”. The function must return a string formatted as “Prime #6 = 13”.

Step by Step Solution

3.44 Rating (151 Votes )

There are 3 Steps involved in it

Step: 1

PGM STARTS include include include u... blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Accounting Information Systems

Authors: Ulric J. Gelinas, Richard B. Dull

10th edition

9781305176218, 113393594X, 1305176219, 978-1133935940

More Books

Students explore these related Programming questions