Problem #2 Write a Simple Calculator Winita a program namad Calculator. This program must have functions: Failure to follow these requirements will result in a falling grade on the assignment avantpasses all tests: main Controls the fow of the program maing only needs the following two lines of code (all other methods are called in the usarOutputo function one two useringut usruutta) usernout Asks the user to enter two numbers. Maica certain with a loop) at the second number is not zara ads Accepts two numbers, ratums the sum "subtract Accepts two numbers, retums the ofference of the first mber minus the second *multply Accepts two numbers, retums the product *divide Accepts two numbers, ratume the quotient of the first number divided by the second module Accepts two numbers, ratume the modulo of the first number divided by the second number exponent Accepts two numbers, retume the first number raised to the power of the second number "userOutput Accepts the two numbers from main and cells the other functions to print their Make your output look like mine (dentical formatting of output, but work with any numbers entered Remember that you must handle any valla numanc input. Be sure to test with 0, negative, and positive integers You are not expected to handle the input of strings > Enter your first number: 5 Enter your second number (ather than zaro): 0 Cannot have for the second number Enter your second number (other than zar): 5.0 5.0-5.0=10.0 50-50=0.0 5.0 5.0 = 25.0 5.0/5.0 = 1.0 5.0% 5.0 0.0 5.05.0=3125.0

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter7: User-defined Simple Data Types, Namespaces, And The String Type
Section: Chapter Questions
Problem 7PE
icon
Related questions
Question

PHYTON

Problem #2 Write a simple Calculator #
Write a program named Calculator. This program must have 9 functions: Failure to follow these
requirements will result in a falling grade on the assignment even if it passes all tests:
"main) Controls the flow of the program main only needs the following two lines of code (all other
methods are called in the userOutput() function):
one, two = userinputo
userOutput(one, twa)
usernout) Asks the user to enter two numbers. Make certain (with a loop) that the second number
is not zara
add Accepts two numbers, returns the sum
*subtract Accepts two numbers, retums the difference of the first number minus the second
number
*multiply Accepts two numbers, retums the product
*divide Accepts two numbers, returns the quotient of the first number divided by the second
number
*modula) Accepts two numbers, returns the modulo of the first number divided by the second
number
*exponent) Accepts two numbers, returns the first number raised to the power of the second
number.
"userOutput Accepts the two numbers from main and calls the other six functions to print their
results
Make your output look like mine (identical formatting of output), but work with any numbers entered.
Remember that you must handle any valla numeric input. Be sure to test with O, negative, and
positive integral
You are not expected to handle the input of strings.
Enter your first number: 5
Enter your second number (ather than zaro): 0
Cannot have 0 for the second number
Enter your second number (ather than zaro): 5.0
5.0 5.0 10.0
5.0 - 5.0 = 0.0
5.0 5.0 25.0
5.0/5.0 = 1.0
5.0 % 5.0 = 0.0
5.05.0=3125.0
Transcribed Image Text:Problem #2 Write a simple Calculator # Write a program named Calculator. This program must have 9 functions: Failure to follow these requirements will result in a falling grade on the assignment even if it passes all tests: "main) Controls the flow of the program main only needs the following two lines of code (all other methods are called in the userOutput() function): one, two = userinputo userOutput(one, twa) usernout) Asks the user to enter two numbers. Make certain (with a loop) that the second number is not zara add Accepts two numbers, returns the sum *subtract Accepts two numbers, retums the difference of the first number minus the second number *multiply Accepts two numbers, retums the product *divide Accepts two numbers, returns the quotient of the first number divided by the second number *modula) Accepts two numbers, returns the modulo of the first number divided by the second number *exponent) Accepts two numbers, returns the first number raised to the power of the second number. "userOutput Accepts the two numbers from main and calls the other six functions to print their results Make your output look like mine (identical formatting of output), but work with any numbers entered. Remember that you must handle any valla numeric input. Be sure to test with O, negative, and positive integral You are not expected to handle the input of strings. Enter your first number: 5 Enter your second number (ather than zaro): 0 Cannot have 0 for the second number Enter your second number (ather than zaro): 5.0 5.0 5.0 10.0 5.0 - 5.0 = 0.0 5.0 5.0 25.0 5.0/5.0 = 1.0 5.0 % 5.0 = 0.0 5.05.0=3125.0
Problem #1 Problem #5 Revisit the MixColors #
Take your answer from Week 3 Wednesday for the MixColors program. We will split this into
methods. Write a program named ColorFunction that does exactly the same thing but has the
following three functions:
*main(): This function will ask the user to enter two primary colors, and pass these values to the
function mixColors(). It will then accept a return from mixColors().
*mixColors(): This function accepts two primary colors and determines the created secondary color.
This color is returned. If it was not valid, return the string "not valid".
*printValue(): This void function accepts a single string of the secondary color or "not valid" and
prints the color or the message "You did not enter two primary colors".
Sample Output Run #1
Enter the first primary color (small letters): red
Enter the second primary color (small letters): blue
You will get purple
Sample Output Run #2
Enter the first primary color (small letters): red
Enter the second primary color (small letters): red
You did not enter two primary colors
NOTE: Both this program and the one from week 3 get identical output, but programs with small
functions like this are easier to maintain and understand.
Transcribed Image Text:Problem #1 Problem #5 Revisit the MixColors # Take your answer from Week 3 Wednesday for the MixColors program. We will split this into methods. Write a program named ColorFunction that does exactly the same thing but has the following three functions: *main(): This function will ask the user to enter two primary colors, and pass these values to the function mixColors(). It will then accept a return from mixColors(). *mixColors(): This function accepts two primary colors and determines the created secondary color. This color is returned. If it was not valid, return the string "not valid". *printValue(): This void function accepts a single string of the secondary color or "not valid" and prints the color or the message "You did not enter two primary colors". Sample Output Run #1 Enter the first primary color (small letters): red Enter the second primary color (small letters): blue You will get purple Sample Output Run #2 Enter the first primary color (small letters): red Enter the second primary color (small letters): red You did not enter two primary colors NOTE: Both this program and the one from week 3 get identical output, but programs with small functions like this are easier to maintain and understand.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 2 images

Blurred answer
Knowledge Booster
Types of Function
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
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,