Concept explainers
Overview
In this assignment, the student will write a C++ program that identifies a non-negative integer as prime, composite, or neither and provides the unique prime factorization for the composite case.
When completing this assignment, the student should demonstrate mastery of the following concepts:
· Decision Making (if, else)
· Iteration (for, while)
· Number Theory (Prime Factors)
· Advanced Loop Variants
Assignment
Write a C++ program that prompts the user for a single integer value. After receiving the value, perform an analysis to determine if the integer is prime, composite or neither. If you are not sure what this means, you need to research the appropriate topics in number theory and consider what the
In the event that you determine the provided integer is composite, provide a listing of the unique prime factorization for that integer as illustrated in the below examples.
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 1 images
- Transcribed Image Text Create a program that allows the user to do some basic functions. First, ask the user if they would like to find out sqrt, log or factorial of a number, then return the results. Here is the sample output: Welcome to the simple math helper. What would you like to calculate? 1. Sqrt 2. Log 3. Factorial > 1 Enter the number to sqrt: >9arrow_forwardJava:arrow_forwardThis pseudocode segment is intended to compute and display the average grade of three tests for any number of students. The program executes until the user enters a negative value for the first test score. Debug the pseudocode by rewriting it to achieve its intended purpose. start Declarations num test1 num test2 num test3 num average housekeeping() while test1 >= 0 mainLoop() endwhile endOfJob() stop housekeeping() output "Enter score for test 1 or a negative number to quit" return mainLoop() output "Enter score for test 2" input test2 average = (test1 + test2 + test3) / 3 output "Average is ", average output "Enter score for test 1 or a negative number to quit" input tesst1 return endOfJob() output "End of program" returnarrow_forward
- The Billy Goat Fast-Fast Food restaurant sells the following products: Product Price ($) Cheeseburger 2.49 Pepsi 1.00 Chips 0.59 Design the Python Program for an application that allows a user to enter an ordered item continuously until a sentinel value is entered. After each item, display its price or the message “Sorry, we do not carry that” as output. After all items have been entered, display the total prices for the order.arrow_forwardTrue or False ___(4) In a while loop, the body of the loop has to be executed at least once whether the test is true or not. ___(5) In Java a while loop can be changed to a for loop and vice versa. ___(6) Java statement !( x / 3 = = 6 ) || y*3 = = -6 ; evaluates to false if x=19 and y= -2arrow_forwardTest2_Q2 Test Content Question 1 16 Points Write a JAVA program using loop that asks the user to input seven integer numbers representing. the humidity level in Bahrain for each of the day of the week (1 represents Sunday, 2 represents Monday, etc.). The program should find and display the following: 1- the maximum humidity level and the day on which it was recorded. 2- the number of days the humidity level was lower than 40. *Assume that there is only one maximum humidity level. Sample Input / Output Enter the humidity for 1 week: 57 61 37 49 50 62 38 The Maximum Humidity is 62 for the Week Day = 6 The no. of days the humidity level < 40 is 2 Note: Your answer should follow the given sample input / output.arrow_forward
- Programming is Javaarrow_forwardHELP NEEDED ASAP! Language: JAVA Write a program that prompts the user for a value greater than 10 as an input (you should loop until the user enters a valid value) and finds the square root of that number and the square root of the result, and continues to find the square root of the result until you reach a number that is smaller than 1.01. The program should output how many times the square root operation was performed.arrow_forwarduser_input input () while user input != 'end': try: #Possible ValueError divisor = int (user_input) if divisor < 0: = except: else: # Possible ZeroDivisionError print (20 // divisor, end=' ') except ValueError: print ('v', end='') except ZeroDivisionError: print ('z', end=' ') # Possible NameError # compute () is not defined print (compute (divisor), end=' ') print ('x', end=' ') print ('OK') Type the program's output user_input input () # // truncates to an integer 2 Input five 2 0 -8 end Outputarrow_forward
- Hands-On Activity 4-4 BuzzButtons is a novelty item company manufacturing personalized lapel buttons that buzz randomly. The buttons are marketed as a conversation starter, and the company's slogan is "It starts the buzz!" The owner is promoting his buttons by offering them at 99 cents each. He wants you to design a program asking the user for his or her name for the button, an e-mail address, and the number of buttons to order. The program should then add a 6% sales tax and a flat shipping rate of $2.00. The program displays the information the user enters as well as the button price total, sales tax amount, shipping amount, and order total. The company contacts the user by e-mail later for shipping address information. Using pseudocode, design an algorithm that asks the user for the number of fixed-price items to order, adds sales tax and flat-rate ship- ping, and displays the result. Save your pseudocode file in Notepad as buzzButtons.txt.arrow_forwardInstructions The files provided in the code editor to the right contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly. An example of the program is shown below: Enter an integer >> 13 Enter a second integer >> 24 Enter a third integer >> 101 The sum of 13 and 24 is 37 The sum of 24 and 101 is 125 The sum of 13 and 101 is 114 The difference between 13 and 24 is -11 The difference between 24 and 101 is -77 The difference between 13 and 101 is -88 Task 1: The DebugThree3 class compiles without error. Task 2: The add() method adds two integers. Task 3: The subtract() method subtracts two integers. Task 4: The DebugThree2 program accepts user input and displays the correct output.arrow_forwardInstructions The files provided in the code editor to the right contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly. An example of the program is shown below: Enter an integer >> 13 Enter a second integer >> 24 Enter a third integer >> 101 The sum of 13 and 24 is 37 The sum of 24 and 101 is 125 The sum of 13 and 101 is 114 The difference between 13 and 24 is -11 The difference between 24 and 101 is -77 The difference between 13 and 101 is -88 Task 1: The DebugThree3 class compiles without error. Task 2: The add() method adds two integers. Task 3: The subtract() method subtracts two integers. Task 4: The DebugThree2 program accepts user input and displays the correct output.arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr