Explanation of Solution
Output of the Program:
The given program has been added with comments and line number.
/*Include required variables*/
#include <iostream> //Line 1
using namespace std; //Line 2
/*Function prototype*/
void myFunc();//Line 3
/*Main function*/
int main()//Line 4
{//Line 5
/*Variable "var" is declared as "int" data type and it is assigned with the value "100"*/
int var = 100; //Line 6
/*Print the value*/
cout << var << endl; //Line 7
/*Call the function "myFunc()"*/
myFunc();//Line 8
/*Display the value of variable "val" after calling the function*/
cout << var << endl; //Line 9
/*Return the value 0*/
return 0; //Line 10
}//Line 11
/* Function definition */
void myFunc()//Line 12
{//Line 13
/*Variable "var" is declared as "int" data type and it is assigned with the value "50"*/
int var = 50; //Line 14
/* Print the value of the variable "var" */
cout << var << endl; //Line 15
}//Line 16
Explanation:
The above program explains the scope of the local variable...
Want to see the full answer?
Check out a sample textbook solutionChapter 6 Solutions
Starting Out with C++: Early Objects
- C++ Write the definition of the function int computerProd() with parameters that receives as arguments two integer values values, computes their product and returns it to the calling function.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_forwardCreate a function repeated in Racket in the functional paradigm, that takes two arguments: a function f of one argument and a non-negative integer count. Use #lang plai at the top of the definitions window. Provide transcript of repeated function using test or provide an explanation of the answer you expect. The result should be a function of one argument, to which it applies the function f count times. Explain what repeated should return if its numeric argument is 0 and why.arrow_forward
- In C++ A void function a. does not have a specific data type for the function output b. has a specific data type for the function output c. must be included after the "main" function of the program. d. is equivalent to a value-returning function except that a void function must be included before mainarrow_forwardIn one sentence, explain why you must provide a function declaration if the code for that function comes after the spot where it's called (such as below main()). Write a function declaration that will match this function call: double product;product = determineProduct(3.0, 5.0, 8.0);arrow_forwardIn c++ In terms of testing and debugging functions, define stubs and drivers. Create a driver for the function you created in the previous volume problem. Show your source code and a sample of the program output. Does your function produce accurate results? previous code: #include <iostream>#include <cmath>using namespace std;const float PI = 3.14; float ConeVolume(float radius, float height){ return (PI / 3) * pow(radius, 2) * height;} int main(){ float radius, height, volume; cout << "Enter the radius: "; cin >> radius; cout << "Enter the height: "; cin >> height; volume = ConeVolume(radius, height); cout << "The volume of the cone is: " << volume << endl; return 0; }arrow_forward
- In what scenarios would it be beneficial to utilize a function object over a standard function?arrow_forwardShould define a main function and end by invoking itarrow_forwardPlease help me explain the following void function c++ code, which I did not understand. Especially for the first void function and int main(), I do not understand why the first void function enter the number and the int main function print out the final answer. #include <iostream>using namespace std; void getNumber(int *input); void doubleValue(int *val); int main(){ int number; getNumber(&number); doubleValue(&number); cout<<"That value doubled is"<<number<<endl; return 0;}void getNumber(int *input){ cout<<"Enter an integer number:"; cin>>*input; }void doubleValue(int *val){ *val *=2;}arrow_forward
- Set-up and implementation code for a void function MaxYou are not required to write a complete C++ program but must write and submit just your responses to the four specific function related questions below: QC1: Write the heading for a void function called Max that has three intparameters: num1, num2 and greatest. The first two parameters receive data from the caller, and greatest is used to return a value as a reference parameter. Document the data flow of the parameters with appropriate comments*. QC2: Write the function prototype for the function in QC1. QC3: Write the function definition of the function in QC1 so that it returns the greatest of the two input parameters via greatest, a reference parameter. QC4: Add comments to the function definition* you wrote in QC3 that also states its precondition and postcondition.arrow_forwardC++ programming 48.In the function prototype void action(int& value); The argument value is said to be a ___________ parameter. 49.In the previous problem, suppose the function action updated its argument. True or false: the variable value in the caller would be updated. ________________ 50.True or false: the following two prototypes represent valid overloaded functions _________:double fna(double,int);float fna(float,int);arrow_forwardConsider the definition of the function main. int main() { double rate, hours, amount; . . . } Each of the functions described must have the appropriate parameters to access these variables. Write the following definitions: a. Write the definition of the function getHoursRate that prompts the user to input the hours worked and rate per hour to initialize the variables hours and rate of the function main. b. Write the definition of the value-returning function payCheck that calculates and returns the amount to be paid to an employee based on the hours worked and rate per hour. The hours worked and rate per hour are stored in the variables hours and rate, respectively, of the function main. The formula for calculating the amount to be paid is as follows: For the first 40 hours, the rate is the given rate; for hours over 40, the rate is 1.5 times the given rate. c. Write the definition of the function printCheck that prints the hours worked, rate per hour, and the…arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning