## PIC 10A

(Sec. 3a-3d)

C++ Programming and Problem Solving

## Instructor: Ivo Dinov, Asst. Prof.

 http://www.math.ucla.edu/~dinov/courses_students.dir/PIC10A_CPP_Spring01.dir/PIC10A_CPP.html

Due Date:

# Wednesday, 8:00 PM, Apr. 25, 2001

• (HW_3_1.cpp/exe) Write a program that converts feet/inches to meters/centimeters. The program needs to first request a conversion type (feet --> meters, by "F"; or feet <-- meters, by "M"), then request the user input (pair of numbers, feet/inches, for the first type; or a double (e.g., 3.12) for the second type of conversion). If the user enters 0' 0", for the first type or 0 0 for the second type, this indicates program termination. Else, continue computations using the following conversion formulas: 1 ft = 0.3048 m and 12 in = 1 ft, of course 100 cm = 1 m. Format your double-precision output as we had shown in class. (Hint: write two functions, for the two conversion types, and call these from within "main", depending on the user needs for metric conversion.)
• 1-st Sample run:
%> Which conversion: English (foot/inch) --> Metric
(meter/centimeter), enter 'F' or 'f';
English (foot/inch) <-- Metric, enter 'M' or 'm':
%> f
%> Enter foot and inches as doubles:
%> 1.0 0.0
%> 1'0" equals 0.3048 m or 30.48 cm
%> ...
• 2-st Sample run:
%> Which conversion: English (foot/inch) --> Metric
(meter/centimeter), enter 'F' or 'f';
English (foot/inch) <-- Metric, enter 'M' or 'm':
%> M
%> Enter meters and centimeters as doubles:
%> 1.0 0.0
%> 1.0 m + 0.0 cm equals 3'3"
%> ...

• (HW_3_2.txt)True or False?
• A program should have all of its functions written completely before it can be tested!
• A function definition can appear inside another function's definition!
• A pass by value parameter may pass data into a function!
• A pass by reference parameter may pass data only into a function!
• A return statement is required in a void function!
• 1TB = 220MB!
• A void function returns no value therefore it must have non-trivial number of input parameters to be useful!

\Ivo D. Dinov, Ph.D., Department of Neurology and Program in Computing, UCLA School of Medicine/