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
Programming Assignment 6: SwapPoints Objective: To write two missing functions that manipulate objects, to complete a given program. Please complete this SwapPoints program.  so it produces the sample output shown at the end of the program, without changing the main method.  Make sure to follow the instructions in the comments of the program.  So your job is to write the two functions below, which are missing from the program: inputNewPlayerLocation: to input (x,y) coordinates from user (using Scanner), then return a Point object with those coordinates. swapPoints: to swap the coordinates of two Point objects. (Hint: To keep the main function's reference variables relevant, you can't swap Point objects entirely. You need to change the x and y coordinates inside the Point objects.)   /* Here is the Sample Output your completed program should produce: Welcome, new player. Please enter your coordinates:x: 5y: 7Welcome, new player. Please enter your coordinates:x: 10y: 15Player1…
4. Be able to write a simple user defined function that you can call and use in another program with a simple formula and some plotting. (i.e. like the kinetic energy example or the other example done in class) Write both the program and the function and show that it works.
Trigonometry: The basic MATLAB trigonometric functions are sin, cos, tan, cot, sec, and csc. The inverses, e.g., arcsin, arctan, etc., are cal- culated with asin, atan, etc. The same is true for hyperbolic functions. The inverse function at an2 takes two arguments, y and x, and gives the four- quadrant inverse tangent. The argument of these functions must be in radians. Calculate the following quantities: sin, cost, and tan. sin²+ cos². (Typing sin^2(x) for sin²x will produce an error). y cosh²z-sinh² x, with x = 32m.
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
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
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