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 (9th Edition)
- 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_forwardDescribe the performance considerations when heavily utilizing function objects.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_forwardConsider the following function main:Int main(){int inStock[10][4];int alpha [20];int beta[20];int gamma[4]= {11,13,15,17};int delta [10] = {3,5,2,6,10,9,7,11,1,8};} a) Write the definition of the function setZero that initializes any one-dimentional array of type int to 0.b) Write the definition of the function inputArray that prompts the user to input 20 numbers and stores the numbers into alpha.c) Write the definition of the function doubleArray that initializes the elements of beta to two times the corresponding elements of alpha. Make sure that you prevent the function from modifying the elements of alpha.d) Write the definition of the function copyGamma that sets the elements of the first row of inStock to gamma and the remaining rows of inStock to three times the previous row of inStock. Make sure that you prevent the function from modifying the elements of gamma.e) Write the definitions of the function copyAlphaBeta that stores alpha into the first five rows of inStock and beta…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_forwardin c++, "Overload of functions" Write an overloaded function that returns a value based on a set of formal parameters: . z={ x - a; x + a - barrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning