Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ For this assignment you are to implement a program that finds the nth prime number, where the 1st prime number is 2, the 2nd

C++

For this assignment you are to implement a program that finds the nth prime number, where the 1st prime number is 2, the 2nd is 3, the 10th is 29, and so on.

The program should begin by asking the user if there is a value to be processed. If the user responds in the affirmative, the program should prompt the user to input a value, say n, and once that value has been input the program should generate and output the nth prime number. Once this prime number has been output, the program should repeatedly ask the user if there is another value to be processed. Each time the user responds in the affirmative, the program should again prompt the user to input a value for n, and then generate and output the nth prime number.

When the user responds in the negative, the program should output a count of the number of prime numbers that were generated and output, and then terminate.

Your program should include the implementation and use of the following functions.

bool MoreData(); This function is used to determine if there is data to be processed. The first time the function is called it should begin by asking the user if there is a value to be processed. On subsequent calls to the function, the user should be asked if there is another value to be processed.

For both prompts the user is expected to respond by entering Y or N, either uppercase or lowercase. If any other value is input, the function should continuously prompt the user to input a correct response of Y or N until the user does so. If the user responds by entering Y, uppercase or lowercase, the function should return the value true. If the user responds by entering N, uppercase or lowercase, the function should return the value false.

bool IsPrime(int testVal); This function returns the value true if testVal is a prime number, otherwise it returns the value false.

int NthPrime(int n); For the parameter value n, this function returns the nth prime number.

The above function should be used wherever appropriate in the implementation of your program.

Each function should only do what is included in its specification For example, if the specification of a function does not include any inputting or outputting, then the function shouldnt do so. You must also adhere to the specified prototypes.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Database Management Systems Designing And Building Business Applications

Authors: Gerald V. Post

1st Edition

0072898933, 978-0072898934

More Books

Students also viewed these Databases questions

Question

1. Design an effective socialization program for employees.

Answered: 1 week ago