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)
- Turtle(Python programming) Include a scarf around the snowman’s neck and label each step with a comment #.arrow_forwardModify the below code according to what is asking you to do. Show your modified code in a picture, please.arrow_forwardPlease help answer these two questions in Python. (See attached image) Attach screenshots of your code for clarity.arrow_forward
- [Fish Tank] You play with a clown fish that has an initial size so. The fish can eat other fish in a tank organized in m columns and n rows. The fish at column i and row j has a positive size si,j. When your fish eats another fish, it grows by that amount. For example, if your clown fish has a size of 10 and eats a fish of size 5, it becomes of size 15. You cannot eat a fish that is bigger than your size. The game starts by eating any fish in the first (left-most) column that is not bigger than yours. After that, you advance one column at a time by moving right. You have only three allowed moves. You either stay at the same row, move one row higher or one row lower. You will always move to the right. Thus, you will make exactly m moves to advance from left to right. Your goal is to exit the fish tank from the right with the biggest possible size. The figure below shows an example with the best answer highlighted. In this case, the final fish size is 71 (10+8+7+24+22). You are required…arrow_forwardProgram 4 - CCC '07 J1 In the story Goldilocks and the Three Bears, each bear had a bowl of porridge to eat while sitting at his/her favourite chair. What the story didn't tell us is that Goldilocks moved the bowls around on the table, so the bowls were not at the right seats anymore. The bowls can be sorted by weight with the lightest bowl being the Baby Bear's bowl, the medium bowl being the Mama Bear's bowl and the heaviest bowl being the Papa Bear's bowl. Write a program that reads in three weights and prints out the weight of Mama Bear's bowl. You may assume all weights are positive integers less than 100. Sample Input 10 8arrow_forwardA cantilever beam is under a concentrate load P (N), the beam has a length of L (m). P L y Complete the Python function below to find the support reaction force in y direction RF (N) and reaction moment RM (N*m) at the clamped end of the beam x = 0. Be careful of the sign of force and moment.arrow_forward
- Please complete the exercise as instructed and do not use global variables. As well, please follow the guildines of what the solution cannot have in the second image provided. Thank you!arrow_forward7. Write a function that evaluates the area of a pentagon. Use "math.pi", for pi, and "math.sqrt" for square root. Write the solution on the space provided below. You do not need to run the code. DII 3.2 (Geometry: area of a pentagon) Write a program that prompts the user to enter the length from the center of a pentagon to a vertex and computes the area of the pen- tagon, as shown in the following figure. 3√3 2 The formula for computing the area of a pentagon is Area -s², where s is TT the length of a side. The side can be computed using the formula s = 2r sin 5 = where r is the length from the center of a pentagon to a vertex. Here is a sample run:arrow_forward13. What is the difference between a formal parameter and an argument? Group of answer choices A function’s argument is referred to as the formal argument to distinguish it from the value that is passed in during the function call. The parameter is the passed value. They are identical but using different terms. A function’s parameter is used for passing by reference. The argument is used for passing by value. A function’s parameter is referred to as the formal parameter to distinguish it from the value that is passed in during the function call. The argument is the passed value. A function’s parameter is used for passing by value. The argument is used for passing by reference.arrow_forward
- Hi this is my firs time so i have homeworek i need hlep in it : Create the principal program, which will complete the following tasks :a. Create a new Student object by reading the required details and by applying at least one type of data validation of your choice on the input. b. Read and save the list of module names and the list of module marks awarded to the student in the two assignments. c. Display the transcript of the student by calling the adequate method.d. Repeating the previous tasks until the user decides to exit. thxarrow_forwardProblem Statement: The mathematician Conway imagined a game, called game of life, which considered cells that are susceptible to reproduce, disappear, or survive when they obey certain rules. These cells are represented by elements on a grid of squares, where a grid has an arbitrary size. Thus, each cell (except those on the boundaries of the grid) is surrounded by eight squares that contain other cells. The rules are stated as follows: 1. Survival: Each cell that has two or three adjacent cells survives until the next generation.2. Death: Each cell that has at least four adjacent cells disappears (or dies) by overpopulation. Also, each cell that has at most one adjacent cell dies by isolation.3. Birth: Each empty square (i.e., dead cell) that is adjacent to exactly three cells gives birthto a new cell for the next generation.It is worth noting that all births and deaths occur at the same time during a generation. Write a program that simulates this game and displays all successive…arrow_forwardphythonarrow_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