Question

In: Computer Science

Complete the following program skeleton. When finished, the program will ask the user for a length (in inches), convert that value to centimeters, and display the result. You are to write the function convert.

Complete the following program skeleton. When finished, the program will ask the user for a length (in inches), convert that value to centimeters, and display the result. You are to write the function convert. (Note: 1 inch = 2.54 cm. Do not modify function main.)

#include #include using namespace std;// Write your function prototype here.int main(){ double measurement; cout ≪ "Enter a length in inches, and I will convert\n"; cout ≪ "it to centimeters: "; cin ≫ measurement; convert(&measurement); cout ≪ fixed ≪ setprecision(4); cout ≪ "Value in centimeters: " ≪ measurement ≪ endl; return 0;}

//

// Write the function convert here.

//

Solutions

Expert Solution

Convert function definition:

The following code defines the function convert. It accepts one double parameter and returns their measurement value.

• This function takes a double argument.

• Convert 1 inch is equal to 2.54cm.

// Write the function convert here.

void convert(double *measurement)

{

// calculate the measurement

*measurement = *measurement*2.54;

}

Complete program is as follows:

The following program demonstrates the functionality of the function convert():

Program:

#include

 

#include

 

using namespace std;

 

void convert(double*);

 

int main()

 

{

    

    double measurement;

    

    cout << "Enter a length in inches, and i will convert\n";

    

    cout << "it to centimeters:";

    

    cin >> measurement;

    

    convert(&measurement);

    

    cout << fixed << setprecision(4);

    

    cout << "Value in centimeters:" << measurement

    

    << endl;

    

    return 0;

    

}

 

// Write the function convert here.

 

void convert(double *measurement)

 

{

    

    // calculate the measurement

    

    *measurement = *measurement*2.54;

    

}

Sample Output:

Enter a length in inches, and i will convert

it to centimeters:45

Value in centimeters:114.3000

Related Solutions