Problem Solving with C++ (10th Edition)
Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134448282
Author: Walter Savitch, Kenrick Mock
Publisher: PEARSON
Question
Book Icon
Chapter 9, Problem 1P
Program Plan Intro

Program Plan:

  • Include required header files.
  • Declaration of function prototype.
  • Definition for function “main()”.
    • Declare and initialize the variable “var”.
    • Print the value before calling function
    • Call the function “addOne()”.
    • Print the value after calling function.
    • Return the value “0”.
  • Definition of function “addOne()”.
    • Increment the pointer variable.

Expert Solution & Answer
Check Mark
Program Description Answer

The given program is to add one to the integer referenced by “ptrNum” by using reference parameter syntax.

Explanation of Solution

//Include required header files

#include<iostream>

using namespace std;

//Declaration of function header

void addOne(int *ptrNum);

//Definition of function main()

int main()

{

    //Declare and initialize the variable "var".

    int var = 10;

    //Print the value before calling function

  cout << "Value before calling function = " << var << '\n';

    //Call the function

    addOne(&var);

    //Print the value after calling function

  cout << "Value after calling function = " << var << '\n';

    //Return the value "0"

    return 0;

}

//Definition of function "addOne()"

void addOne(int *ptrNum)

{

    //Increment the pointer variable

    *ptrNum = *ptrNum + 1;

}

Sample Output

Output:

Value before calling function = 5

Value after calling function = 6

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
Create a function in C language that takes two integers x, and y as the parameters and returns the sum and the absolute difference of both the numbers but the return type of the function should be void. You can add extra parameters to the function but the function should not return anything and should send the required values as well. Test your function for the numbers 10, and 5 inside the main function.
In c++ language. The code should be structured( only one return in each function, no exit or continue, or break)
C Programming Problem : Write a C program with a function that takes an integer value (1 <- integer value < 9999) and returns the number with its digits reversed. For example, given the number 6798, the function should return 8976. Those two- original number and reversed number- numbers will pass to another function as parameters and calculate their sum. The program should use the function reverseDigits to reverse the digits and SumOriginalReverse to calculate their sum. Your output should appear in the following format: Output reverse digiS 4321 Main Enter a number between 1 and 9999: 6798 The number with its digits reversed is: 8976 6798 + 8976 - 15774 12.34 JomoriginalRevers Enter a number between I and 9999: 6655 The number with its digits reversed is: 5566 6655 + 5566 = 12221 Enter a number between 1 and 9999: 8 The number with its digits reversed is: 8 8 + 8 = 16 Enter a number between 1 and 9999: 123 The number with its digits reversed is: 321 123 + 321 = 444 Enter a number…
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr