C++ for Engineers and Scientists

4th Edition

ISBN: 9781133187844

Author: Bronson, Gary J.

Publisher: Course Technology Ptr

*expand_more*

*expand_more*

*format_list_bulleted*

Question

Help.

Expert Solution

Trending nowThis is a popular solution!

Step by stepSolved in 2 steps

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

(Numerical) Heron’s formula for the area, A, of a triangle with sides of length a, b, and c is A=s(sa)(sb)(sc) where s=(a+b+c)2 Write, test, and execute a function that accepts the values of a, b, and c as parameters from a calling function, and then calculates the values of sand[s(sa)(sb)(sc)]. If this quantity is positive, the function calculates A. If the quantity is negative, a, b, and c do not form a triangle, and the function should set A=1. The value of A should be returned by the function.

*arrow_forward*

An integer number is said to be a perfect number if its factors, including 1 (but not the number itself), sum to the number. For example, 6 is a perfect number because 6 = 1 + 2 + 3. Write a function named perfect that determines if parameter number is a perfect number or not. Use this perfect function in a program that determines and prints all the perfect numbers between 1 and 1000.Also print the factors of each perfect number to confirm that the number is indeed perfect.

*arrow_forward*

A. The following code in the function "is_prime" attempts to examine a number and return whether the number is prime (i.e. it has no factors besides 1 and itself). It has a "Boolean Flag" called 'prime', however, the boolean logic is not implemented correctly, so the function won't always return the correct answer.
# This function determines whether an integer is prime.def is_prime(n):prime = Truefor i in range(2, n): if n2 % i == 0: prime = Falseelse: prime = truereturn prime
In what cases does the function report an incorrect answer?
How can the code be fixed for it to always report the correct answer?
Write your answers as "comments" and the fixed code as a separate python file

*arrow_forward*

An integer number is said to be a perfect number if its factors, including 1 (but not the number itself), sum to the number. For example, 6 is a perfect number because 6 =1 + 2 + 3. Write a function perfect that determines if parameter number is a perfect number. Use this function in a program that determines and prints all the perfect numbers between 1 and 1000. Print the factors of each perfect number to confirm that the number is indeed perfect. Challenge the power of your computer by testing numbers much larger than 1000.

*arrow_forward*

This is a programming assignment. You can use any programming language. Program a GeneticAlgorithm to find an integer number between 0 and 31 that maximizes the function f (x) = x2.The initial procedure is given as below.• Population size: 6• Crossover probability: 100%• Mutation probability: 5%• Terminating criteria:o When your program produces an average of candidates is equal to or greater than29, then you can accept it as a terminating condition.• Fitness function:o You can use the function itself (f (x) = x2)as your fitness function.1. For the 1st generation, you need to print the process and result of selection, crossover, andmutation operation.you need to print the corresponding integer values and bits (binary values)of selection, crossover, and mutation operation. You also need to decide andprint the crossover point and the mutation point.2. From the 2nd generation, you do not have to print all results of selection, crossover,mutation operations. You can just print the result…

*arrow_forward*

Write a function that asks the user for their birthday month and day and then the function should call a nested function to find out the person’s zodiac sign. Test your program with some user input. Aries: March 21 - April 19 Taurus: April 20 – May 20 Gemini: May 21- June 21 Cancer: June 22- July 22 Leo: July 23 – August 22 Virgo: August 23 – September 22 Libra: September 23 – October 23 Scorpio: October 24 – November 21
Sagittarius: November 22 – December 21 Capricorn: December 22 – January 19 Aquarius: January 20 – February 18 Pisces: February 19 – March 20

*arrow_forward*

Define a function hypotenuse that calculates the hypotenuse of a right triangle when the other two sides are given. The function should take two double arguments and return the hypotenuse as a double. You can use the sqrt function from the cmath library. Use this function in a program to determine the hypotenuse for each of the following triangles:
Triangle Side 1 Side 2
1 3.0 4.0
2 5.0 12.0
3 8.0 15.0

*arrow_forward*

Question 6
# This function checks whether a given number is even or not
def isEven(number):
"""
what it takes?
a number
what it does?
determines if a number is even
what it returns?
if even, return 1
if odd, return -1
"""
# your code goes in here
defisEven(number):
#check if the number is divisible by 2 by checking the remainder.
if number % 2==0:
#If remainder is 0, then its divisble by 2 and an even number
#hence return-1
return1
else:
#if remainder is not 0, it'll be 1, so its NOT divisible by 2 and its an odd number
#hence return -1
return-1
Test case for question 6
try:
if isEven(5) == -1:
score['question 6'] = 'pass'
else:
score['question 6'] = 'fail'
except:
score['question 6'] = 'fail'
isEven(5)

*arrow_forward*

The following formula can be used to determine the distance an object falls due togravity in a specific time period:d =112 gt2The variables in the formula are as follows:• d is the distance in meters,• g is 9.8,• and tis the time in seconds that the object has been falling.Write a function named fall i ngDi stance that accepts an object's falling time (in seconds)as an argument. The function should return the distance, in meters, that the object hasfallen during that time interval. Write a program that demonstrates the function by callingit in a loop that passes the values 1 through 10 as arguments and displays the return value.

*arrow_forward*

3. Find Relatively Prime
Write a function to return a number that is relatively prime with the given number.
/* return an integer that is relatively prime with n, and greater than 1i.e., the gcd of the returned int and n is 1
Note: Although gcd(n,n-1)=1, we don't want to return n-1*/int RelativelyPrime (int n)
4. Find Inverse
Then implement the following function, which returns the inverse modulo, and test it.Note that you need to check whether a and n are relative prime before calling thisfunction. Recall that a and n are relatively prime means that gcd(a,n)=1, i.e., theirgreatest common divisor is 1. Also recall that the extended Euclidean Algorithm canfind the integer s and t for a and n such that as+nt=gcd(a,n), where s is the inverseof a modulo n.
/* n>1, a is nonnegative *//* a<=n *//* a and n are relative prime to each other *//* return s such that a*s mod n is 1 */int inverse (int a, int n){int s, t;int d = ExtednedEuclidAlgGCD (n, a, s, t);if (d==1){return (mod (t,…

*arrow_forward*

Write a function named "reduce" that takes two positive integer arguments (as reference),call them "num" and "denom", treats them as the numerator and denominator of a fraction,and reduces the fraction.The function should return the value 0 (to indicate failure to reduce: if either of the twoarguments is zero) and should return the value 1 otherwise.Function Prototype: bool reduce(int & num,int & denom);

*arrow_forward*

To convert between Celsius and Fahrenheit, the following formula is used, where C = Celsius temperature and F = Fahrenheit temperature:
C = 5/9 * (F-32)
Write a C++ temperature conversion program which does the following:
Write a function called toCelsuis which takes a Fahrenheit temperature as a parameter, and returns the equivalent Celsius temperature:
float toCelsius(float)
Demonstrate that your function works by writing a main() function that prints out a conversion table. It should have Fahrenheit values 60, 61, 62, ... through 80 (21 temperatures in total) and should also have the corresponding Celsius temperatures that your function calculated. So your output should look something like this (with 21 temperature conversions total, I used ... to save space here for most of them):
Welcome to the temperature table!F C60 15.661 16.1... ...80 26.7
If you like: you can add this line in your function to make floating point output fixed, make sure you…

*arrow_forward*

*arrow_back_ios*

- SEE MORE QUESTIONS

*arrow_forward_ios*

Recommended textbooks for you

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

COMPREHENSIVE MICROSOFT OFFICE 365 EXCE

Computer Science

ISBN:9780357392676

Author:FREUND, Steven

Publisher:CENGAGE L

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

COMPREHENSIVE MICROSOFT OFFICE 365 EXCE

Computer Science

ISBN:9780357392676

Author:FREUND, Steven

Publisher:CENGAGE L