Question

Please describe and discuss the following 1. What is the function pow? Where is it defined?...

Please describe and discuss the following 1. What is the function pow? Where is it defined? Give an example using the function pow. 2. What is type casting? Give an example. 3. What would the following statement in C++ do? result *= a + 5; 4. Write a C++ statement that generates and prints a random number. Why are random number generators needed? 5. What are setw and setprecision functions? Give example statements.

Homework Answers

Answer #1
  1. POW function:

baseexponent

This is the power function, which raise the base by the power of exponent value.

Example: 7 ^ 3 means, = 343.

And 10.53 ^ 3 = 1167.575877

Code:

#include <stdio.h> /* prinf * /

#include <math.h> /* math libaray to get all math formulas */

int main ()

{

printf ("7 ^ 3 = %f\n", pow (7.0, 3.0) );

printf ("10.53 ^ 12 = %f\n", pow (10.53, 3.0) );

return 0;

}

  1. Type Casting:

Simply it means converting the variable from current type to another type. There is different method to convert implicit and explicit. C++ is a strong typed language, many conversation may need the explicit conversions which is known as C++ as type casting.

Different syntaxes for generic type casting: functional and c-like

double x = 10.3

Int y

y = int(x); //functional notation

y = (int) x ; // c-like cast notation

  1. Result

result *= a + 5;

After adding the variable a and 5 it again multiples with variable values of result. Means for example

It can also be written as

result = result * (a+5);

yields same answer. I hope you got the sense.

Random number:

This number is generated by an algorithm which results a sequence of apparently non-related numbers each time it is called.

Syntax: int rand(void)

 
int main()
{
  int a = 0;
  while(a++ < 10) 
   {
 
    int r = (rand() % 100) + 1;
    count << r << " ";
    }
  return 0;
}

Sample output :

42 35 1 70 25 74 59 63 65 68

Setw:

setw is to set the field widthto be used to print a nice formatted outputs. It takes numeric parameters.

Int main()

{

std::cout << std :: setw(10);

std::cout << 29 << std  :: endl;
 
return 0;

}

Set precision: this function enable us to format the floating point values on output operations. Parameters will be a numerics.

It will take the parameters and prints the float output after that many number of point it will place a decimal.

 
int main () 
{
double f =4.514159;
 
std::cout << std::setprecision(5) << f << '\n';
std::cout << std::setprecision(9) << f << '\n';
return 0;

}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
The function named myRandomNum that returns a random integer in the range [1, 100] is defined...
The function named myRandomNum that returns a random integer in the range [1, 100] is defined as follows: int myRandomNum () { return rand()%100 + 1; } Now, write a program (code fragment) that repeatedly generates and prints random integers in the range [1, 100]. The program must stop when the absolute value of the difference between successive printed values is less than 5. Two sample output is given to help you understand the problem: 1. The program can possibly...
#1 Please discuss the importance of cost function in economics ? #2 Discuss also explicit, implicit...
#1 Please discuss the importance of cost function in economics ? #2 Discuss also explicit, implicit cost and marginal cost. #3 Give an example of an opportunity cost that an accountant would not count as a cost. Why would the accountant ignore this cost? #4 What is marginal product, and what does it mean if it is diminishing? #5 Define total cost, average total cost, and marginal cost. How are they related?
Please read the requirements: Write a C++ function, date, that will accept a date via a...
Please read the requirements: Write a C++ function, date, that will accept a date via a parameter in the month-day-year format, mmddyyyy, (e.g., 10262020 stands for the date October 26, 2020), and then will determine the corresponding month number, day, and year of that date, returning these three integer values to the calling function via arguments. An example of a call to the function date is shown in the following statement: date (10262020, month, day, year); This call to the...
##4. What will the following program display? ##def main(): ## x = 1 ## y =...
##4. What will the following program display? ##def main(): ## x = 1 ## y = 3.4 ## print(x, y) ## first printing ## change_us(x, y) ## print(x, y) ##second printing ## ##def change_us(a, b): ## a = 0 ## b = 0 ## print(a, b) ## ##main() ## ##Yes, yes, main() displays ##1 3.4 ##0 0 ##1 3.4 ## The question is: why x and y are still the same while the second printing of (x,y)? ## It seems...
1. Suppose we have the following relation defined on Z. We say that a ∼ b...
1. Suppose we have the following relation defined on Z. We say that a ∼ b iff 2 divides a + b. (a) Prove that the relation ∼ defines an equivalence relation on Z. (b) Describe the equivalence classes under ∼ . 2. Suppose we have the following relation defined on Z. We say that a ' b iff 3 divides a + b. It is simple to show that that the relation ' is symmetric, so we will leave...
complete a C++ program that asks the user to make a choice off a menu that...
complete a C++ program that asks the user to make a choice off a menu that will be displayed to them. The user can make as many selections as they wish. The last choice from the menu will give them an option to stop. The menu choices will be the following four calculations: Find the volume of a cone Find the volume of a sphere Find the area of octagon Find the distance between two points Stop For the different...
1. Draw and describe the following: a.) Please draw an artistic rendition of neural tissue. Please...
1. Draw and describe the following: a.) Please draw an artistic rendition of neural tissue. Please include a picture of a neuron, the associated glial cells, whether it exists in the CNS or PNS, and label the parts of the cells. b.) Draw and describe the events that take place in a synapse between two neurons. What neurotransmitter is used? How does this differ from the synapse that takes place between neurons and muscle cells? c.) Describe and draw a...
1. What are the inputs to Excel’s RAND function? a.There is one argument to put into...
1. What are the inputs to Excel’s RAND function? a.There is one argument to put into the function – the distribution from which to generate random numbers. b.There are two arguments to put into the function – the number of random values to generate, followed by the number of decimal places. c.The RAND function has no arguments, just parentheses with nothing in between. 2. What do you actually type into a spreadsheet cell to use the RAND function? a. =RAND()...
Suppose an economy's production is defined by the following neoclassical production function: Y=3K 1/3L 2/3. Suppose...
Suppose an economy's production is defined by the following neoclassical production function: Y=3K 1/3L 2/3. Suppose further that the economy wide supply of capital and labor are given as 125,000 and 1,000 respectively. If congress imposes a minimum wage of 11 units of output in this economy, what will be the likely result of this action? a. An unemployment rate of 25% b. An unemployment rate of 10% c. Full employment, but lower output d. An unemployment rate of 50%
Suppose an economy's production is defined by the following neoclassical function: Y=K 1/5L 4/5. What are...
Suppose an economy's production is defined by the following neoclassical function: Y=K 1/5L 4/5. What are the expressions for the marginal product of capital and the marginal product of labor? 1/5Y/L and 4/5Y/L 1/5Y/K and 4/5Y/L 1/5Y/L and 4/5Y/K 1/5Y/K and 4/5Y/K