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 showVar(); //Line 3
/* Main function */
int main()//Line 4
{ //Line 5
/* Loop till "count" variable is less than "10" */
for (int count = 0; count < 10; count++) //Line 6
/*Call the function "showVar()"*/
showVar(); //Line 7
/*Return the value 0*/
return 0; //Line 8
}//Line 9
/*Function definition*/
void showVar() //Line 10
{//Line 11
/* Variable "var" is declared as static "int" and assign "10" to it */
static int var = 10; //Line 12
/*Print the value "var"*/
cout << var << endl; //Line 13
/*Increment the variable "var"*/
var++; //Line 14
} //Line 15
Explanation:
The above program explains the scope of the local variable when it is declared as “static”.
“main()” function:
- In line 6, it uses the “for” loop for iterating the “count” variable equals to less than 10.
- When the value of “count” is “0”, the function “showVar()” has been called, which prints the value 10.
- When the value of “count” is “1”, the function “showVar()” has been called, which prints the value 11.
- When the value of “count” is “2”, the function “showVar()” has been called, which prints the value 12...
Trending nowThis is a popular solution!
Chapter 6 Solutions
Starting Out with C++: Early Objects
- Code Should Be In C++arrow_forward#include<stdio.h> //Standard library math.h for Mathematics functions #include<math.h> //function declaration void function1(void); void function2(void); int main(void) { //calling both function function1(); function2(); printf("\nMain function for Ceil value: %f",ceil(4.5)); return0; } // Defining the first function void function1(void) { printf("\nFirst function for Square Root: %f",sqrt(91)); } //Defining the second function void function2(void) { printf("\nSecond function for Power: %f",pow(2,4)); } I need to do what the picture is asking for.arrow_forwardC PROGRAM Reverse + Random Formula In the code editor, there's already an initial code that contains the function declaration of the function, computeReverseNumber(int n) and an empty main() function. For this problem, you are task to implement the computeReverseNumber function. This function will take in an integer n as its parameter. This will get the reverse of the passed integer and will then compute and return the value: result = (original_number + reverse_of_the_number) / 3 In the main() function, ask the user to input the value of n, call the function computeReverseNumber and pass the inputted value of n, and print the result in the main() with two (2) decimal places. SAMPLE: Input n: 20 Output: 7.33 Input n: 123 Output: 148.00arrow_forward
- Classwork Requirements: Developa program in C++ that: Reads as many test scores as the user wants from the keyboard (assuming at most 50scores). Test scores should be whole numbers. You must validate user input; only positive numbers are valid. Prints the scores in original order sorted from high to low the highest score the lowest score the average of the scores Implement the following functions using the given function prototypes: void displayArray(int array[], int size)- Displays the content of the array void selectionSort(int array[], int size)- sorts the array using the selection sort algorithm in descending Hint: refer to example 8-5 in the textbook. int findMax(int array[], int size)- finds and returns the highest element of the array int findMin(int array[], int size)- finds and returns the lowest element of the array double findAvg(int array[], int size)- finds and returns the average of the elements of the arrayarrow_forwardConsider the function definition: void GetNums(int howMany, float& alpha, float& beta) { int i; beta = 0; for (i = 0; i < howMany; i++) { beta = alpha + beta; } } Describe what happens in MEMORY when the GetNums function is called.arrow_forwardIn what scenarios would it be beneficial to utilize a function object over a standard function?arrow_forward
- Find any errors in the following function definition: void fun (int, x) { return; } // funarrow_forwardSet-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_forwardThe statement in line1 is an example of int squareT (int x, int y) //line1 { if (xarrow_forward#include using namespace std; void myfunction(int num2, int num1); lint main() { my function (5,2); return 0; } void myfunction(int num1, int num2) {if (num1>3) cout << "A1"; else if (num1<3) cout<<"A2"; else cout<<"A3";} O A2 O A1 O A3 A1 A2 A3arrow_forwardTrue or False : The concept of function abstraction hinders our code development by confusing us with the details of the function.arrow_forwardQues tion 1 The following program converts and print the Fahrenheit equivalents of all Celsius temperatures from 0 to 100 degrees, and the Celsius equivalents of all Fahrenheit temperatures from 32 to 212 degrees. Implement the integer functions as declared in the program: #include int celcius( int fTemp ); // function prototype int fahrenheit( int eTemp ); // function prototype int main() { int i, / loop counter Il display table of Fahrenheit equivalents of Celsius temperature printf "Fahrenheit equivalents of Celcius temperatures:In"); printf( "Celciust\tFahrenhe itln"); II display Fahrenheit equivalents of Celsius 0 to 100 for( i = 0; i<= 100; i+H) { printft "%d\t\W%d\n", i, fahrenheit( i ) ); II display table of Celsius equivalents of Fahrenheit temperature printf( "\nCelcius equivalents of Fahrenheit temperatures:\n"); printf( "FahrenheituCelcius\n"); Il display Celsius equivalents of Fahrenheit 32 to 212 for( i = 32; i<= 212; i+) { printf "%d\t\w%d\n", i, celcius( i ) ); return…arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning