CMSC 104, Version 8/061L16IncrementalProg.ppt Incremental Programming Topics Review of Incremental Programming Example of Incremental Programming Reading.

Slides:



Advertisements
Similar presentations
Write a program step by step. Step 1: Problem definition. Given the coordinate of two points in 2-D space, compute and print their straight distance.
Advertisements

CMSC 104, Version 9/011 Arithmetic Operators Topics Arithmetic Operators Operator Precedence Evaluating Arithmetic Expressions In-class Project Incremental.
PSEUDOCODE & FLOW CHART
17 March, 2000 CS1001 Lecture 2 Programming and problem solving Software engineering practices.
Software Development Method. Assignments Due – Homework 0, Warmup Reading – Chapter 2 –
1 Modularity In “C”. 2 General Syntax data_type function_Name (parameter list) { … return expression; // return output } Body of the function is a compound.
Computer Science 1620 Programming & Problem Solving.
Basic Input/Output and Variables Ethan Cerami New York
CMSC 104, Version 8/061L22Arrays1.ppt Arrays, Part 1 of 2 Topics Definition of a Data Structure Definition of an Array Array Declaration, Initialization,
CMSC 104, Version 8/061L18Functions1.ppt Functions, Part 1 of 4 Topics Using Predefined Functions Programmer-Defined Functions Using Input Parameters Function.
CMSC 104, Version 9/01 1 The Box Problem: Write an interactive program to compute and display the volume and surface area of a box. The program must also.
DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING.
6 Steps of the Programming Process
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
CMSC 104, Version 9/011 Incremental Programming Topics Review of Incremental Programming Example of Incremental Programming Reading None.
Which Language is Better?
Creating your first C++ program
Arithmetic Operators Topics Arithmetic Operators Operator Precedence
CSci 111 – computer Science I Fall 2014 Cynthia Zickos WRITING A SIMPLE PROGRAM IN JAVA.
Lecture 4: Calculating by Iterating. The while Repetition Statement Repetition structure Programmer specifies an action to be repeated while some condition.
Algorithms  Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
1 Ch. 1: Software Development (Read) 5 Phases of Software Life Cycle: Problem Analysis and Specification Design Implementation (Coding) Testing, Execution.
CMSC 1041 Examples Using Top-Down Design and Functions to Simplify Code and Create Modules.
CMSC 104, Version 8/061L10ArithmeticOps.ppt Arithmetic Operators Topics Arithmetic Operators Operator Precedence Evaluating Arithmetic Expressions In-class.
Principles of Programming - NI Simple Recursion Recursion is where a function calls itself. Concept of recursive function: A recursive function is.
The ‘while’ loop ‘round and ‘round we go.
Computer Programming A simple example /* HelloWorld: A simple C program */ #include int main (void) { printf (“Hello world!\n”); return.
1 UMBC CMSC 104, Section Fall 2002 Functions, Part 1 of 3 Topics Top-down Design The Function Concept Using Predefined Functions Programmer-Defined.
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
L071 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program Reading Sections
Repetition statements
Chapter 4 C Program Control Part I
2008/09/22: Lecture 6 CMSC 104, Section 0101 John Y. Park
The Software Development Cycle
Algorithms Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
Introduction to C Topics Compilation Using the gcc Compiler
Algorithm and Ambiguity
Arithmetic Operators Topics Arithmetic Operators Operator Precedence
2008/09/24: Lecture 6b CMSC 104, Section 0101 John Y. Park
2011/11/20: Lecture 15 CMSC 104, Section 4 Richard Chang
IPC144 Introduction to Programming Using C Week 2 – Lesson 1
The while Looping Structure
Variables In programming, we often need to have places to store data. These receptacles are called variables. They are called that because they can change.
Arithmetic Operators in C
Arithmetic Operators Topics Arithmetic Operators Operator Precedence
2008/11/12: Lab 5/Lecture 17 CMSC 104, Section 0101 John Y. Park
Incremental Programming
Arithmetic Operators in C
1) C program development 2) Selection structure
The while Looping Structure
Creating your first C program
The ‘while’ loop ‘round and ‘round we go.
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING
Example Using Functions
Algorithm and Ambiguity
Solutions to In-Class Problems
Examples Example Problems, their Algorithms, and their C Source Code.
Functions, Part 4 of 4 Topics: Coding Practice Reading: None
More Loops Topics Relational Operators Logical Operators for Loops.
Variables in C Topics Naming Variables Declaring Variables
Functions, Part 3 of 3 Topics: Coding Practice Reading: None
The while Looping Structure
Incremental Programming
The while Looping Structure
Functions, Part 2 of 42 Topics Functions That Return a Value
and Functions to Simplify Code
The Software Development Cycle
Presentation transcript:

CMSC 104, Version 8/061L16IncrementalProg.ppt Incremental Programming Topics Review of Incremental Programming Example of Incremental Programming Reading None.

CMSC 104, Version 8/062L16IncrementalProg.ppt Incremental Programming Review It is best not to take the “big bang” approach to coding. Write your code in incomplete but working pieces. For example, for your projects, o Don’t write the whole program at once. o Just write enough to display the user prompt on the screen. o Get that part working first (compile and run). o Next, write the part that gets the value from the user, and then just print it out.

CMSC 104, Version 8/063L16IncrementalProg.ppt Increment Programming Review (con’t) o Get that working (compile and run). o Next, change the code so that you use the value in a calculation and print out the answer. o Get that working (compile and run). o Continue this process until you have the final version. o Get the final version working. Bottom line: Always have a working version of your program!

CMSC 104, Version 8/064L16IncrementalProg.ppt Example of Incremental Programming Problem: Write an interactive program that allows the user to calculate the interest accrued on a savings account. The interest is compounded annually. The user must supply the principal amount, the interest rate, and the number of years over which to compute the interest.

CMSC 104, Version 8/065L16IncrementalProg.ppt Rough Algorithm Print explanation of the program Get from user = While ( > 0 ) amount = amount + (amount X ) = - 1 End_while = - Display report

CMSC 104, Version 8/066L16IncrementalProg.ppt Report Design Interest rate : % Period : 20 years Principal at start of period : Interest accrued : Total amount at end of period :

CMSC 104, Version 8/067L16IncrementalProg.ppt Version #1 /* Filename: interest.c * Author:Sue Evans * Date written: 11/14/99 * Description: This program computes the interest accrued in an account * that compounds interest annually. */ #include int main ( void ) { /* Print Instructions */ printf (“This program computes the interest accrued in an account that\n”); printf (“compounds interest annually. You will need to enter the amount\n”); printf (“of the principal, the interest rate and the number of years.\n\n”); return 0; }

CMSC 104, Version 8/068L16IncrementalProg.ppt Output #1 This program computes the interest accrued in an account that compounds interest annually. You will need to enter the amount of the principal, the interest rate and the number of years.

CMSC 104, Version 8/069L16IncrementalProg.ppt Version #2 /* Filename: interest.c * Author: Sue Evans * Date written: 11/14/99 * Description: This program computes the interest accrued in an account * that compounds interest annually. */ #include int main ( void ) { float principal, rate ; int years ; /* Print Instructions */ printf (“This program computes the interest accrued in an account that\n”) ; printf (“compounds interest annually. You will need to enter the amount\n”) ; printf (“of the principal, the interest rate and the number of years.\n\n”) ; /* Get input from user */ printf (“Enter the principal amount : “) ; scanf (“%f”, &principal) ; printf (“Enter the interest rate as a decimal (for 7% enter.07) : “) ; scanf (“%f”, &rate) ; printf (“Enter the number of years : “) ; scanf (“%d”, &years) ; printf (“\nprincipal = %f, rate = %f, years = %d\n”, principal, rate, years ) ; return 0 ; }

CMSC 104, Version 8/0610L16IncrementalProg.ppt Output #2 This program computes the interest accrued in an account that compounds interest annually. You will need to enter the amount of the principal, the interest rate and the number of years. Enter the principal amount : Enter the interest rate as a decimal (for 7% enter.07) :.07 Enter the number of years : 20 principal = , rate = , years = 20

CMSC 104, Version 8/0611L16IncrementalProg.ppt Version #3 /* Filename: interest.c * Author: Sue Evans * Date written: 11/14/99 * Description: This program computes the interest accrued in an account * that compounds interest annually. */ #include int main ( void ) { float principal, rate, amount, interest ; int years, i ; /* Print Instructions */ printf (“This program computes the interest accrued in an account that\n”); printf (“compounds interest annually. You will need to enter the amount\n”); printf (“of the principal, the interest rate and the number of years.\n\n”); /* Get input from user */ printf (“Enter the principal amount : “); scanf (“%f”, &principal); printf (“Enter the interest rate as a decimal (for 7% enter.07) : “) ; scanf (“%f”, &rate); printf (“Enter the number of years : “); scanf (“%d”, &years);

CMSC 104, Version 8/0612L16IncrementalProg.ppt Version #3 (con’t) /* Save the original principal amount by varying another variable, amount */ amount = principal; /* Calculate total amount in the account after the specified number of years */ for ( i = 0 ; i < 1 ; i++ ) { amount += amount * rate ; } /* Calculate accrued interest */ interest = amount - principal ; printf (“\nprincipal = %f, rate = %f, years = %d\n”, principal, rate, years ) ; printf (“amount = %f, interest = %f\n”, amount, interest); return 0 ; }

CMSC 104, Version 8/0613L16IncrementalProg.ppt Output #3 This program computes the interest accrued in an account that compounds interest annually. You will need to enter the amount of the principal, the interest rate and the number of years. Enter the principal amount : Enter the interest rate as a decimal (for 7% enter.07) :.07 Enter the number of years : 20 principal = , rate = , years = 20 amount = , interest =

CMSC 104, Version 8/0614L16IncrementalProg.ppt Version #4 /* Filename: interest.c * Author: Sue Evans * Date written: 11/14/99 * Description: This program computes the interest accrued in an account * that compounds interest annually. */ #include int main ( void ) { float principal, rate, amount, interest ; int years, i ; /* Print Instructions */ printf (“This program computes the interest accrued in an account that\n”); printf (“compounds interest annually. You will need to enter the amount\n”); printf (“of the principal, the interest rate and the number of years.\n\n”); /* Get input from user */ printf (“Enter the principal amount : “); scanf (“%f”, &principal); printf (“Enter the interest rate as a decimal (for 7% enter.07) : “) ; scanf (“%f”, &rate); printf (“Enter the number of years : “); scanf (“%d”, &years);

CMSC 104, Version 8/0615L16IncrementalProg.ppt Version #4 (con’t) /* Save the original principal amount by varying another variable, amount */ amount = principal; /* Calculate total amount in the account after the specified number of years */ for ( i = 0 ; i < 2 ; i++ ) { amount += amount * rate ; } /* Calculate accrued interest */ interest = amount - principal ; printf (“\nprincipal = %f, rate = %f, years = %d\n”, principal, rate, years ) ; printf (“amount = %f, interest = %f\n”, amount, interest); return 0 ; }

CMSC 104, Version 8/0616L16IncrementalProg.ppt Output #4 This program computes the interest accrued in an account that compounds interest annually. You will need to enter the amount of the principal, the interest rate and the number of years. Enter the principal amount : Enter the interest rate as a decimal (for 7% enter.07) :.07 Enter the number of years : 20 principal = , rate = , years = 20 amount = , interest =

CMSC 104, Version 8/0617L16IncrementalProg.ppt Version #5 /* Filename: interest.c * Author: Sue Evans * Date written: 11/14/99 * Description: This program computes the interest accrued in an account * that compounds interest annually. */ #include int main ( void ) { float principal, rate, amount, interest ; int years, i ; /* Print Instructions */ printf (“This program computes the interest accrued in an account that\n”); printf (“compounds interest annually. You will need to enter the amount\n”); printf (“of the principal, the interest rate and the number of years.\n\n”); /* Get input from user */ printf (“Enter the principal amount : “); scanf (“%f”, &principal); printf (“Enter the interest rate as a decimal (for 7% enter.07) : “) ; scanf (“%f”, &rate); printf (“Enter the number of years : “); scanf (“%d”, &years);

CMSC 104, Version 8/0618L16IncrementalProg.ppt Version #5 (con’t) /* Save the original principal amount by varying another variable, amount */ amount = principal; /* Calculate total amount in the account after the specified number of years */ for ( i = 0 ; i < years ; i++ ) { amount += amount * rate ; } /* Calculate accrued interest */ interest = amount - principal ; printf (“\nprincipal = %f, rate = %f, years = %d\n”, principal, rate, years ) ; printf (“amount = %f, interest = %f\n”, amount, interest); return 0 ; }

CMSC 104, Version 8/0619L16IncrementalProg.ppt Output #5 This program computes the interest accrued in an account that compounds interest annually. You will need to enter the amount of the principal, the interest rate and the number of years. Enter the principal amount : Enter the interest rate as a decimal (for 7% enter.07) :.07 Enter the number of years : 20 principal = , rate = , years = 20 amount = , interest =

CMSC 104, Version 8/0620L16IncrementalProg.ppt Final Version /* Filename: interest.c * Author: Sue Evans * Date written: 11/14/99 * Description: This program computes the interest accrued in an account * that compounds interest annually. */ #include int main ( void ) { float principal, rate, amount, interest ; int years, i ; /* Print Instructions */ printf (“This program computes the interest accrued in an account that\n”); printf (“compounds interest annually. You will need to enter the amount\n”); printf (“of the principal, the interest rate and the number of years.\n\n”); /* Get input from user */ printf (“Enter the principal amount : “); scanf (“%f”, &principal); printf (“Enter the interest rate as a decimal (for 7% enter.07) : “) ; scanf (“%f”, &rate); printf (“Enter the number of years : “); scanf (“%d”, &years);

CMSC 104, Version 8/0621L16IncrementalProg.ppt Final Version (con’t) /* Save the original principal amount by varying another variable, amount */ amount = principal; /* Calculate total amount in the account after the specified number of years */ for ( i = 0 ; i < years ; i++ ) { amount += amount * rate ; } /* Calculate accrued interest */ interest = amount - principal ; /* Print report */ printf (“Interest rate : %.4f %\n”, 100 * rate ) ; printf (“ Period : %d years\n\n”, years ) ; printf (“ Principal at start of period : %9.2f\n”, principal ); printf (“ Interest accrued : %9.2f\n”, interest ); printf (“Total amount at end of period : %9.2f\n”, amount); return 0 ; }

CMSC 104, Version 8/0622L16IncrementalProg.ppt Final Output This program computes the interest accrued in an account that compounds interest annually. You will need to enter the amount of the principal, the interest rate and the number of years. Enter the principal amount : Enter the interest rate as a decimal (for 7% enter.07) :.07 Enter the number of years : 20 Interest rate : % Period : 20 years Principal at start of period : Interest accrued : Total amount at end of period :

CMSC 104, Version 8/0623L16IncrementalProg.ppt No “Big Bang,” Please! We now have a working program that we are convinced is logically correct and that solves the problem. Would we have this much confidence in our program if we had used the “big bang” approach? I doubt it!

CMSC 104, Version 8/0624L16IncrementalProg.ppt Software Engineering Software Engineering is the discipline within computer science concerned with techniques needed for the production and maintenance of large software systems. Most programs spend 90 percent of their time doing 10 percent of their instructions. Find this 10 percent and make them as good as possible.

CMSC 104, Version 8/0625L16IncrementalProg.ppt Rules Of Thumb Never code until the specifications are precise and complete! Know your problem. Keep your algorithms as simple as you can! Be sure you understand your problem completely. Program in hast and debug forever! Keep your functions short; rarely should any function be more than a page long.

CMSC 104, Version 8/0626L16IncrementalProg.ppt More Rules Always name your variables and functions with the greatest care and explain them thoroughly. Keep your documentation concise but descriptive. Each task should do only one task, but do it well. Avoid global variables.