Concept explainers
(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
Want to see the full answer?
Check out a sample textbook solutionChapter 3 Solutions
C++ How to Program (10th Edition)
Additional Engineering Textbook Solutions
Computer Science: An Overview (12th Edition)
Starting Out with C++ from Control Structures to Objects (9th Edition)
Starting out with Visual C# (4th Edition)
Starting Out with Python (3rd Edition)
C How to Program (8th Edition)
Database Concepts (7th Edition)
- (Conversion) a. Write a C++ program to convert meters to feet. The program should request the starting meter value, the number of conversions to be made, and the increment between metric values. The display should have appropriate headings and list the meters and the corresponding feet value. If the number of iterations is greater than 10, have your program substitute a default increment of 10. Use the relationship that 1 meter = 3.281 feet. b. Run the program written in Exercise 6a on a computer. Verify that your program begins at the correct starting meter value and contains the exact number of conversions specified in your input data. c. Modify the program written in Exercise 6a to request the starting meter value, the ending meter value, and the increment. Instead of the condition checking for a fixed count, the condition checks for the ending meter value. If the number of iterations is greater than 20, have your program substitute a default increment of (ending value - starting value) / 19.arrow_forwardRead the following program and answer the questions given at the end.arrow_forwardWhich of the following statements are equivalent? Which ones are correctly indented?arrow_forward
- State whether each of the following is true or false. If false, explain why h) All arguments following the format control string in a printf function must be preceded by an ampersand (&).arrow_forward-Convert SES variable to a factor and assign the value labels “low”, ”middle” and “high” to the 3 levels of thevariable. Then -Define the variables complic, comorb, depressi, diabetes as factors. For all these factors, a zero means “no” and a 1 means “yes”. Assign these value labels through the function factor() and check the change using str()arrow_forwardState the following is true or false. If false, explain why."Empty parentheses following a function name in a function definition indicate that the function does not require any parameters to perform its task."arrow_forward
- State whether each of the following is true or false. If false, explain why.a) Structures may contain variables of only one data typearrow_forwardPlease fill in the blanks for the following statements: If a function does not return a value its return type is __________________.arrow_forwardState whether each of the following is true or false. If false, explain why.a) Function printf always begins printing at the beginning of a new linearrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning