Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!