Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Science 1620 Programming & Problem Solving.

Similar presentations


Presentation on theme: "Computer Science 1620 Programming & Problem Solving."— Presentation transcript:

1 Computer Science 1620 Programming & Problem Solving

2 Programming is the science (art) of solving a problem using a computer program one of the greatest challenges involves translation: problem is stated in human language solution is in computer language how do we make this translation?

3 Programming programming efficiency can be improved through three steps pre-coding analysis and design structured programming incremental programming

4 Analysis & Design you are typically given a problem statement often, from a client with no programming background this means the description will be far from C++ you must somehow develop a solution to this problem using C++ what steps do you take? Solution Problem

5 One Solution (New Programmers) start coding right away generate a complete program right away Solution Problem Coding

6 One Solution (New Programmers) start coding right away generate a complete program right away Code is compiled compiler errors result in recoding Solution Problem Coding Compiling Errors

7 One Solution (New Programmers) start coding right away generate a complete program right away Code is compiled compiler errors result in recoding Code is tested runtime errors result in recoding Solution Problem Coding Compiling Execution Errors

8 One Solution (New Programmers) start coding right away generate a complete program right away Code is compiled compiler errors result in recoding Code is tested runtime errors result in recoding When no errors are tested, code is considered a solution Solution Problem Coding Compiling Execution Errors

9 Problem: many errors are not a result of programming error, but rather with a flaw in the program logic many of these errors could be avoided if the program was designed more carefully Solution Problem Coding Compiling Execution Errors

10 Solution before you write any code: analyze the problem thoroughly analysis design the solution without any code algorithm design

11 Solution Problem Coding Compiling Execution Errors Analysis Algorithm Design These two steps, if done correctly, will reduce the number of corrections to be made here.

12 Analysis (from text): 1. Thoroughly understand the problem 2. Understand the problem requirements. Requirements can include: 1. whether the program requires interaction with the user 2. whether it produces output, what the output looks like 3. what types of data will be used 3. If the problem is complex, it may need to be divided into smaller problems (divide and conquer). Analysis needs to be applied to each step.

13 Algorithm Design a step by step solution of what the program will do NOT WRITTEN IN CODE use pseudocode, or an English description of what you want your program to do your pseudocode will progressively get closer and closer to real code

14 Example (Text): A program to compute the perimeter and area of a rectangle. The length and width of the rectangle will be specified by the user, as an integer. Analysis: will this program require input from the user? Yes: we will need to know the length and width of the rectangle will this program require output? Yes: we will need to display the area and perimeter of the rectangle. what will the format of the output be? int, since the inputs are ints what will the data types be: int

15 Design Step 1: Read the length of the rectangle from the user. Step 2: Read the width of the rectangle from the user. Step 3: Compute the perimeter of the rectangle. Step 4: Compute the area of the rectangle Step 5: Output the results of this computation to the screen.

16 Example (Text): Every salesperson has a base salary. The salesperson also receives a bonus at the end of each month, based on the following criteria: If the salesperson has been with the store for five years or less, the bonus is $10 for each year that he or she has worked there. If the salesperson has been with the store for more than five years, the bonus $20 for each year that he or she has worked there. The salesperson can earn an additional bonus through commission: if the sales made by the person are more than $5000 but less than $10000, the salesperson receives a 3% commission on sales. If the total sales by the person is at least $10000 the salesperson receives a 6% sales commission. Write a program to calculate the monthly paycheque for an employee.

17 Analysis: will this program require input from the user? base salary how long the person has worked at the store what the monthly sales of the person was will this program require output? Yes: The monthly salary total. what will the format of the output be? should probably restrict the output to 2 decimal places (currency) what will the data types be: base salary: floating point time with store: integer or floating point monthly sales: floating point salary total: floating point Example (Text): Every salesperson has a base salary. The salesperson also receives a bonus at the end of each month, based on the following criteria: If the salesperson has been with the store for five years or less, the bonus is $10 for each year that he or she has worked there. If the salesperson has been with the store for more than five years, the bonus $20 for each year that he or she has worked there. The salesperson can earn an additional bonus through commission: if the sales made by the person are more than $5000 but less than $10000, the salesperson receives a 3% commission on sales. If the total sales by the person is at least $10000, the salesperson receives a 6% sales commission. Write a program to calculate the monthly salary for an employee.

18 Design Step 1: Read the base salary of the employee. Step 2: Read the number of years employee has been with company Step 3: Read the monthly sales of the employee Step 4: Calculate the time bonus of the employee Step 5: Calculate the commission bonus of the employee Step 6: Sum the base salary, time bonus, and commission bonus of the employee Step 7: Output the computed total

19 Example: Suppose you invest X dollars into an investment at Y%. Suppose further that every 4 years, you withdraw Z dollars from the investment. However, you may not withdraw more than the investment is currently worth. Write a program that computes and outputs the value of the investment for 20 years.

20 Analysis: will this program require input from the user? starting dollar amount interest rate withdraw amount will this program require output? Yes: The yearly balance of the investment. what will the format of the output be? should probably restrict the output to 2 decimal places (currency) what will the data types be: everything is floating point. Example: Suppose you invest X dollars into an investment at Y%. Suppose further that every 4 years, you withdraw Z dollars from the investment. However, you may not withdraw more than the investment is currently worth. Write a program that computes and outputs the value of the investment for 20 years.

21 Design Step 1: Read the starting balance of the investment Step 2: Read the interest rate of the investment Step 3: Read the withdraw amount of the investment Step 4: Output account balance for the next twenty years

22 Structured Programming "divide and conquer programming" a methodology for turning design into code Process: for each step in your design if the step can be translated into a line of code, then replace it with that line of code otherwise, decompose that step into smaller, simpler steps repeat until every step has been converted to code

23 Design (area and perimeter calculation) Step 1: Read the length of the rectangle from the user. Step 2: Read the width of the rectangle from the user. Step 3: Compute the perimeter of the rectangle. Step 4: Compute the area of the rectangle Step 5: Output the results of this computation to the screen.

24 Design (area and perimeter calculation) Step 1: Read the length of the rectangle from the user. Step 2: Read the width of the rectangle from the user. Step 3: Compute the perimeter of the rectangle. Step 4: Compute the area of the rectangle Step 5: Output the results of this computation to the screen. Can this step be translated to one line of code? not really let's decompose it into simpler steps

25 Design (area and perimeter calculation) Step 1.1 Declare storage for the length Step 1.2 Prompt the user for a length Step 1.3 Read the entered value into defined storage Step 2: Read the width of the rectangle from the user. Step 3: Compute the perimeter of the rectangle. Step 4: Compute the area of the rectangle Step 5: Output the results of this computation to the screen.

26 Design (area and perimeter calculation) Step 1.1 Declare storage for the length Step 1.2 Prompt the user for a length Step 1.3 Read the entered value into defined storage Step 2: Read the width of the rectangle from the user. Step 3: Compute the perimeter of the rectangle. Step 4: Compute the area of the rectangle Step 5: Output the results of this computation to the screen. Can this step be translated to one line of code?

27 Design (area and perimeter calculation) int length; Step 1.2 Prompt the user for a length Step 1.3 Read the entered value into defined storage Step 2: Read the width of the rectangle from the user. Step 3: Compute the perimeter of the rectangle. Step 4: Compute the area of the rectangle Step 5: Output the results of this computation to the screen.

28 Design (area and perimeter calculation) int length; Step 1.2 Prompt the user for a length Step 1.3 Read the entered value into defined storage Step 2: Read the width of the rectangle from the user. Step 3: Compute the perimeter of the rectangle. Step 4: Compute the area of the rectangle Step 5: Output the results of this computation to the screen. Can this step be translated to one line of code?

29 Design (area and perimeter calculation) int length; cout << "Please enter the rectangle's length: "; Step 1.3 Read the entered value into defined storage Step 2: Read the width of the rectangle from the user. Step 3: Compute the perimeter of the rectangle. Step 4: Compute the area of the rectangle Step 5: Output the results of this computation to the screen.

30 Design (area and perimeter calculation) int length; cout << "Please enter the rectangle's length: "; Step 1.3 Read the entered value into defined storage Step 2: Read the width of the rectangle from the user. Step 3: Compute the perimeter of the rectangle. Step 4: Compute the area of the rectangle Step 5: Output the results of this computation to the screen. Can this step be translated to one line of code?

31 Design (area and perimeter calculation) int length; cout << "Please enter the rectangle's length: "; cin >> length; Step 2: Read the width of the rectangle from the user. Step 3: Compute the perimeter of the rectangle. Step 4: Compute the area of the rectangle Step 5: Output the results of this computation to the screen.

32 Design (area and perimeter calculation) int length; cout << "Please enter the rectangle's length: "; cin >> length; Step 2: Read the width of the rectangle from the user. Step 3: Compute the perimeter of the rectangle. Step 4: Compute the area of the rectangle Step 5: Output the results of this computation to the screen. Can this step be translated to one line of code? not really decompose into simpler elements

33 Design (area and perimeter calculation) int length; cout << "Please enter the rectangle's length: "; cin >> length; Step 2.1 Declare storage for the width Step 2.2 Prompt the user for a width Step 2.3 Read the entered value into defined storage Step 3: Compute the perimeter of the rectangle. Step 4: Compute the area of the rectangle Step 5: Output the results of this computation to the screen.

34 Design (area and perimeter calculation) int length; cout << "Please enter the rectangle's length: "; cin >> length; int width; cout << "Please enter the rectangle's width: "; cin >> width; Step 3: Compute the perimeter of the rectangle. Step 4: Compute the area of the rectangle Step 5: Output the results of this computation to the screen.

35 Design (area and perimeter calculation) int length; cout << "Please enter the rectangle's length: "; cin >> length; int width; cout << "Please enter the rectangle's width: "; cin >> width; Step 3: Compute the perimeter of the rectangle. Step 4: Compute the area of the rectangle Step 5: Output the results of this computation to the screen.

36 Design (area and perimeter calculation) int length; cout << "Please enter the rectangle's length: "; cin >> length; int width; cout << "Please enter the rectangle's width: "; cin >> width; int perimeter = 2 * (length + width); Step 4: Compute the area of the rectangle Step 5: Output the results of this computation to the screen.

37 Design (area and perimeter calculation) int length; cout << "Please enter the rectangle's length: "; cin >> length; int width; cout << "Please enter the rectangle's width: "; cin >> width; int perimeter = 2 * (length + width); Step 4: Compute the area of the rectangle Step 5: Output the results of this computation to the screen.

38 Design (area and perimeter calculation) int length; cout << "Please enter the rectangle's length: "; cin >> length; int width; cout << "Please enter the rectangle's width: "; cin >> width; int perimeter = 2 * (length + width); int area = length * width; Step 5: Output the results of this computation to the screen.

39 Design (area and perimeter calculation) int length; cout << "Please enter the rectangle's length: "; cin >> length; int width; cout << "Please enter the rectangle's width: "; cin >> width; int perimeter = 2 * (length + width); int area = length * width; Step 5: Output the results of this computation to the screen.

40 Design (area and perimeter calculation) int length; cout << "Please enter the rectangle's length: "; cin >> length; int width; cout << "Please enter the rectangle's width: "; cin >> width; int perimeter = 2 * (length + width); int area = length * width; Step 5.1: Output the perimeter to the screen Step 5.2: Output the area to the screen.

41 Design (area and perimeter calculation) int length; cout << "Please enter the rectangle's length: "; cin >> length; int width; cout << "Please enter the rectangle's width: "; cin >> width; int perimeter = 2 * (length + width); int area = length * width; cout << "The perimeter of the rectangle is " << perimeter << endl; Step 5.2: Output the area to the screen.

42 Design (area and perimeter calculation) int length; cout << "Please enter the rectangle's length: "; cin >> length; int width; cout << "Please enter the rectangle's width: "; cin >> width; int perimeter = 2 * (length + width); int area = length * width; cout << "The perimeter of the rectangle is " << perimeter << endl; cout << "The area of the rectangle is " << area << endl;

43 #include using namespace std; int main() { return 0; } Write program to compute the perimeter and area of a rectangle. The size of the rectangle will be specified by the user. int length; cout << "Please enter the rectangle's length: "; cin >> length; int width; cout << "Please enter the rectangle's width: "; cin >> width; int perimeter = 2 * (length + width); int area = length * width; cout << "The perimeter of the rectangle is " << perimeter << endl; cout << "The area of the rectangle is " << area << endl;

44

45 Design (salary program) Step 1: Read the base salary of the employee. Step 2: Read the number of years employee has been with company Step 3: Read the monthly sales of the employee Step 4: Calculate the time bonus of the employee Step 5: Calculate the commission bonus of the employee Step 6: Sum the base salary, time bonus, and commission bonus of the employee Step 7: Output the computed total

46 Design (salary program) Step 1: Read the base salary of the employee. Step 2: Read the number of years employee has been with company Step 3: Read the monthly sales of the employee Step 4: Calculate the time bonus of the employee Step 5: Calculate the commission bonus of the employee Step 6: Sum the base salary, time bonus, and commission bonus of the employee Step 7: Output the computed total

47 Design (salary program) Step 1.1 Declare storage for the base Step 1.2 Prompt the user for a base salary Step 1.3 Read the entered value into defined storage Step 2: Read the number of years employee has been with company Step 3: Read the monthly sales of the employee Step 4: Calculate the time bonus of the employee Step 5: Calculate the commission bonus of the employee Step 6: Sum the base salary, time bonus, and commission bonus of the employee Step 7: Output the computed total

48 Design (salary program) double base; cout << "Please enter the employee's monthly base salary: "; cin >> base; Step 2: Read the number of years employee has been with company Step 3: Read the monthly sales of the employee Step 4: Calculate the time bonus of the employee Step 5: Calculate the commission bonus of the employee Step 6: Sum the base salary, time bonus, and commission bonus of the employee Step 7: Output the computed total

49 Design (salary program) double base; cout << "Please enter the employee's monthly base salary: "; cin >> base; Step 2: Read the number of years employee has been with company Step 3: Read the monthly sales of the employee Step 4: Calculate the time bonus of the employee Step 5: Calculate the commission bonus of the employee Step 6: Sum the base salary, time bonus, and commission bonus of the employee Step 7: Output the computed total

50 Design (salary program) double base; cout << "Please enter the employee's monthly base salary: "; cin >> base; Step 2.1 Declare storage for employee # of years Step 2.2 Prompt the user for the employee's # of years Step 2.3 Read the entered value into defined storage Step 3: Read the monthly sales of the employee Step 4: Calculate the time bonus of the employee Step 5: Calculate the commission bonus of the employee Step 6: Sum the base salary, time bonus, and commission bonus of the employee Step 7: Output the computed total

51 Design (salary program) double base; cout << "Please enter the employee's monthly base salary: "; cin >> base; int years; cout << "Please enter employee's years with the company: "; cin >> years; Step 3: Read the monthly sales of the employee Step 4: Calculate the time bonus of the employee Step 5: Calculate the commission bonus of the employee Step 6: Sum the base salary, time bonus, and commission bonus of the employee Step 7: Output the computed total

52 Design (salary program) double base; cout << "Please enter the employee's monthly base salary: "; cin >> base; int years; cout << "Please enter employee's years with the company: "; cin >> years; Step 3: Read the monthly sales of the employee Step 4: Calculate the time bonus of the employee Step 5: Calculate the commission bonus of the employee Step 6: Sum the base salary, time bonus, and commission bonus of the employee Step 7: Output the computed total

53 Design (salary program) double base; cout << "Please enter the employee's monthly base salary: "; cin >> base; int years; cout << "Please enter employee's years with the company: "; cin >> years; Step 3.1 Declare storage for monthly sales Step 3.2 Prompt the user for the monthly sales of the employee Step 3.3 Read the entered value into defined storage Step 4: Calculate the time bonus of the employee Step 5: Calculate the commission bonus of the employee Step 6: Sum the base salary, time bonus, and commission bonus of the employee Step 7: Output the computed total

54 Design (salary program) double base; cout << "Please enter the employee's monthly base salary: "; cin >> base; int years; cout << "Please enter employee's years with the company: "; cin >> years; double sales; cout << "Please enter the monthly sales of the employee: "; cin >> sales; Step 4: Calculate the time bonus of the employee Step 5: Calculate the commission bonus of the employee Step 6: Sum the base salary, time bonus, and commission bonus of the employee Step 7: Output the computed total

55 Design (salary program) double base; cout << "Please enter the employee's monthly base salary: "; cin >> base; int years; cout << "Please enter employee's years with the company: "; cin >> years; double sales; cout << "Please enter the monthly sales of the employee: "; cin >> sales; Step 4: Calculate the time bonus of the employee Step 5: Calculate the commission bonus of the employee Step 6: Sum the base salary, time bonus, and commission bonus of the employee Step 7: Output the computed total If the salesperson has been with the store for five years or less, the bonus is $10 per year of work. If the salesperson has been with the store for more than five years, the bonus is $20 for each year of work.

56 Design (salary program) double base; cout << "Please enter the employee's monthly base salary: "; cin >> base; int years; cout << "Please enter employee's years with the company: "; cin >> years; double sales; cout << "Please enter the monthly sales of the employee: "; cin >> sales; Step 4.1: If the years with the company is less than or equal to 5 Step 4.1.1: Compute the time bonus as 10 times the years with the company Step 4.2: Otherwise Step 4.2.1 Compute the time bonus as 20 times the years with the company Step 5: Calculate the commission bonus of the employee Step 6: Sum the base salary, time bonus, and commission bonus of the employee Step 7: Output the computed total If the salesperson has been with the store for five years or less, the bonus is $10 per year of work. If the salesperson has been with the store for more than five years, the bonus is $20 for each year of work.

57 Design (salary program) double base; cout << "Please enter the employee's monthly base salary: "; cin >> base; int years; cout << "Please enter employee's years with the company: "; cin >> years; double sales; cout << "Please enter the monthly sales of the employee: "; cin >> sales; if (years <= 5) Step 4.1.1: Compute the time bonus as 10 times the years with the company Step 4.2: Otherwise Step 4.2.1 Compute the time bonus as 20 times the years with the company Step 5: Calculate the commission bonus of the employee Step 6: Sum the base salary, time bonus, and commission bonus of the employee Step 7: Output the computed total

58 Design (salary program) double base; cout << "Please enter the employee's monthly base salary: "; cin >> base; int years; cout << "Please enter employee's years with the company: "; cin >> years; double sales; cout << "Please enter the monthly sales of the employee: "; cin >> sales; if (years <= 5) double bonus = 10.0 * years; Step 4.2: Otherwise Step 4.2.1 Compute the time bonus as 20 times the years with the company Step 5: Calculate the commission bonus of the employee Step 6: Sum the base salary, time bonus, and commission bonus of the employee Step 7: Output the computed total

59 Design (salary program) double base; cout << "Please enter the employee's monthly base salary: "; cin >> base; int years; cout << "Please enter employee's years with the company: "; cin >> years; double sales; cout << "Please enter the monthly sales of the employee: "; cin >> sales; if (years <= 5) double bonus = 10.0 * years; else Step 4.2.1 Compute the time bonus as 20 times the years with the company Step 5: Calculate the commission bonus of the employee Step 6: Sum the base salary, time bonus, and commission bonus of the employee Step 7: Output the computed total

60 Design (salary program) double base; cout << "Please enter the employee's monthly base salary: "; cin >> base; int years; cout << "Please enter employee's years with the company: "; cin >> years; double sales; cout << "Please enter the monthly sales of the employee: "; cin >> sales; if (years <= 5) double bonus = 10.0 * years; else double bonus = 20.0 * years; Step 5: Calculate the commission bonus of the employee Step 6: Sum the base salary, time bonus, and commission bonus of the employee Step 7: Output the computed total Bonus will not be usable outside of the if statement.

61 Design (salary program) double base; cout << "Please enter the employee's monthly base salary: "; cin >> base; int years; cout << "Please enter employee's years with the company: "; cin >> years; double sales; cout << "Please enter the monthly sales of the employee: "; cin >> sales; double bonus; if (years <= 5) bonus = 10.0 * years; else bonus = 20.0 * years; Step 5: Calculate the commission bonus of the employee Step 6: Sum the base salary, time bonus, and commission bonus of the employee Step 7: Output the computed total

62 Design (salary program) double base; cout << "Please enter the employee's monthly base salary: "; cin >> base; int years; cout << "Please enter employee's years with the company: "; cin >> years; double sales; cout << "Please enter the monthly sales of the employee: "; cin >> sales; double bonus; if (years <= 5) bonus = 10.0 * years; else bonus = 20.0 * years; Step 5: Calculate the commission bonus of the employee Step 6: Sum the base salary, time bonus, and commission bonus of the employee Step 7: Output the computed total If the sales made by the person are more than $5000 but less than $10000, the salesperson receives a 3% commission on sales. If the total sales by the person is at least $10000 the salesperson receives a 6% sales commission.

63 Design (salary program) double base; cout << "Please enter the employee's monthly base salary: "; cin >> base; int years; cout << "Please enter employee's years with the company: "; cin >> years; double sales; cout << "Please enter the monthly sales of the employee: "; cin >> sales; double bonus; if (years <= 5) bonus = 10.0 * years; else bonus = 20.0 * years; Step 5.1: If sales are greater than or equal to 10000 Step 5.1.1 commission is 6% of sales Step 5.2 otherwise if sales are over 5000 and less than 10000 Step 5.2.1 commission is 3% of sales Step 5.3 otherwise Step 5.3.1 commission is 0 Step 6: Sum the base salary, time bonus, and commission bonus of the employee Step 7: Output the computed total

64 Design (salary program) double base; cout << "Please enter the employee's monthly base salary: "; cin >> base; int years; cout << "Please enter employee's years with the company: "; cin >> years; double sales; cout << "Please enter the monthly sales of the employee: "; cin >> sales; double bonus; if (years <= 5) bonus = 10.0 * years; else bonus = 20.0 * years; double commission; if (sales >= 10000.0) commission = 0.06 * sales; Step 5.2 otherwise if sales are over 5000 and less than 10000 Step 5.2.1 commission is 3% of sales Step 5.3 otherwise Step 5.3.1 commission is 0 Step 6: Sum the base salary, time bonus, and commission bonus of the employee Step 7: Output the computed total

65 Design (salary program) double base; cout << "Please enter the employee's monthly base salary: "; cin >> base; int years; cout << "Please enter employee's years with the company: "; cin >> years; double sales; cout << "Please enter the monthly sales of the employee: "; cin >> sales; double bonus; if (years <= 5) bonus = 10.0 * years; else bonus = 20.0 * years; double commission; if (sales >= 10000.0) commission = 0.06 * sales; else if ( (sales 5000.0)) commission = 0.03 * sales; else commission = 0; Step 6: Sum the base salary, time bonus, and commission bonus of the employee Step 7: Output the computed total

66 Design (salary program) double base; cout << "Please enter the employee's monthly base salary: "; cin >> base; int years; cout << "Please enter employee's years with the company: "; cin >> years; double sales; cout << "Please enter the monthly sales of the employee: "; cin >> sales; double bonus; if (years <= 5) bonus = 10.0 * years; else bonus = 20.0 * years; double commission; if (sales >= 10000.0) commission = 0.06 * sales; else if (sales > 5000.0) commission = 0.03 * sales; else commission = 0; Step 6: Sum the base salary, time bonus, and commission bonus of the employee Step 7: Output the computed total

67 Design (salary program) double base; cout << "Please enter the employee's monthly base salary: "; cin >> base; int years; cout << "Please enter employee's years with the company: "; cin >> years; double sales; cout << "Please enter the monthly sales of the employee: "; cin >> sales; double bonus; if (years <= 5) bonus = 10.0 * years; else bonus = 20.0 * years; double commission; if (sales >= 10000.0) commission = 0.06 * sales; else if (sales > 5000.0) commission = 0.03 * sales; else commission = 0; Step 6: Sum the base salary, time bonus, and commission bonus of the employee Step 7: Output the computed total

68 Design (salary program) double base; cout << "Please enter the employee's monthly base salary: "; cin >> base; int years; cout << "Please enter employee's years with the company: "; cin >> years; double sales; cout << "Please enter the monthly sales of the employee: "; cin >> sales; double bonus; if (years <= 5) bonus = 10.0 * years; else bonus = 20.0 * years; double commission; if (sales >= 10000.0) commission = 0.06 * sales; else if (sales > 5000.0) commission = 0.03 * sales; else commission = 0; double salary = base + bonus + commission; Step 7: Output the computed total

69 Design (salary program) double base; cout << "Please enter the employee's monthly base salary: "; cin >> base; int years; cout << "Please enter employee's years with the company: "; cin >> years; double sales; cout << "Please enter the monthly sales of the employee: "; cin >> sales; double bonus; if (years <= 5) bonus = 10.0 * years; else bonus = 20.0 * years; double commission; if (sales >= 10000.0) commission = 0.06 * sales; else if (sales > 5000.0) commission = 0.03 * sales; else commission = 0; double salary = base + bonus + commission; Step 7: Output the computed total

70 Design (salary program) double base; cout << "Please enter the employee's monthly base salary: "; cin >> base; int years; cout << "Please enter employee's years with the company: "; cin >> years; double sales; cout << "Please enter the monthly sales of the employee: "; cin >> sales; double bonus; if (years <= 5) bonus = 10.0 * years; else bonus = 20.0 * years; double commission; if (sales >= 10000.0) commission = 0.06 * sales; else if (sales > 5000.0) commission = 0.03 * sales; else commission = 0; double salary = base + bonus + commission; cout << setprecision(2) << fixed << showpoint; cout << "Your total salary for the month is $" << salary << endl;

71 #include using namespace std; int main() { double base; cout << "Please enter the employee's monthly base salary: "; cin >> base; int years; cout << "Please enter employee's years with the company: "; cin >> years; double sales; cout << "Please enter the monthly sales of the employee: "; cin >> sales; double bonus; if (years <= 5) bonus = 10.0 * years; else bonus = 20.0 * years; double commission; if (sales >= 10000.0) commission = 0.06 * sales; else if (sales > 5000.0) commission = 0.03 * sales; else commission = 0; double salary = base + bonus + commission; cout << setprecision(2) << fixed << showpoint; cout << "Your total salary for the month is $" << salary << endl; return 0; }

72

73 As you gain experience, your translation will become more efficient you will be able to translate one design statement into multiple lines of code certain statements can be combined int length; cout << "Please enter a length: "; cin >> length; read in a length from the user Design Code double salary = base + bonus; cout << salary << endl; cout << base + bonus << endl;

74 Design Step 1: Read the starting balance of the investment Step 2: Read the interest rate of the investment Step 3: Read the withdraw amount of the investment Step 4: Output balance for the next twenty years

75 Design (investment program) Step 1: Read the starting balance of the investment. Step 2: Read the interest rate of the investment Step 3: Read the withdraw amount of the investment Step 4: Output balance for the next twenty years

76 Design (investment program) double balance; cout << "Please enter the starting balance of investment: "; cin >> balance; Step 2: Read the interest rate of the investment Step 3: Read the withdraw amount of the investment Step 4: Output balance for the next twenty years

77 Design (investment program) double balance; cout << "Please enter the starting balance of investment: "; cin >> balance; Step 2: Read the interest rate of the investment Step 3: Read the withdraw amount of the investment Step 4: Output balance for the next twenty years

78 Design (investment program) double balance; cout << "Please enter the starting balance of investment: "; cin >> balance; double interest; cout << "Please enter the interest rate of investment: "; cin >> interest; Step 3: Read the withdraw amount of the investment Step 4: Output balance for the next twenty years

79 Design (investment program) double balance; cout << "Please enter the starting balance of investment: "; cin >> balance; double interest; cout << "Please enter the interest rate of investment: "; cin >> interest; Step 3: Read the withdraw amount of the investment Step 4: Output balance for the next twenty years

80 Design (investment program) double balance; cout << "Please enter the starting balance of investment: "; cin >> balance; double interest; cout << "Please enter the interest rate of investment: "; cin >> interest; double withdrawal; cout << "Please enter the withdrawal amount: "; cin >> withdrawal; Step 4: Output balance for the next twenty years

81 Design (investment program) double balance; cout << "Please enter the starting balance of investment: "; cin >> balance; double interest; cout << "Please enter the interest rate of investment: "; cin >> interest; double withdrawal; cout << "Please enter the withdrawal amount: "; cin >> withdrawal; Step 4: Output balance for the next twenty years

82 Design (investment program) double balance; cout << "Please enter the starting balance of investment: "; cin >> balance; double interest; cout << "Please enter the interest rate of investment: "; cin >> interest; double withdrawal; cout << "Please enter the withdrawal amount: "; cin >> withdrawal; Step 4: Repeat twenty times Step 4.1 Add the interest to the investment balance Step 4.2 If this is a withdrawal year, remove withdrawal from balance Step 4.3 Output the balance of the account Indent to show that all these steps are part of a statement block.

83 Design (investment program) double balance; cout << "Please enter the starting balance of investment: "; cin >> balance; double interest; cout << "Please enter the interest rate of investment: "; cin >> interest; double withdrawal; cout << "Please enter the withdrawal amount: "; cin >> withdrawal; for (int year = 1; year <= 20; year++) { Step 4.1 Add the interest to the investment balance Step 4.2 If this is a withdrawal year, remove withdrawal from balance Step 4.3 Output the balance of the account }

84 Design (investment program) double balance; cout << "Please enter the starting balance of investment: "; cin >> balance; double interest; cout << "Please enter the interest rate of investment: "; cin >> interest; double withdrawal; cout << "Please enter the withdrawal amount: "; cin >> withdrawal; for (int year = 1; year <= 20; year++) { Step 4.1 Add the interest to the investment balance Step 4.2 If this is a withdrawal year, remove withdrawal from balance Step 4.3 Output the balance of the account }

85 Design (investment program) double balance; cout << "Please enter the starting balance of investment: "; cin >> balance; double interest; cout << "Please enter the interest rate of investment: "; cin >> interest; double withdrawal; cout << "Please enter the withdrawal amount: "; cin >> withdrawal; for (int year = 1; year <= 20; year++) { balance = balance + (balance * interest); Step 4.2 If this is a withdrawal year, remove withdrawal from balance Step 4.3 Output the balance of the account }

86 Design (investment program) double balance; cout << "Please enter the starting balance of investment: "; cin >> balance; double interest; cout << "Please enter the interest rate of investment: "; cin >> interest; double withdrawal; cout << "Please enter the withdrawal amount: "; cin >> withdrawal; for (int year = 1; year <= 20; year++) { balance += (balance * interest); Step 4.2 If this is a withdrawal year, remove withdrawal from balance Step 4.3 Output the balance of the account }

87 Design (investment program) double balance; cout << "Please enter the starting balance of investment: "; cin >> balance; double interest; cout << "Please enter the interest rate of investment: "; cin >> interest; double withdrawal; cout << "Please enter the withdrawal amount: "; cin >> withdrawal; for (int year = 1; year <= 20; year++) { balance *= (1 + interest); Step 4.2 If this is a withdrawal year, remove withdrawal from balance Step 4.3 Output the balance of the account }

88 Design (investment program) double balance; cout << "Please enter the starting balance of investment: "; cin >> balance; double interest; cout << "Please enter the interest rate of investment: "; cin >> interest; double withdrawal; cout << "Please enter the withdrawal amount: "; cin >> withdrawal; for (int year = 1; year <= 20; year++) { balance *= (1 + interest); Step 4.2 If this is a withdrawal year, remove withdrawal from balance Step 4.3 Output the balance of the account }

89 Design (investment program) double balance; cout << "Please enter the starting balance of investment: "; cin >> balance; double interest; cout << "Please enter the interest rate of investment: "; cin >> interest; double withdrawal; cout << "Please enter the withdrawal amount: "; cin >> withdrawal; for (int year = 1; year <= 20; year++) { balance *= (1 + interest); Step 4.2 If this is a withdrawal year Step 4.2.1 remove withdrawal from balance Step 4.3 Output the balance of the account } "Suppose further that every 4 years, you withdraw Z dollars from the investment."

90 Design (investment program) double balance; cout << "Please enter the starting balance of investment: "; cin >> balance; double interest; cout << "Please enter the interest rate of investment: "; cin >> interest; double withdrawal; cout << "Please enter the withdrawal amount: "; cin >> withdrawal; for (int year = 1; year <= 20; year++) { balance *= (1 + interest); if (this is a withdrawal year) Step 4.2.1 remove withdrawal from balance Step 4.3 Output the balance of the account } This needs to be true every fourth year, and false otherwise.

91 Design (investment program) double balance; cout << "Please enter the starting balance of investment: "; cin >> balance; double interest; cout << "Please enter the interest rate of investment: "; cin >> interest; double withdrawal; cout << "Please enter the withdrawal amount: "; cin >> withdrawal; int count = 0; for (int year = 1; year <= 20; year++) { balance *= (1 + interest); count++; if (count == 4) { Step 4.2.1 remove withdrawal from balance count == 0; } Step 4.3 Output the balance of the account }

92 Design (investment program) double balance; cout << "Please enter the starting balance of investment: "; cin >> balance; double interest; cout << "Please enter the interest rate of investment: "; cin >> interest; double withdrawal; cout << "Please enter the withdrawal amount: "; cin >> withdrawal; for (int year = 1; year <= 20; year++) { balance *= (1 + interest); if (year % 4 == 0) Step 4.2.1 remove withdrawal from balance Step 4.3 Output the balance of the account }

93 Design (investment program) double balance; cout << "Please enter the starting balance of investment: "; cin >> balance; double interest; cout << "Please enter the interest rate of investment: "; cin >> interest; double withdrawal; cout << "Please enter the withdrawal amount: "; cin >> withdrawal; for (int year = 1; year <= 20; year++) { balance *= (1 + interest); if (year % 4 == 0) Step 4.2.1 remove withdrawal from balance Step 4.3 Output the balance of the account } "However, you may not withdraw more than the investment is currently worth."

94 Design (investment program) double balance; cout << "Please enter the starting balance of investment: "; cin >> balance; double interest; cout << "Please enter the interest rate of investment: "; cin >> interest; double withdrawal; cout << "Please enter the withdrawal amount: "; cin >> withdrawal; for (int year = 1; year <= 20; year++) { balance *= (1 + interest); if (year % 4 == 0) Step 4.2.1 if the account has enough money to withdraw Step 4.2.1.1 make the full withdrawal amount Step 4.2.2 otherwise Step 4.2.2.1 withdraw the entire balance Step 4.3 Output the balance of the account }

95 Design (investment program) double balance; cout << "Please enter the starting balance of investment: "; cin >> balance; double interest; cout << "Please enter the interest rate of investment: "; cin >> interest; double withdrawal; cout << "Please enter the withdrawal amount: "; cin >> withdrawal; for (int year = 1; year <= 20; year++) { balance *= (1 + interest); if (year % 4 == 0) if (balance >= withdrawal) Step 4.2.1.1 make the full withdrawal amount Step 4.2.2 otherwise Step 4.2.2.1 withdraw the entire balance Step 4.3 Output the balance of the account }

96 Design (investment program) double balance; cout << "Please enter the starting balance of investment: "; cin >> balance; double interest; cout << "Please enter the interest rate of investment: "; cin >> interest; double withdrawal; cout << "Please enter the withdrawal amount: "; cin >> withdrawal; for (int year = 1; year <= 20; year++) { balance *= (1 + interest); if (year % 4 == 0) if (balance >= withdrawal) Step 4.2.1.1 make the full withdrawal amount Step 4.2.2 otherwise Step 4.2.2.1 withdraw the entire balance Step 4.3 Output the balance of the account }

97 Design (investment program) double balance; cout << "Please enter the starting balance of investment: "; cin >> balance; double interest; cout << "Please enter the interest rate of investment: "; cin >> interest; double withdrawal; cout << "Please enter the withdrawal amount: "; cin >> withdrawal; for (int year = 1; year <= 20; year++) { balance *= (1 + interest); if (year % 4 == 0) if (balance >= withdrawal) balance -= withdrawal; Step 4.2.2 otherwise Step 4.2.2.1 withdraw the entire balance Step 4.3 Output the balance of the account }

98 Design (investment program) double balance; cout << "Please enter the starting balance of investment: "; cin >> balance; double interest; cout << "Please enter the interest rate of investment: "; cin >> interest; double withdrawal; cout << "Please enter the withdrawal amount: "; cin >> withdrawal; for (int year = 1; year <= 20; year++) { balance *= (1 + interest); if (year % 4 == 0) if (balance >= withdrawal) balance -= withdrawal; Step 4.2.2 otherwise Step 4.2.2.1 withdraw the entire balance Step 4.3 Output the balance of the account }

99 Design (investment program) double balance; cout << "Please enter the starting balance of investment: "; cin >> balance; double interest; cout << "Please enter the interest rate of investment: "; cin >> interest; double withdrawal; cout << "Please enter the withdrawal amount: "; cin >> withdrawal; for (int year = 1; year <= 20; year++) { balance *= (1 + interest); if (year % 4 == 0) if (balance >= withdrawal) balance -= withdrawal; else Step 4.2.2.1 withdraw the entire balance Step 4.3 Output the balance of the account }

100 Design (investment program) double balance; cout << "Please enter the starting balance of investment: "; cin >> balance; double interest; cout << "Please enter the interest rate of investment: "; cin >> interest; double withdrawal; cout << "Please enter the withdrawal amount: "; cin >> withdrawal; for (int year = 1; year <= 20; year++) { balance *= (1 + interest); if (year % 4 == 0) if (balance >= withdrawal) balance -= withdrawal; else Step 4.2.2.1 withdraw the entire balance Step 4.3 Output the balance of the account }

101 Design (investment program) double balance; cout << "Please enter the starting balance of investment: "; cin >> balance; double interest; cout << "Please enter the interest rate of investment: "; cin >> interest; double withdrawal; cout << "Please enter the withdrawal amount: "; cin >> withdrawal; for (int year = 1; year <= 20; year++) { balance *= (1 + interest); if (year % 4 == 0) if (balance >= withdrawal) balance -= withdrawal; else balance -= balance; Step 4.3 Output the balance of the account }

102 Design (investment program) double balance; cout << "Please enter the starting balance of investment: "; cin >> balance; double interest; cout << "Please enter the interest rate of investment: "; cin >> interest; double withdrawal; cout << "Please enter the withdrawal amount: "; cin >> withdrawal; for (int year = 1; year <= 20; year++) { balance *= (1 + interest); if (year % 4 == 0) if (balance >= withdrawal) balance -= withdrawal; else balance = 0; Step 4.3 Output the balance of the account }

103 Design (investment program) double balance; cout << "Please enter the starting balance of investment: "; cin >> balance; double interest; cout << "Please enter the interest rate of investment: "; cin >> interest; double withdrawal; cout << "Please enter the withdrawal amount: "; cin >> withdrawal; for (int year = 1; year <= 20; year++) { balance *= (1 + interest); if (year % 4 == 0) if (balance >= withdrawal) balance -= withdrawal; else balance = 0; Step 4.3 Output the balance of the account }

104 Design (investment program) double balance; cout << "Please enter the starting balance of investment: "; cin >> balance; double interest; cout << "Please enter the interest rate of investment: "; cin >> interest; double withdrawal; cout << "Please enter the withdrawal amount: "; cin >> withdrawal; for (int year = 1; year <= 20; year++) { balance *= (1 + interest); if (year % 4 == 0) if (balance >= withdrawal) balance -= withdrawal; else balance = 0; cout << fixed << showpoint << setprecision(2); cout << "Balance after year " << year << " = $" << balance << endl; }

105 Design (investment program) double balance; cout << "Please enter the starting balance of investment: "; cin >> balance; double interest; cout << "Please enter the interest rate of investment: "; cin >> interest; double withdrawal; cout << "Please enter the withdrawal amount: "; cin >> withdrawal; cout << fixed << showpoint << setprecision(2); for (int year = 1; year <= 20; year++) { balance *= (1 + interest); if (year % 4 == 0) if (balance >= withdrawal) balance -= withdrawal; else balance = 0; cout << "Balance after year " << year << " = $" << balance << endl; }

106 #include using namespace std; int main() { double balance; cout << "Please enter the starting balance of investment: "; cin >> balance; double interest; cout << "Please enter the interest rate of investment: "; cin >> interest; double withdrawal; cout << "Please enter the withdrawal amount: "; cin >> withdrawal; cout << fixed << showpoint << setprecision(2); for (int year = 1; year <= 20; year++) { balance *= (1 + interest); if (year % 4 == 0) if (balance >= withdrawal) balance -= withdrawal; else balance = 0; cout << "Balance after year " << year << " = $" << balance << endl; } return 0; }

107

108 From Design to Code Hints: certain keywords hint at a selection structure "if" if this is a withdrawal year "whether" determine whether employee has been with store for more than 10 years

109 From Design to Code Hints: certain keywords hint at a loop while, for while an amount is less than 2000 repeat repeat for twenty years each output each value between 0 and 5

110 Incremental Coding programmers often try to code the entire solution to a problem immediately when the code is compiled, there are many compiler errors remember: compiler errors can compound (produce other compiler errors) the code is difficult to debug difficult to know where runtime errors are Solution: incremental coding

111 Incremental Coding Approach: 1. Translate a small part of your design to code 2. compile the program fix any compiler errors 3. run the program fix any runtime errors use cout statements to identify errors 4. repeat steps 1-3 until your program is written

112 Design (investment program) Step 1: Read the starting balance of the investment. Step 2: Read the interest rate of the investment Step 3: Read the withdraw amount of the investment Step 4: Output balance for the next twenty years

113 Design (investment program) double balance; cout << "Please enter the starting balance of investment: "; cin >> balance; Step 2: Read the interest rate of the investment Step 3: Read the withdraw amount of the investment Step 4: Output balance for the next twenty years

114 #include using namespace std; int main() { double balance; cout << "Please enter the starting balance of investment: "; cin >> balance; double interest; cout << "Please enter the interest rate of investment: "; cin >> interest; double withdrawal; cout << "Please enter the withdrawal amount: "; cin >> withdrawal; cout << fixed << showpoint << setprecision(2); for (int year = 1; year <= 20; year++) { balance *= (1 + interest); if (year % 4 == 0) if (balance >= withdrawal) balance -= withdrawal; else balance = 0; cout << "Balance after year " << year << " = $" << balance << endl; } return 0; }

115 The previous compiles with no errors How do we check for runtime errors Many programming IDEs have a debugger run in debug mode as the program executes, debugger shows instructions being executed step by step Without debugger: Use a dummy cout statement The cout statement will echo the value of the programmer's input Once you are sure the program is reading the variable correctly, you can delete the cout statement

116 #include using namespace std; int main() { double balance; cout << "Please enter the starting balance of investment: "; cin >> balance; cout << balance << endl; double interest; cout << "Please enter the interest rate of investment: "; cin >> interest; double withdrawal; cout << "Please enter the withdrawal amount: "; cin >> withdrawal; cout << fixed << showpoint << setprecision(2); for (int year = 1; year <= 20; year++) { balance *= (1 + interest); if (year % 4 == 0) if (balance >= withdrawal) balance -= withdrawal; else balance = 0; cout << "Balance after year " << year << " = $" << balance << endl; } return 0; }

117

118 Is this really necessary? suppose that the programmer had accidentally used an int instead of a double

119 #include using namespace std; int main() { int balance; cout << "Please enter the starting balance of investment: "; cin >> balance; cout << balance << endl; double interest; cout << "Please enter the interest rate of investment: "; cin >> interest; double withdrawal; cout << "Please enter the withdrawal amount: "; cin >> withdrawal; cout << fixed << showpoint << setprecision(2); for (int year = 1; year <= 20; year++) { balance *= (1 + interest); if (year % 4 == 0) if (balance >= withdrawal) balance -= withdrawal; else balance = 0; cout << "Balance after year " << year << " = $" << balance << endl; } return 0; }

120

121 #include using namespace std; int main() { double balance; cout << "Please enter the starting balance of investment: "; cin >> balance; cout << balance << endl; double interest; cout << "Please enter the interest rate of investment: "; cin >> interest; double withdrawal; cout << "Please enter the withdrawal amount: "; cin >> withdrawal; cout << fixed << showpoint << setprecision(2); for (int year = 1; year <= 20; year++) { balance *= (1 + interest); if (year % 4 == 0) if (balance >= withdrawal) balance -= withdrawal; else balance = 0; cout << "Balance after year " << year << " = $" << balance << endl; } return 0; } Once you are confident the program is working, you can delete your dummy cout statements.

122 #include using namespace std; int main() { double balance; cout << "Please enter the starting balance of investment: "; cin >> balance; double interest; cout << "Please enter the interest rate of investment: "; cin >> interest; double withdrawal; cout << "Please enter the withdrawal amount: "; cin >> withdrawal; cout << fixed << showpoint << setprecision(2); for (int year = 1; year <= 20; year++) { balance *= (1 + interest); if (year % 4 == 0) if (balance >= withdrawal) balance -= withdrawal; else balance = 0; cout << "Balance after year " << year << " = $" << balance << endl; } return 0; } Once you are confident the program is working, you can delete your dummy cout statements.

123 Design (investment program) double balance; cout << "Please enter the starting balance of investment: "; cin >> balance; Step 2: Read the interest rate of the investment Step 3: Read the withdraw amount of the investment Step 4: Output balance for the next twenty years

124 Design (investment program) double balance; cout << "Please enter the starting balance of investment: "; cin >> balance; double interest; cout << "Please enter the interest rate of investment: "; cin >> interest; Step 3: Read the withdraw amount of the investment Step 4: Output balance for the next twenty years

125 Design (investment program) double balance; cout << "Please enter the starting balance of investment: "; cin >> balance; double interest; cout << "Please enter the interest rate of investment: "; cin >> interest; Step 3: Read the withdraw amount of the investment Step 4: Output balance for the next twenty years

126 Design (investment program) double balance; cout << "Please enter the starting balance of investment: "; cin >> balance; double interest; cout << "Please enter the interest rate of investment: "; cin >> interest; double withdrawal; cout << "Please enter the withdrawal amount: "; cin >> withdrawal; Step 4: Output balance for the next twenty years

127 #include using namespace std; int main() { double balance; cout << "Please enter the starting balance of investment: "; cin >> balance; double interest; cout << "Please enter the interest rate of investment: "; cin >> interest; double withdrawal; cout << "Please enter the withdrawal amount: "; cin >> withdrawal; cout << "balance = " << balance << endl; cout << fixed << showpoint << setprecision(2); for (int year = 1; year <= 20; year++) { balance *= (1 + interest); if (year % 4 == 0) if (balance >= withdrawal) balance -= withdrawal; else balance = 0; cout << "Balance after year " << year << " = $" << balance << endl; } return 0; }

128 #include using namespace std; int main() { double balance; cout << "Please enter the starting balance of investment: "; cin >> balance; double interest; cout << "Please enter the interest rate of investment: "; cin >> interest; double withdrawal; cout << "Please enter the withdrawal amount: "; cin >> withdrawal; cout << "balance = " << balance << endl; cout << "interest = " << interest << endl; cout << "withdrawal = " << withdrawal << endl; cout << fixed << showpoint << setprecision(2); for (int year = 1; year <= 20; year++) { balance *= (1 + interest); if (year % 4 == 0) if (balance >= withdrawal) balance -= withdrawal; else balance = 0; cout << "Balance after year " << year << " = $" << balance << endl; } return 0; }

129

130 Design (investment program) double balance; cout << "Please enter the starting balance of investment: "; cin >> balance; double interest; cout << "Please enter the interest rate of investment: "; cin >> interest; double withdrawal; cout << "Please enter the withdrawal amount: "; cin >> withdrawal; Step 4: Output balance for the next twenty years

131 Design (investment program) double balance; cout << "Please enter the starting balance of investment: "; cin >> balance; double interest; cout << "Please enter the interest rate of investment: "; cin >> interest; double withdrawal; cout << "Please enter the withdrawal amount: "; cin >> withdrawal; Step 4: Repeat twenty times Step 4.1 Add the interest to the investment balance Step 4.2 If this is a withdrawal year, remove withdrawal from balance Step 4.3 Output the balance of the account

132 Design (investment program) double balance; cout << "Please enter the starting balance of investment: "; cin >> balance; double interest; cout << "Please enter the interest rate of investment: "; cin >> interest; double withdrawal; cout << "Please enter the withdrawal amount: "; cin >> withdrawal; for (int year = 1; year <= 20; year++) { Step 4.1 Add the interest to the investment balance Step 4.2 If this is a withdrawal year, remove withdrawal from balance Step 4.3 Output the balance of the account }

133 #include using namespace std; int main() { double balance; cout << "Please enter the starting balance of investment: "; cin >> balance; double interest; cout << "Please enter the interest rate of investment: "; cin >> interest; double withdrawal; cout << "Please enter the withdrawal amount: "; cin >> withdrawal; cout << fixed << showpoint << setprecision(2); for (int year = 1; year <= 20; year++) { balance *= (1 + interest); if (year % 4 == 0) if (balance >= withdrawal) balance -= withdrawal; else balance = 0; cout << "Balance after year " << year << " = $" << balance << endl; } return 0; }

134 #include using namespace std; int main() { double balance; cout << "Please enter the starting balance of investment: "; cin >> balance; double interest; cout << "Please enter the interest rate of investment: "; cin >> interest; double withdrawal; cout << "Please enter the withdrawal amount: "; cin >> withdrawal; cout << fixed << showpoint << setprecision(2); for (int year = 1; year <= 20; year++) { cout << "year = " << year << endl; alance *= (1 + interest); if (year % 4 == 0) if (balance >= withdrawal) balance -= withdrawal; else balance = 0; cout << "Balance after year " << year << " = $" << balance << endl; } return 0; }

135 Now we know the loop statement executes 20 times.

136 And so on dummy cout statements can be used in other statements as well conditionals tells you whether the statement of an if is executing when you expect it to functions tells you whether a function is being called correctly

137 Summary Programming and Problem Solving Analysis and Program Design Structured Programming Divide and Conquer Incremental Programming


Download ppt "Computer Science 1620 Programming & Problem Solving."

Similar presentations


Ads by Google