Suppose f is defined as an int variable, index and ring are defined as double va
ID: 3543485 • Letter: S
Question
Suppose f is defined as an int variable, index and ring are defined as double variables. Write an if-else statement that sets f to -1 if index is less than ring or sets f to 1 if index is greater than ring. Surround the true- and false-clauses of your if-else statement with braces to form blocks.
Suppose inches is an int variable that stores a person's height (in inches). Suppose double ConvertInchToCm(int inches) is a function that converts inches to centimeters and returns the result as a double. Suppose int Round(double n) is a function that rounds input parameter n up or down to the nearest integer. Write a C++ statement that converts height in inches to centimeters, rounds the height in centimeters to the nearest integer, and assigns the rounded value to an int variable named cm. Assume cm is already defined. Hint: there are two function calls here, so use function composition.
Suppose a constant double variable named LB_PER_KG has been defined and initialized to 2.20462262. Let lbs be a double variable that represents a person's weight in pounds. Write an arithmetic expression that would convert the weight in pounds to weight in kilograms, using LB_PER_KG.
Explanation / Answer
1)
if(index<ring)
{
f=-1
}
//there is third case in which index and ring are equal
// so here we have to use else if
else if()
{
f=1;
}
2)
//these diclaraton are just to ease in undersatanding
int inches;
double ConvertInchToCm(int inches);
int Round(double n);
int cm;
//here is your answer
cm = Round(ConvertInchToCm(inches));
3)
double weightInKg = lbs / LB_PER_KG;