COMPILER DESIGN

ADVANCED TOPICS IN COMPILER DESIGN

CODE GENERATION FOR OBJECT ORIENTED LANGUAGES

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
Develop an algorithm to prompt the user for and accept a measurement in centimeters and convert it to inches. Output the measurement in both inches and centimeters. Recall that 1 inch = 2.54cm.Which is the correct way in writing the result for the above program?
A
print “The conversion is", inches, “=", measure
B
print “The conversion is inches = measure”
C
print “The conversion is” read conversion
D
print “The conversion is” inches “=” measure
Explanation: 

Detailed explanation-1: -Inches to Centimeter Formula The value of 1 inch is approximately equal to 2.54 centimeters. To convert inches to the centimeter values, multiply the given inch value by 2.54 cm. 1 cm = 0.393701 inches.

Detailed explanation-2: -Answer: To convert from centimeters to meters, simply divide the number of centimeters by 100 and change the units to m. The m is an abbreviation for meters. To convert from meters to centimeters, simply multiply the number of meters by 100 and change the units to cm.

Detailed explanation-3: -There are 2.54 centimeters in 1 inch. Using the conversion number of 0.3937, the conversion formula for converting x centimeters to inches is this: x centimeters * 0.3937 = inches.

Detailed explanation-4: -h cm = round(h inch * 2.54, 1): The height in centimeters is calculated by multiplying the height in inches by 2.54 (the conversion factor from inches to centimeters), and rounding the result to one decimal place using the round() function.

There is 1 question to complete.