C++ How to Program (10th Edition)
C++ How to Program (10th Edition)
10th Edition
ISBN: 9780134448237
Author: Paul J. Deitel, Harvey Deitel
Publisher: PEARSON
bartleby

Concept explainers

bartleby

Videos

Textbook Question
Book Icon
Chapter 3, Problem 3.13E

(Removing Duplicated Code in the main Function) In Fig. 3.9, the main function contains six statements (lines 14-15, 16-17, 26-27, 28-29, 37-38 and 39-40) that each display an Account object's name and balance. Study these statements and you'll notice that they differ only in the Account object being manipulated-accountl or account2. In this exercise, you'll define a new displayAccount function that contains one copy of that output statement. The member function's parameter will be an Account Object and the member function will output the object's name and balance. You'll then replace the six duplicated statements in main with calls to displayAccount, passing as an argument the specific Account object to output.

    Modify Fig. 3.9 to define the following displayAccount function after the using directive and before main:

void displayAccount(Account accountToDisplay) {

// place the statement that displays

// accountToDisplay's name and balance here

}

Replace the comment in the member function's body with a statement that displays accountToDisplay’s name and balance.

  Once you've completed displayAccount’s declaration, modify main to replace the statements that display each Account’s name and balance with calls to displayAccount of the form:

  displayAccount(nameOfAccountObject);

In each call, the argument should be the account1 or account2 object, as appropriate. Then, test the updated program to ensure that it produces the same output as shown in Fig. 3.9.

Blurred answer
Students have asked these similar questions
What is the screen output of the following code
Using your own words, please describe what a function is. Defend your statements with a concrete illustration.
Please help me to print two lines given below in the same line but the condition given by my prof was to use two print() statements to print both lines. But remember the lines should be printed in the same line and separated by a single space. "Practice" "Assignment"
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar 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
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Literals in Java Programming; Author: Sudhakar Atchala;https://www.youtube.com/watch?v=PuEU4S4B7JQ;License: Standard YouTube License, CC-BY
Type of literals in Python | Python Tutorial -6; Author: Lovejot Bhardwaj;https://www.youtube.com/watch?v=bwer3E9hj8Q;License: Standard Youtube License