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
How to develop a C program that receives the message sent by the provided program and displays the name and email included in the message on the screen?Here is the code of the program that sends the message for reference: typedef struct {    long tipo;    struct {        char nome[50];        char email[40];    } dados;} MsgStruct; int main() {    int msg_id, status;    msg_id = msgget(1000, 0600 | IPC_CREAT);    exit_on_error(msg_id, "Creation/Connection");    MsgStruct msg;    msg.tipo = 5;    strcpy(msg.dados.nome, "Pedro Silva");    strcpy(msg.dados.email, "pedro@sapo.pt");    status = msgsnd(msg_id, &msg, sizeof(msg.dados), 0);    exit_on_error(status, "Send");    printf("Message sent!\n");}
9. Let L₁=L(ab*aa), L₂=L(a*bba*). Find a regular expression for (L₁ UL2)*L2. 10. Show that the language is not regular. L= {a":n≥1} 11. Show a derivation tree for the string aabbbb with the grammar S→ABλ, A→aB, B→Sb. Give a verbal description of the language generated by this grammar.
14. Show that the language L= {wna (w) < Nь (w) < Nc (w)} is not context free.
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