Starting Out with C++: Early Objects
Starting Out with C++: Early Objects
8th Edition
ISBN: 9780133360929
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: Addison-Wesley
Expert Solution & Answer
Book Icon
Chapter 6.11, Problem 6.18CP

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...

Blurred answer
Students have asked these similar questions
Assume that the declarations for two functions look as follows:  int Function1(double x); 2.void Function2(double x); Give some sample code that would show how each function could be used.
9-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;                                                      }
Write a definition for a void-function that has two int value parameters and outputs to the screen the product of these arguments. Write a main function that asks the user for these two numbers, reads them in, calls your function, then terminates. c++

Chapter 6 Solutions

Starting Out with C++: Early Objects

Ch. 6.8 - How many return values may a function have?Ch. 6.8 - Write a header for a function named distance. The...Ch. 6.8 - Write a header for a function named days. The...Ch. 6.8 - Prob. 6.14CPCh. 6.8 - Write a header for a function named lightYears....Ch. 6.11 - What is the difference between a static local...Ch. 6.11 - Prob. 6.17CPCh. 6.11 - Prob. 6.18CPCh. 6.13 - Prob. 6.19CPCh. 6.13 - Write the prototype and header for a function...Ch. 6.13 - Write the prototype and header for a function...Ch. 6.13 - What is the output of the following program?...Ch. 6.13 - The following program asks the user to enter two...Ch. 6.15 - Is it required that overloaded functions have...Ch. 6.15 - What is the output of the following program code?...Ch. 6.15 - What is the output of the following program code?...Ch. 6 - The ____ is the part of a function definition that...Ch. 6 - If a function doesnt return a value, the word...Ch. 6 - If function showValue has the following header:...Ch. 6 - Either a functions ____ or its ____ must precede...Ch. 6 - Values that are sent into a function are called...Ch. 6 - Special variables that hold copies of function...Ch. 6 - When only a copy of an argument is passed to a...Ch. 6 - A(n)_____ eliminates the need to place a function...Ch. 6 - A(n)_____ variable is defined inside a function...Ch. 6 - ____ variables are defined outside all functions...Ch. 6 - _____ variables provide an easy way to share large...Ch. 6 - Unless you explicitly initialize numeric global...Ch. 6 - If a function has a local variable with the same...Ch. 6 - ______ local variables retain their value between...Ch. 6 - The _____ statement causes a function to end...Ch. 6 - ______ arguments are passed to parameters...Ch. 6 - When a function uses a mixture of parameters with...Ch. 6 - Prob. 18RQECh. 6 - When used as parameters, _______ variables allow a...Ch. 6 - Reference variables are defined like regular...Ch. 6 - Reference variables allow arguments to be passed...Ch. 6 - The ________ function causes a program to...Ch. 6 - Two or more functions may have the same name, as...Ch. 6 - What is the advantage of breaking your...Ch. 6 - What is the difference between an argument and a...Ch. 6 - When a function accepts multiple arguments, does...Ch. 6 - What does it mean to overload a function?Ch. 6 - If you are writing a function that accepts an...Ch. 6 - Give an example of where an argument should he...Ch. 6 - How do you return a value from a function?Ch. 6 - Prob. 31RQECh. 6 - Prob. 32RQECh. 6 - The following statement calls a function named...Ch. 6 - A program contains the following function, int...Ch. 6 - Write a function, named timesTen, that accepts an...Ch. 6 - A program contains the following function. void...Ch. 6 - Write a function named getNumber, which uses a...Ch. 6 - Write a function named biggest that receives three...Ch. 6 - Prob. 39RQECh. 6 - Markup Write a program that asks the user to enter...Ch. 6 - Celsius Temperature Table The formula for...Ch. 6 - Falling Distance The following formula can be used...Ch. 6 - Kinetic Energy In physics, an object that is in...Ch. 6 - Winning Division Write a program that determines...Ch. 6 - Prob. 6PCCh. 6 - Lowest Score Drop Write a program that calculates...Ch. 6 - Star Search A particular talent competition has...Ch. 6 - isPrime Function A prime number is an integer...Ch. 6 - Present Value Suppose you want to deposit a...Ch. 6 - Stock Profit The profit from the sale of a stock...Ch. 6 - Multiple Stock Sales Use the function that you...Ch. 6 - Order Status The Middletown Wholesale Copper Wire...Ch. 6 - Overloaded Hospital Write a program that computes...Ch. 6 - Population In a population, the birth rate is the...Ch. 6 - Transient Population Modify Programming Challenge...Ch. 6 - Using FilesHospital Report Modify Programming...Ch. 6 - Group Project 20. Using FilesTravel Expenses This...
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning