Menu

(Solved) : Please Explain Clearly Answers Decision Structures Suppose X Y Variables Type Double Decla Q43969446 . . .

Please, explain clearly your answers

Decision Structures

  1. Suppose x & y are variables of type double. How todeclare them with a code fragment that sets y to x if x is positiveand to 0 otherwise?
  2. Suppose x & y are variable of type double. Write acode fragment that sets y to the absolute value of x withoutcalling the abs function. Use an if statement.
  3. How to declare a code fragment that reads in twofloating-point numbers and tests whether they are the same up totwo decimal places.

Output:

Enter two floating-point numbers: 2.01.99998

They are the same up to two decimal places.

Enter two floating-point numbers: 2.01.98999

They are different.

  1. How to declare a while loop that prints:-
  1. All squares less than n. For example, if n is 100,print 0 1 4 9 16 25 36 49 64 81.
  2. All powers of two less than n. For example, if n is100, print 1 2 4 8 16 32 64.
  1. How to declare a loop that computes:-
  1. The sum of all even numbers between 2 & 100(inclusive).
  2. The sum of all squares between 1 & 100(inclusive).
  3. The sum of all odd numbers between a & b(inclusive).
  4. The sum of all odd digits of n. (For example, if n is32677, the sum would be 3 + 7 + 7 = 17).
  1. How to declare the following code that read a line ofinput as a string & print
  1. Only the uppercase letters in the string.
  2. Every second letter of the string.
  3. The string, with all vowels replaced by anunderscore.
  1. How to declare the following functions & provid3e aprogram to test them.
  1. Double smallest (double x, double y, double z),returning the smallest of the arguments.
  2. Double average (double x, double y, double z),returning the average of the arguments.
  1. How to declare the following functions & provide aprogram to test them:-
  1. bool all_the_same (double x, double y, double z),returning true if the arguments are all the same.
  2. bool all_different (double x, double y, double z),returning true if the arguments are all different.
  1. How to declare the following functions:
  1. int first_digit (int n), returning the first digit ofthe argument.
  2. int last_digit (int n), returning the last digit of theargument.
  3. int digits (int n), returning the number of digits ofthe argument

For example, first_digit(1729) is 1, last_digit(1729) is9, and digits(1729) is 4.

  1. How to declare a function string middle (string str)that returns a string containing the middle character in str if thelength of str is odd, or the two middle characters if the length iseven. For example, middle (“middle”) returns “dd”.
  2. How to declare a function string repeat (string str,int n) that returns the string str repeated n times. For example,repeat (“ho”, 3) returns “hohoho”.

Expert Answer


Answer to Please, explain clearly your answers Decision Structures Suppose x & y are variables of type double. How to declare them…

OR