Problem Solving with C++ - MyProgrammingLab
10th Edition
ISBN: 9780134522418
Author: SAVITCH
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 4.6, Problem 25STE
Program Plan Intro
Description of Function:
Function has two parts that are called “function declaration” and “function definition”.
- The function declaration defines how the function is called.
- The function definition defines how the function computes the value it returns.
Parameters and arguments:
The parameter is used to denote to the variable as found in the definition of function and it is also called formal parameters.
The argument denotes to the actual input provided at function call and it is also called actual parameter.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Suppose you have two function definitions with the following declarations:double score(double time, double distance);int score(double points);Which function definition would be used in the following function call and why would it be the oneused?double x = 1.0;x = score(x, 2*x);
1. Write a function which takes one parameter int num, and prints out a countdown timer with minutes and seconds separated by a colon (:). It should print out one line for each second elapsed and then pause one second before printing out the next line. A few things to note:
- You can assume that calling the function usleep(1000000) makes the program pause for one second
- It should count down from num minutes:zero seconds to zero minutes:zero seconds
- Your function must have the following signature:
void timer(int num)
You do not need to demonstrate calling this function from main().
You don't need to format the output nicely; the below is acceptable output for calling this function when minutes is 10:
10:0
9:59
9:58
…
9:1
9:0
8:59
8:58
…
0:2
0:1
0:0
Consider the following function call:
draw_circle('red', 3)
What is the function name and what is the first argument passed to the function?
a.
The function name is draw_circle and the first argument is 3.
b.
You need to see the function definition to determine the function name and arguments.
c.
The function name is draw_circle, but you need to see the function definition to determine the arguments.
d.
The function name is draw_circle and the first argument is 'red'.
e.
The first argument is 'red', but you need to see the function definition to determine the function name.
Chapter 4 Solutions
Problem Solving with C++ - MyProgrammingLab
Ch. 4.2 - Prob. 1STECh. 4.2 - Convert each of the following mathematical...Ch. 4.2 - Write a complete C++ program to compute and output...Ch. 4.2 - Write and compile short programs to test the...Ch. 4.3 - Prob. 5STECh. 4.3 - Prob. 6STECh. 4.3 - Prob. 7STECh. 4.3 - Prob. 8STECh. 4.3 - Carefully describe the call-by-value parameter...Ch. 4.3 - Prob. 10STE
Ch. 4.3 - Write a function definition for a function called...Ch. 4.3 - Write a function definition for a function called...Ch. 4.3 - Write a function definition for a function isDigit...Ch. 4.3 - Write a function definition for a function...Ch. 4.4 - What is the purpose of the comment that...Ch. 4.4 - Prob. 16STECh. 4.4 - Prob. 17STECh. 4.4 - Carefully describe the process of program testing.Ch. 4.4 - Prob. 19STECh. 4.5 - If you use a variable in a function definition,...Ch. 4.5 - Suppose a function named Function1 has a variable...Ch. 4.5 - The following function is supposed to take as...Ch. 4.5 - Prob. 23STECh. 4.6 - Prob. 24STECh. 4.6 - Prob. 25STECh. 4.6 - Prob. 26STECh. 4.6 - Suppose you have two function definitions with the...Ch. 4.6 - This question has to do with the Programming...Ch. 4.6 - Prob. 29STECh. 4 - A liter is 0.264179 gallons. Write a program that...Ch. 4 - Modify your program from Practice Program 1 so...Ch. 4 - The price of stocks is sometimes given to the...Ch. 4 - Write a program to gauge the rate of inflation for...Ch. 4 - Enhance your program from the previous Practice...Ch. 4 - Write a function declaration for a function that...Ch. 4 - The gravitational attractive force between two...Ch. 4 - Prob. 8PCh. 4 - Prob. 9PCh. 4 - Write a program that computes the annual after-tax...Ch. 4 - Write a program that asks for the users height,...Ch. 4 - Modify your program from Programming Project 2 so...Ch. 4 - Write a program that outputs the lyrics for the...Ch. 4 - To maintain ones body weight, an adult human needs...Ch. 4 - You have invented a vending machine capable of...Ch. 4 - Your time machine is capable of going forward in...Ch. 4 - Do Programming Project 11 from Chapter 3 except...Ch. 4 - Your sports league uses the following lottery...Ch. 4 - Do Programming Project 14 from Chapter 3, the Edoc...
Knowledge Booster
Similar questions
- For this question you will design and implement a function that takes 5 arguments and produces 5 return values. This question is internally recognized as variant 0371. The 5 arguments must be of types int, int, bool, bool, and char (in that order), and they must be stored in parameter variables 'ham', 'bar', 'xyz', 'gzk', and 'foo', respectively. As a clarifying example, the second parameter - 'bar' - will be of type int. The function you create must perform the operations list below, in the specified order and exactly as they are described here. You are NOT permitted to simplify the operations. 1. create a new variable named 'ukr' that stores the result of increasing the 'ham' parameter by 42 2. if the conjunction of the 'xyz' parameter and the 'gzk' parameter has a value of True, multiply the value of the 'ham' parameter by a value of 29 and store the result back in 'ham' 3. negate the value of the 'xyz' parameter and store the result back in 'xyz' 4. decrease the value of the 'ham'…arrow_forwardWrite a function to divide variable ‘a’ with ‘b’. Store the result in a separate variable andreturn it from the function. Practice default parameters by calling your function with 1 argumentand with 2 arguments. Use the concept of function prototyping for this question. The signature offunction is as follows: int divide (int a, int b=2)arrow_forward9-Given the code segment below, what should be the data type of the formal parameter in the function prototype of func(), given the call from main()? Note that function prototypes need not include the identifier (name of the parameter), so do NOT put any variable name in your answer. Remove any space in your answer. If the accessing is wrong, answer INVALID (in all capital letters). void func( ______ ); int main() { double aData[6][4]; func(&aData[4]); return 0; }arrow_forward
- Suppose you have written the following function. function salesTax(price, rate) { let tax = price * rate; return tax;{ How can you call the function, passing in values of 9% for the sales tax rate and $20 for the price? a. salesTax(20, 0.09); b. salesTax(0.09, 20); c. function salesTax(20, 0.09); d. tax = 20 * 0.09;arrow_forwardConsider the following function definition. double funcTest(string name, char u, int num, double y){}Which of the following are correct function prototypes of the function funcTest?a. double funcTest(string, char, int, double);b. double funcTest(string n, char ch, int x, double t);c. double funcTest(name, u, num, y);d. int funcTest(string, char, int, double)arrow_forwardWrite a function declaration and a function definition for a function that takes one argument of type int and one argument of type double, and that returns a value of type double that is the average of the two arguments.arrow_forward
- (Practice) For the following function headers, determine the number, type, and order(sequence) of the values that must be passed to the function: a. void factorial(int n) b. void volts(int res, double induct, double cap) c. void power(int type, double induct, double cap) d. void flag(char type, double current, double time) e. void total(double amount, double rate) f. void roi(int a, int b, char c, char d, double e, double f) g. void getVal(int item, int iter, char decflag, char delim)arrow_forward(Practice) For the following function headers, determine the number, type, and order (sequence) of values that should be passed to the function when it’s called and the data type of the value the function returns: a. int factorial(int n) b. double volts(int res, double induct, double cap) c. double power(int type, double induct, double cap) d. char flag(char type, float current, float time) e. int total(float amount, float rate) f. float roi(int a, int b, char c, char d, float e, float f) g. void getVal(int item, int iter, char decflag, char delim)arrow_forward(Numerical) Heron’s formula for the area, A, of a triangle with sides of length a, b, and c is A=s(sa)(sb)(sc) where s=(a+b+c)2 Write, test, and execute a function that accepts the values of a, b, and c as parameters from a calling function, and then calculates the values of sand[s(sa)(sb)(sc)]. If this quantity is positive, the function calculates A. If the quantity is negative, a, b, and c do not form a triangle, and the function should set A=1. The value of A should be returned by the function.arrow_forward
- Section 6.9 of your textbook ("Debugging") lists three possibilities to consider if a function is not working. Describe each possibility in your own words. Define "precondition" and "postcondition" as part of your description.arrow_forwardWrite a function with one integer parameter that will return the sum of the divisors of its argument c++arrow_forwardI need help in solving this question Question 10 Given the code segment below, what should be the data type of the formal parameter in the function prototype of func(), given the call from main()?Note that function prototypes need not include the identifier (name of the parameter), so do NOT put any variable name in your answeIf the accessing is wrong, answer INVALID (in all capital letters). void func( ______ ); int main() { double aData[6][4]; func(aData[6]); return 0; }arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning