Concept explainers
Complete the following program skeleton. When finished, the program will ask the user for a length (in inches), then 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 <iostream>
#include <iomanip>
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.
//
Want to see the full answer?
Check out a sample textbook solutionChapter 9 Solutions
Starting Out with C++: From Control Structures through Objects, Brief Version plus MyLab Programming with Pearson eText - Access Card Package (8th Edition)
Additional Engineering Textbook Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Starting Out with Python (4th Edition)
Starting Out With Visual Basic (7th Edition)
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
Software Engineering (10th Edition)
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
- Mark the following statements as true or false: a. To use a predefined function in a program, you need to know only the name of the function and how to use it. (1) b. A value-returning function returns only one value. (2, 3) c. Parameters allow you to use different values each time the function is called. (2, 7, 9) d. When a return statement executes in a user-defined function, the function immediately exits. (3, 4) e. A value-returning function returns only integer values. (4) f. A variable name cannot be passed to a value parameter. (3, 6) g. If a C++ function does not use parameters, parentheses around the empty parameter list are still required. (2, 3, 6) h. In C + + , the names of the corresponding formal and actual parameters must be the same. (3, 4, 6) i. A function that changes the value of a reference parameter also changes the value of the actual parameter. (7) j. Whenever the value of a reference parameter changes, the value of the actual parameter changes. (7) k. In C++, function definitions can be nested; that is, the definition of one function can be enclosed in the body of another function. (9) l. Using global variables in a program is a better programming style than using local variables, because extra variables can be avoided. (10) m. In a program, global constants are as dangerous as global variables. (10) n. The memory for a static variable remains allocated between function calls. (11)arrow_forward2. a. Function Description: The Python function is mortgage() It receives 2 parameters (salePrice, creditScore ) from the program that invokes it.. The first is a float; the second is an integer. The function's purpose is to determine whether the customer meets the minimum standard to be considered for a mortgage. The sale price needs to be under $1,000,000 and the Credit Score needs to exceed 600 points. The function returns a message stating whether the customer meets the minimum standard and why. Fill in the following function table. Function Name Purpose Required Inputs Expected result 2.b Write the function code 2.c Write the Python program code to input salePrice and creditScore. The code will invoke the mortgage() function with this print statement: "print (mortgage (salePrice, creditScore))" 2.d Test your program: program using various inputs, such as the person's creditScore was too low but the salesPrice was fine; vice versa; or both scores too low. Show that your program's…arrow_forwardComplete the below code Note: Read commented part next to each blank #include #include #include float avg (float m, float n) 1 declare the function give_sqrt int main (void) float xy. float avgl. scanf("f"&x); scanf(r&y): avgl = / Call the function avg and pass x and y printf ("the avg of x and y is din", avgi ); give sqrt (avgi).arrow_forward
- Note: Write programs in c language format use in programs (Printf & Scanf)arrow_forward1. What is this paramters that are only accessible in the body of the function, like all variables used in the function? 2. What is the part of the program that creates function? 3. It performs operations like union, difference and intersectionarrow_forwardCode in C please. for this question you will write a function definition and a main function. implement the following function. char runmenu( ); \\display the program options and get the users selection (a, d, or q)) \\get and return the selection from the user \\declare all necessary variables \\you can decide what a,d, or q stand for add the main function with the function call to runmenuarrow_forward
- When a function accepts multiple arguments, does it matter what order the arguments are passed in?arrow_forwardPython Help Write the function grade_average(test1,test2,test3,test4,test5) that returns the average of five test scores.Write the function letter_grade(grade) that returns the letter grade of a test score: if the test score is 100-90 it should return A, if the test is between 80-89 it should return B, if the test is between 70-79 it should return C, if the test is between 60-69 it should return D, and it should return F otherwiseWrite a main function that asks the user to enter five test scores and calls the average function to find the average of the five test scores. After returning the average, use letter_grade function to return the letter grade of the average grade.arrow_forwardHow can we pass argument to a function by reference instead of pass by value?arrow_forward
- done in c++ Program Specifications: Write a program that asks for a user's name and age, finds the ticket price based on the age, and prints out the user's name, age, and ticket price. The program must define the following 3 functions and call them in the main function. Create a function called getName that takes in no arguments and returns the name of the user. Create a function called getAge that takes in the argument age and uses pass-by-reference to set the age of the user. Ensure that the user cannot put in an age that is negative or greater than 100. Create a function called printTicket that takes in the user's name and age and does the following ○ If they are less than or equal to 13 years old set ticket_Price to 9.99. ○ If their age is greater than 13 and less than 65, set ticket_Price to 19.99. ○ If their age is greater than or equal to 65, set ticket_Price to 12.99. ○ Output to the console the user's name, age and ticket price.arrow_forwardComputer sciencearrow_forwardLAB: User-Defined Functions: Miles to track laps One lap around a standard high-school running track is exactly 0.25 miles. Define a function named MilesToLaps that takes a float as a parameter, representing the number of miles, and returns a float that represents the number of laps.Then, write a main program that takes a number of miles as an input, calls function MilesToLaps() to calculate the number of laps, and outputs the number of laps. Ex: If the input is: 1.5 the output is: 6.0 Ex: If the input is: 2.2 the output is: 8.8 Your program should define and call a function: Function MilesToLaps(float userMiles) returns float userLaps Note: Remove all comments outside any functions before running the program.arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr