
Exercise 11/04/03
Objective: Learn about overloading function names, functions as procedures, and call-by-reference parameters.
1. Answer all questions below.
2. Test and correct your answer.
#include <iostream>
using namespace std;
int convert_to_inches(int feet, int inches);
void convert_to_inches(int feet, int inches, int& total_inches);
int main()
{
cout << “Enter two integers that represent the length “
<< “in feet and inches: “;
cin >> feet >> inches;
// a) Will two functions with the same name in the same program cause
// syntax error? Explain your answer.
// b) Show statements needed to call the first convert_to_inches function
// to obtain the converted amount and output it. Add all missing
// statements so that the program will work.
// c) Show statements needed to call the second convert_to_inches function
// to obtain the converted amount and output it. Add all missing
// statements so that the program will work.
return 0;
}
int convert_to_inches(int feet, int inches)
{
return 12*feet + inches;
}
void convert_to_inches(int feet, int inches, int& total_inches)
{
total_inches = 12*feet + inches;
}