© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 8 - Interest Calculator Application: Introducing.

Slides:



Advertisements
Similar presentations
Switch code for Lab 4.2 switch (input) { /* input is a variable that we will test. */ case 'M': printf("The prefix is equal to 1E6.\n"); break; case 'k':
Advertisements

© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 16 – Shopping List Application: Introducing.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 10 – Enhancing the Wage Calculator Application:
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 13 – Salary Survey Application: Introducing.
Microsoft Visual Basic: Reloaded Chapter Seven More on the Repetition Structure.
 2006 Pearson Education, Inc. All rights reserved Control Statements: Part 1.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 11 – Fundraiser Application: Introducing Scope.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 4 – Introducing Algorithms, Pseudocode and.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 4 – C Program Control Outline 4.1Introduction.
 2008 Pearson Education, Inc. All rights reserved Control Statements: Part 2.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 14 – Student Grades Application: Introducing.
 2006 Pearson Education, Inc. All rights reserved Control Statements: Part 2.
11.3 Function Prototypes A Function Prototype contains the function’s return type, name and parameter list Writing the function prototype is “declaring”
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 17 – Payroll Application: Introducing Inheritance.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Control Structures: continued.
 2007 Pearson Education, Inc. All rights reserved C Program Control.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 7 – Class Average Application: Introducing.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 9 – Income Tax Calculator Application: Introducing.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 6 – Car Payment Calculator Application: Introducing.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 9 Car Payment Calculator Application Introducing the Do While...Loop and Do Until...Loop.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 2 - Welcome Application: Introduction to C++
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 2 - HelloWorld Application: Introduction to.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Looping Exercises Deciding Which Loop to Use At this.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Interest Calculator Application Introducing the For...Next Repetition Statements.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 8 - Interest Calculator Application: Introducing.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 10 – Enhancing the Wage Calculator Application:
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 7.1 Test-Driving the Wage Calculator Application.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 4 – Wage Calculator Application: Introducing.
Lecture 4 C Program Control Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 5 – Dental Payment Application: Introducing.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 9 – Income Tax Calculator Application: Introducing.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 6 – Car Payment Calculator Application: Introducing.
University of Palestine software engineering department Introduction to data structures Control Statements: Part 1 instructor: Tasneem Darwish.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 17 – Flag Quiz Application Introducing One-Dimensional.
An Introduction to Programming with C++ Sixth Edition Chapter 7 The Repetition Structure.
Loop.  While Loop  Do-while Loop  For Loop Continue Statement Conclusion Loop Loop.
Dale Roberts Program Control using Java - Repetition Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Class Average Application Introducing the Do...Loop While and Do...Loop Until.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Flow Control (for) Outline 4.1Introduction 4.2The.
Chapter 3: Assignment, Formatting, and Interactive Input.
 2003 Prentice Hall, Inc. All rights reserved. Outline 1 fig02_07.cpp (1 of 2) 1 // Fig. 2.7: fig02_07.cpp 2 // Class average program with counter-controlled.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 7 – Class Average Application: Introducing.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 20.1 Test-Driving the Shipping Hub Application.
Control Structures - Selections - Repetitions/iterations (part 2) 1 -Based on slides from Deitel & Associates, Inc. - Revised by T. A. Yang.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 5.3Math Library Functions Math library functions –perform.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 18 – Student Grades Application Introducing.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 10 - JavaScript/JScript: Control Structures II Outline 10.1Introduction 10.2Essentials of.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 5.1 Test-Driving the Inventory Application.
Java™ How to Program, Early Objects Version, 8/e © by Pearson Education, Inc. All Rights Reserved.
Sections 5.1 – 5.4 © Copyright by Pearson Education, Inc. All Rights Reserved.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 8.1 Test-Driving the Car Payment Calculator.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 15 – Fund Raiser Application Introducing.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 3 – Inventory Application: Introducing Variables,
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 3 – Inventory Application: Introducing Variables,
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 10.1 Test-Driving the Interest Calculator.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 24.1 Test-Driving the Enhanced Car Payment.
CSCI/CMPE 4341 Topic: Programming in Python Chapter 4: Control Structures (Part 2) Xiang Lian The University of Texas – Pan American Edinburg, TX
 2006 Pearson Education, Inc. All rights reserved Control Statements: Part 2.
Chapter 05 (Part II) Control Statements: Part II.
 2003 Prentice Hall, Inc. All rights reserved. 1 Outline 11.1 Test-Driving the Interest Calculator Application 11.2 Essentials of Counter-Controlled Repetition.
C++ How to Program, 8/e © by Pearson Education, Inc. All Rights Reserved.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Enhanced Car Payment Calculator Application Introducing Exception Handling.
 2008 Pearson Education, Inc. All rights reserved Control Statements: Part 2.
Chapter 4 C Program Control Part I
Lecture 7: Repeating a Known Number of Times
Tutorial 9 - Car Payment Calculator Application Introducing the while Repetition Statement Outline 9.1 Test-Driving the Car Payment Calculator Application.
Chapter 6 Control Statements: Part 2
JavaScript: Control Statements II
Presentation transcript:

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 8 - Interest Calculator Application: Introducing the for Repetition Statement and the Math Library Outline 8.1 Test-Driving the Interest Calculator Application 8.2 Essentials of Counter-Controlled Repetition 8.3 Introducing the for Repetition Statement 8.4 Examples Using the for Statement 8.5 Constructing the Interest Calculator Application 8.6 Wrap-Up

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Objectives In this tutorial, you will learn to: –Execute statements repeatedly with the for repetition statement. –Use the math library to execute common mathematical functions.

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 8.1Test Driving the Interest Calculator Application

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Figure 8.1 Running the completed Interest Calculator application. 8.1Test Driving the Interest Calculator Application (Cont.) Figure 8.2 Completed Interest Calculator application output. Displaying the result in tabular format

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 8.2Essentials of Counter-Controlled Repetition Essential elements of counter-controlled repetition 1.Data type and name of the control variable ( int counter; )  Initial value of the control variable ( int counter = 2;) 2.The condition that tests for the final value of the control variable ( counter <= 5; ) 3.The increment (or decrement) by which the control variable is modified during each iteration of the loop ( counter++; )

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Figure 8.3 Examining counter-controlled repetition using a while statement. 1. Names control variable and initializes its value to 2 2. Condition that tests whether value of control variable is less than or equal to 5, meaning that 5 is the final value for which the condition is true 3. Increment counter by 1 for each iteration of the loop Error: move left << setw(10) before months (see slide 18)

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 8.3Introducing the for Repetition Statement The for statement specifies all elements of counter-controlled repetition in the header Figure 8.4 Code segment for the Car Payment Calculator application that demonstrates the for statement.

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Figure 8.5 for header components. 8.3Introducing the for Repetition Statement (Cont.) Common error –Controlling a counter-controlled loop with a floating-point value Always use integer values to control counter-controlled loops

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Figure 8.6 for repetition statement UML activity diagram. 8.3Introducing the for Repetition Statement (Cont.)

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 8.4Examples Using the for Statement Vary the control variable from 1 to 100 in increments of 1 Vary the control variable from 100 to 1 in decrements of 1 Vary the control variable from 7 to 77 in increments of 7

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 8.5Constructing the Interest Calculator Application Prompt the user for and input the principal, interest rate and years Display a table header For each year, starting at 1 and ending with the number of years entered Calculate and display the year Calculate and display the current value of the investment Figure 8.7 Pseudocode for the Interest Calculator application.

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 8.5Constructing the Interest Calculator Application (Cont.) Figure 8.8 Defining variables to store the principal, interest rate and investment duration. Defining variables to store user input

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 8.5Constructing the Interest Calculator Application (Cont.) Figure 8.9 Prompting the user for and inputting the principal, interest rate and investment duration. Prompting the user for and inputting the principal, interest rate and investment duration

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 8.5Constructing the Interest Calculator Application (Cont.) Using the setw and left stream manipulators to display a table header Figure 8.10 Displaying a table header. Note: setw() function used correctly. Displaying a table header Using the fixed and setprecision stream manipulators to format text Figure 8.11 Formatting floating-point numbers. Formatting floating- point numbers

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 8.5Constructing the Interest Calculator Application (Cont.) for header declares all essential items of counter-controlled repetition Figure 8.12 Creating the for statement. Empty for statement

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 8.5Constructing the Interest Calculator Application (Cont.) C++ Standard Math Library – Necessary for the pow function –Performs exponentiation (there is no exponential operator in C++) Also includes functions for square roots and trigonometry etc. Figure 8.13 Including the standard library header file. Including

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 8.5Constructing the Interest Calculator Application (Cont.) The pow function takes two arguments –First argument is value to be raised to a power –Second argument specifies power to which the first argument will be raised Figure 8.14 Calculating amount on deposit after specified number of years. Using function pow to calculate the amount on deposit after the specified number of years

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 8.5Constructing the Interest Calculator Application (Cont.) Figure 8.15 Displaying the amount on deposit for each year. Displaying the amount on deposit for each year Figure 8.16 Completed application output.

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. InterestCalculator.cpp (1 of 3) Include the standard library header file Define variables to store user input

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. InterestCalculator.cpp (2 of 3) Prompt for and input the principal, rate and year Display the table header and format floating-point values

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. InterestCalculator.cpp (3 of 3) Use a for statement to calculate the amount on deposit and display it in tabular format

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Lab and Homework Assignment Tutorial 8 − Interest Calculator Application. Turn in annotated source file with your own comments. Answer and Turn-in Tutorial 8 Questions 8.1 to Always write the question followed by the answer. Remember to highlight the answer. Exercises 8.11, 8.12, and the Programming Challenge For Exercise 8.11 start with your completed Tutorial 8 − Interest Calculator Application. Due next Wednesday

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Appendix AExamples Using the for Statement Vary the control variable from 1 to 100 in increments of 1 Vary the control variable from 100 to 1 in decrements of 1 Vary the control variable from 7 to 77 in increments of 7