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
EBK STARTING OUT WITH C++ FROM CONTROL
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_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_forwardin C++ program please: part a) According to Wikipedia: “The International Collegiate Programming Contest, known as the ICPC, is an annual multi-tiered competitive programming competition among the universities of the world.” Moreover, the participants of the contest should be no older than 24. Complete the following function which takes as input two parameters: the current year and the birth year of a student. The function should return the age of the person given the parameters. int calculateAge(int current_year, int birth_year) { part b) The teacher wants to determine if a group of students is eligible for this competition. Complete the following piece of code considering that the age of these students are stored in the studentsAge array and use the calculateAge function to determine the eligibility. Note: solution should use calculateAge ! int main() { int studentsAge[10]; #your answer for (int i = 0; i < 10; i++) { cin >> studentsAge[i]; # your answer Your program…arrow_forward
- 1 year = 15 months 1 month = 30 days write a function that takes an int parameter that represents the number of days, and converts the number of days to years, months, and days and returns this information in a struct So for example, it will convert 800 days into a struct that represents one year, 11 months, and 20 daysarrow_forwardC++ program Write a function named "reduce" that takes two positive integer arguments (as reference), call them "num" and "denom", treats them as the numerator and denominator of a fraction, and reduces the fraction.The function should return the value 0 (to indicate failure to reduce: if either of the two arguments is zero) and should return the value 1 otherwise.Function Prototype: bool reduce(int & num,int & denom);arrow_forwardin C++ program please: part a) According to Wikipedia: “The International Collegiate Programming Contest, known as the ICPC, is an annual multi-tiered competitive programming competition among the universities of the world.” Moreover, the participants of the contest should be no older than 24. Complete the following function which takes as input two parameters: the current year and the birth year of a student. The function should return the age of the person given the parameters. int calculateAge(int current_year, int birth_year) { part b) The teacher wants to determine if a group of students is eligible for this competition. Complete the following piece of code considering that the age of these students are stored in the studentsAge array and use the calculateAge function to determine the eligibility. Note: solution should use calculateAge ! int main() { int studentsAge[10]; #your answer for (int i = 0; i < 10; i++) { cin >> studentsAge[i]; # your answer Your program…arrow_forward
- Jjdisplays the following message: The event is from START_DAY to END DAY where START_DAY and END_DAY are names of day as shown on the above table. If an invalid code is passed to the function, it displays "Invalid code(s)". Complete the program with several function calls from within main() to the above function with the following values: 1,2 2,4 3,7 7,10.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_forwardHow can we pass argument to a function by reference instead of pass by value?arrow_forward
- Python 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_forwardWhen a function accepts multiple arguments, does it matter what order the arguments are passed in?arrow_forwardAll task are of c++ language and done using functions. task1: Write program to print the structure of house. You are required to use three functions. 1)Build Roof 2)Build Walls 3)build Floor. task2: Find the factorial of the number user enters using functions. task 3: write a void function divisor that receives an integer number and display its divisor on screen including 1 and itself. write the main function to test your function. task 4: You are required to create a conversion program. First ask the user his choice and then convert. • Conversion from Pound to Kg. (1 Pound = 0.453 Kg) • Conversion from Feet to centimeter (1 Foot = 30.48 cm) • Convert Hours & minutes in Daysarrow_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