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

In C: Write a complete program that performs the following task: Ask the user for the...
In C: Write a complete program that performs the following task: Ask the user for the number of sequences to display. For each sequence, Ask the user for a starting value Print out the value and double it (multiply by 2). Continue printing and doubling (all on the same line, separated by one space each) as long as the current number is less than 1000, or until 8 numbers have been printed on the line. You may assume that the...
Write code to ask user to provide input length in miles, yards, feet and inches and...
Write code to ask user to provide input length in miles, yards, feet and inches and write code to convert sum of total length into meters. Display result by reiterating input values in inches, feet, yards, and miles entered by user, and the sum of the total length in meters. PLEASE use bluej for code
1. Write a Python program that will ask the user length and width of the right...
1. Write a Python program that will ask the user length and width of the right triangle and find the area of the right-angled triangle. The formula for finding the area of a right-angle triangle is ab/2. Also, find out the result if you calculate as (ab)/2. Is it the same? If it is same, why it is the same. If it is not the same, why it is not the same.
Ice Cream Program Assignment Write a program that uses a function to ask the user to...
Ice Cream Program Assignment Write a program that uses a function to ask the user to choose an ice cream flavor from a menu (see output below.) You must validate the users input for the flavor of ice cream accounting for both upper and lower-case letters. You must give them an appropriate error message and allow them to try again.   Once you have a valid flavor, your function will return the flavor back to the main() function.    Your main()...
Write a program that does the following. It will ask the user to enter an integer...
Write a program that does the following. It will ask the user to enter an integer larger than 1, and the if entered integer is not larger than 1, it keeps prompting the user. After the user enters a valid integer, the program prints all the prime factors of the integer (including the repeated factors). For example, if the entered integer is 24, the program prints: 2 2 2 3 Run your program with the test cases where the entered...
Take the following program and include overload functions into it. Display result of function. C++ Program:...
Take the following program and include overload functions into it. Display result of function. C++ Program: #include <iostream> using namespace std; // this is the additional function string read() {     string input;     cout << "Enter input: ";     cin >> input;     return input; } int main() {     // call function here     string output = read();     cout << "You entered: " << output; }
Write a mips assembly code program that ask the user to enter an integer value, and...
Write a mips assembly code program that ask the user to enter an integer value, and then print the result of doubling that number.
Write a program and ask a user to enter a numeric value between 0 - 99....
Write a program and ask a user to enter a numeric value between 0 - 99. Your program will spell out the numbers into words. You must use at least three switch cases in addition to multiple if statements. Each missing switch statement will reduce your grade for this problem by 20%. Note: The total number of if statements and switch cases should not exceed 28. Additional if/case statement will further reduce your grade by 5%. in c++ please
Write a program to prompt the user to display the following menu: Sort             Matrix                   Q
Write a program to prompt the user to display the following menu: Sort             Matrix                   Quit If the user selects ‘S’ or ‘s’, then prompt the user to ask how many numbers you wish to read. Then based on that fill out the elements of one dimensional array with integer numbers. Then sort the numbers and print the original and sorted numbers in ascending order side by side. How many numbers: 6 Original numbers:                     Sorted numbers 34                                                                         2          55                                                      ...
Write a program to prompt the user to display the following menu: Sort             Matrix                   Q
Write a program to prompt the user to display the following menu: Sort             Matrix                   Quit If the user selects ‘S’ or ‘s’, then prompt the user to ask how many numbers you wish to read. Then based on that fill out the elements of one dimensional array with integer numbers. Then sort the numbers and print the original and sorted numbers in ascending order side by side. How many numbers: 6 Original numbers:                     Sorted numbers 34                                                                         2          55                                                      ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT