Programming Assignment 3 PDF

Title Programming Assignment 3
Course Object-Oriented Programming I
Institution Baruch College CUNY
Pages 2
File Size 73.3 KB
File Type PDF
Total Downloads 79
Total Views 150

Summary

Download Programming Assignment 3 PDF


Description

Object-Oriented Programming I CIS 9310

Fall 2019

Programming Assignment 3

For this assignment you are to implement two prime number functions, and then use these two functions to implement a larger program/application. One of the prime number function, IsPrime(), tests integer values to determine if they are prime. The prototype for the function is: bool IsPrime(int num); This function tests the value of num to determine if it is a prime number. If num is prime, then the function returns true, otherwise it returns the value false. The second prime number function, having the prototype int Prime(int n); returns the nth prime number, where 2 is the first prime, 3, the second, 5 the third, and so on. For example, the expression Prine(5), returns the value 11, since 11 is the 5th prime number. Using the two prime number functions you are to then implement a program that repeatedly offers the user the following three menu options: F: Find the nth prime number T: Test a value to see if it is prime Q: Terminate the program The user selects an option by entering the associated letter, in uppercase or lowercase. Any other input should lead to a prompting of the user for a correct input. Depending on the option selected by the user program should perform the action described in the following. In response to a menu option input of F the program prompts the user to enter a positive (greater than 0) value. If a valid value is input, then the program, treating that value as its ordinal number equivalent, should output the prime number corresponding to that value. For example, an input value of one should result in the output of 2, the first prime number; an input of 2 results in the output of 3; and so on. If the user inputs an invalid number value (i.e., zero or a negative number) the program should output an appropriate error message, but take no additional action for the F option

For a menu option input value of T the program prompts the user to enter a non-negative value (i.e., a value that is greater than or equal to zero), after which the program outputs a message indicating whether or not the input value is prime. The program responds to an invalid value with an appropriate message, and no additional action for the T option. An input of Q causes the program to terminate.

Due Date: November 12, 2019...


Similar Free PDFs