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