Starting Out With C++: Early Objects (10th Edition)
10th Edition
ISBN: 9780135235003
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 6, Problem 10PC
isPrime Function
A prime number is an integer greater than 1 that is evenly divisible by only 1 and itself. For example, the number 5 is prime because it can only be evenly divided by 1 and 5. The number 6, however, is not prime because it can be divided by 1, 2, 3, and 6.
Write a Boolean function named isPrime, which takes an integer as an argument and returns true if the argument is a prime number, and false otherwise. Demonstrate the function in a complete program.
TIP: Recall that the % operator divides one number by another and returns the remainder of the division. In an expression such as num1 % num2, the % operator will return 0 if num1 is evenly divisible by num2.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
5. A prime number is a number that is only evenly divisible by itself and 1. For example, the
number 5 is prime because it can only be evenly divided by 1 and 5. The number 6, how-
ever, is not prime because it can be divided evenly by 1, 2, 3, and 6.
Write a Boolean function named is_prime which takes an integer as an argument and
returns true if the argument is a prime number, or false otherwise. Use the function in a
program that prompts the user to enter a number then displays a message indicating
whether the number is prime.
6. In another program, use the function you wrote in question 5 to print the prime numbers
between 1 and 100 using for loop.
Computer Science
A value-returning function returns multiple values.
Group of answer choices
True
False
Chapter 6 Solutions
Starting Out With C++: Early Objects (10th Edition)
Ch. 6.2 - Use the following information to answer questions...Ch. 6.2 - Use the following information to answer questions...Ch. 6.2 - Prob. 6.3CPCh. 6.2 - Use the following information to answer questions...Ch. 6.2 - Use the following information to answer questions...Ch. 6.2 - Use the following information to answer questions...Ch. 6.5 - Indicate which of the following is the function...Ch. 6.5 - A) Write the function header for a function named...Ch. 6.5 - What is the output of the following program?...Ch. 6.5 - The following program skeleton asks for the number...
Ch. 6.9 - How many return values may a function have?Ch. 6.9 - Write a header for a function named distance. The...Ch. 6.9 - Write a header for a function named days. The...Ch. 6.9 - Prob. 6.14CPCh. 6.9 - Write a header for a function named lightYears....Ch. 6.11 - What is the difference between a static local...Ch. 6.11 - Prob. 6.17CPCh. 6.11 - Prob. 6.18CPCh. 6.13 - Prob. 6.19CPCh. 6.13 - Write the prototype and header for a function...Ch. 6.13 - Write the prototype and header for a function...Ch. 6.13 - What is the output of the following program?...Ch. 6.13 - The following program asks the user to enter two...Ch. 6.15 - Is it required that overloaded functions have...Ch. 6.15 - What is the output of the following program code?...Ch. 6.15 - What is the output of the following program code?...Ch. 6 - The ____ is the part of a function definition that...Ch. 6 - If a function doesnt return a value, the word...Ch. 6 - If function showValue has the following header:...Ch. 6 - Either a functions ____ or its ____ must precede...Ch. 6 - Values that are sent into a function are called...Ch. 6 - Special variables that hold copies of function...Ch. 6 - When only a copy of an argument is passed to a...Ch. 6 - A(n)_____ eliminates the need to place a function...Ch. 6 - A(n)_____ variable is defined inside a function...Ch. 6 - ____ variables are defined outside all functions...Ch. 6 - _____ variables provide an easy way to share large...Ch. 6 - Unless you explicitly initialize numeric global...Ch. 6 - If a function has a local variable with the same...Ch. 6 - ______ local variables retain their value between...Ch. 6 - The _____ statement causes a function to end...Ch. 6 - ______ arguments are passed to parameters...Ch. 6 - When a function uses a mixture of parameters with...Ch. 6 - Prob. 18RQECh. 6 - When used as parameters, _______ variables allow a...Ch. 6 - Reference variables are defined like regular...Ch. 6 - Reference variables allow arguments to be passed...Ch. 6 - The ________ function causes a program to...Ch. 6 - Two or more functions may have the same name, as...Ch. 6 - What is the advantage of breaking your...Ch. 6 - What is the difference between an argument and a...Ch. 6 - When a function accepts multiple arguments, does...Ch. 6 - What does it mean to overload a function?Ch. 6 - If you are writing a function that accepts an...Ch. 6 - Give an example of where an argument should he...Ch. 6 - How do you return a value from a function?Ch. 6 - Prob. 31RQECh. 6 - Prob. 32RQECh. 6 - The following statement calls a function named...Ch. 6 - A program contains the following function, int...Ch. 6 - Write a function, named timesTen, that accepts an...Ch. 6 - A program contains the following function. void...Ch. 6 - Write a function named getNumber, which uses a...Ch. 6 - Write a function named biggest that receives three...Ch. 6 - Prob. 39RQECh. 6 - Markup Write a program that asks the user to enter...Ch. 6 - Celsius Temperature Table The formula for...Ch. 6 - Falling Distance The following formula can be used...Ch. 6 - Kinetic Energy In physics, an object that is in...Ch. 6 - Winning Division Write a program that determines...Ch. 6 - Shipping Charges The Fast Freight Shipping Company...Ch. 6 - Prob. 7PCCh. 6 - Lowest Score Drop Write a program that calculates...Ch. 6 - Star Search A particular talent competition has...Ch. 6 - isPrime Function A prime number is an integer...Ch. 6 - Present Value Suppose you want to deposit a...Ch. 6 - Future Value Suppose you have a certain amount of...Ch. 6 - Stock Profit The profit from the sale of a stock...Ch. 6 - Multiple Stock Sales Use the function that you...Ch. 6 - Order Status The Middletown Wholesale Copper Wire...Ch. 6 - Overloaded Hospital Write a program that computes...Ch. 6 - Population In a population, the birth rate is the...Ch. 6 - Transient Population Modify Programming Challenge...Ch. 6 - Using FilesHospital Report Modify Programming...Ch. 6 - Group Project 20. Using FilesTravel Expenses This...
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Decription keyarrow_forwardConvert radians into degrees Write a function in Python that accepts one numeric parameter. This parameter will be the measure of an angle in radians. The function should convert the radians into degrees and then return that value.arrow_forwardpython3 program In mathematics, a harshad number is an integer that is evenly divisible by the sum of its digits. For example, 18 is a harshad number because 1 + 8 = 9 and 18 is divisible by 9. Write a function that returns the number of harshad numbers between 1 and 1000000.arrow_forward
- A function can return another function. True Falsearrow_forwardtrue false void ffx() is a function with no return value void ffx() is a function with no argument int ffx(char x) is a function with int return value int ffx(char *x) is a function with parameter passed by reference char ffx( int x) is a function with int return value int ffc(char &x) is a function with parameter passed by referencearrow_forwardUSE C++programming languagearrow_forward
- Predefined Function: ceil(), floor(), rand(), srand0 1. Create a program that will round off a given number. Example Program Output: Enter a number to be round of: 10.5 Round off value: 10 Enter a number to be round of: 10.6 Round off value: 11 Enter a number to be round of: 10.4 Round off value: 10 Enter a number to be round of: 11.5 Round off value: 12arrow_forward***IN PSUEDOCODE ONLY - not a real programming language!!*** Question:A prime number is a number that is only evenly divisible by itself and 1. For example, the number 5 is prime because it can only be evenly divided by 1 and 5. The number 6, however, is not prime because it can be divided evenly by 1, 2, 3, and 6. Design a Boolean function called isPrime, that accepts an integer as an argument and returns True if the argument is a prime number, or False otherwise. Use the function in a program that prompts the user to enter a number and then displays a message indicating whether the number is prime. The following modules should be written: - getNumber, that accepts a Ref to an integer, prompts the user to enter a number, and accepts that input - isPrime, that accepts an integer as an argument and returns True if the argument is a prime number, or False otherwise - showPrime, that accepts an integer as an argument , calls isPrime, and displays a message indicating whether the…arrow_forwardA prime number is a number that is only evenly divisible by itself and 1. For example, the number 5 is prime because it can only be evenly divided by 1 and 5. The number 6, however, is not prime because it can be divided evenly by 1, 2, 3, and 6. Design a Boolean function called isPrime, that accepts an integer as an argument and returns True if the argument is a prime number, or False otherwise. Use the function in a program that prompts the user to enter a number and then displays a message indicating whether the number is prime. The following modules should be written: getNumber, that accepts a Ref to an integer, prompts the user to enter a number, and accepts that input isPrime, that accepts an integer as an argument and returns True if the argument is a prime number, or False otherwise showPrime, that accepts an integer as an argument , calls isPrime, and displays a message indicating whether the number is prime The main module, that will call getNumber and showPrimearrow_forward
- Function Name: compliments Parameters: answer1 - a boolean (True or False) representing whether the user is "smart" answer2 - a boolean (True or False) representing whether the user is "awesome" answer3 - a boolean (True or False) representing whether the user is "fun" Description: Write a function that outputs a string of compliments based on the adjectives selected by the inputs. Use the inputs True and False. The function should return the string “You are” concatenated with the compliments that are true. The three compliments should be: "smart" "awesome" and "fun". If none of the compliments are true, print the string “Goodbye.” instead. Test Cases: >>>compliments(True, True, True) You are smart awesome fun. >>>compliments(False, True, False) You are awesome. >>>compliments(False, False, False) Goodbye.arrow_forwardPlease answer it in Python Write a palindrome function that takes a word as an argument and returns a Boolean indicating whether the word is a palindrome. A palindrome is a word that remains the same when read from right to left instead of the usual order from left to right. Example: palindrome('here') is True but palindrome('go') is False. Write a function word_allows taking as an argument a word and a list of forbidden words, and returning True if the word is allowed, and False if the word is prohibited. Example: word_allows('fric', ['sous', 'fric', 'thune', 'ble']) is False word_allows('silver', ['sous', 'fric', 'thune', 'ble']) is truearrow_forwardoperators are overloaded when there are too many variables in the function.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
.2: Function Parameters and Arguments - p5.js Tutorial; Author: The Coding Train;https://www.youtube.com/watch?v=zkc417YapfE;License: Standard Youtube License