Loop Continue ISYS 350.

Slides:



Advertisements
Similar presentations
Two-Dimensional Arrays Chapter What is a two-dimensional array? A two-dimensional array has “rows” and “columns,” and can be thought of as a series.
Advertisements

© Paradigm Publishing, Inc Excel 2013 Level 2 Unit 1Advanced Formatting, Formulas, and Data Management Chapter 2Advanced Functions and Formulas.
情報基礎 A Lecture 10 Takeshi Tokuyama Tohoku University Graduate School of Information Sciences System Information Sciences Design and Analysis of Information.
Arrays. Memory organization Table at right shows 16 bytes, each consisting of 8 bits Each byte has an address, shown in the column to the left
1 ICS103 Programming in C Lecture 16: 2-Dimensional Arrays.
Introduction to Computers and Programming Lecture 10: For Loops Professor: Evan Korth New York University.
Tutorial 12 Working with Arrays, Loops, and Conditional Statements
Writing and Solving Proportions. Proportions Proportion is an equation stating that two ratios are equivalent. Proportional are two quantities that form.
Access Level Three [Functions] & “ And “ & [Expressions]
Server-Side Scripting with JSP (2) ISYS 350. Java Array Examples of declaring an array: – int[] anArray = new int[10]; 10 elements index from 0 to 9 –
Lawrence Snyder University of Washington, Seattle © Lawrence Snyder 2004.
Two –Dimensional Arrays Mrs. C. Furman Java Programming November 19, 2008.
Lecture 16: Working with Complex Data Arrays. Double-Subscripted Arrays Commonly used to represent tables of values consisting of information arranged.
Multi-Dimensional Arrays Arrays that have more than one index: Example of differences between basic data types and arrays using integers: Basic integer:
Computer Programming 12 Mr. Jean April 24, The plan: Video clip of the day Upcoming Quiz Sample arrays Using arrays More about arrays.
ADO.NET Part 2. Slide 2 Overview Slide 3 Introduction to the DataGridView Control It’s a two-dimensional grid containing rows and columns Its use in.
Two –Dimensional Arrays Mrs. C. Furman September 18, 2008.
Scope When we create variables and functions, they are limited in where they are visible and where they can be referenced For the most part, the identifiers.
Server-Side Scripting with PHP ISYS 475. PHP Manual Website
Unit 02: Website Layout Practice Mr C Johnston ICT Teacher - Sidney Stringer School, Coventry
Java Servlet ISYS 350. What is Java Servlet? It is a java class that serves a client request. Servlets are most often used to: Process or store data that.
Array and ArrayList ISYS 350. Array An array allows you to store a group of items of the same type together. Processing a large number of items in an.
Get Longest Run Index (FR) public int getLongestRunIndex(int []values) { int maxRunStart = -1, maxRunLength = 1; int runStart = 0, runLength = 1; for(int.
1 Arrays of Arrays An array can represent a collection of any type of object - including other arrays! The world is filled with examples Monthly magazine:
Loop Continue ISYS 350. Straight Line Depreciation Table.
Arrays. Array: Sequence of values of the same type Construct array: Store in variable of type double[ ] new double[10] double[] data = new double[10];
digit x 1 digit 3 DIGIT BY 2 DIGIT Multiplying Decimals 4 digit by 3 digit
Ranges. Unlike many of our programming concepts, the idea of a Range is particular to Excel The ideas and code discussed in these slides can be found.
Loop Continue ISYS 350. Exiting a Loop Prematurely In some cases it is necessary to end a loop before the test condition would end it Use the break statement:
CS 161 Introduction to Programming and Problem Solving Chapter 17 Nested Loops Herbert G. Mayer, PSU Status 9/8/2014 Initial content copied verbatim from.
Multidimensional Arrays Vectors of Vectors When One Is Not Enough.
© 2006 Pearson Addison-Wesley. All rights reserved Arrays of Greater Dimension One-dimensional arrays are linear containers. Multi-dimensional Arrays.
Parts of the Clock Click on the minute hand. Click on the clock’s face.
Loop Continue ISYS 350. Exiting a Loop Prematurely In some cases it is necessary to end a loop before the test condition would end it Use the break statement:
Loops ISYS 350. Two Types of Loops while loop for loop.
Arrays float Scores[9]; ? index: element // one dimensional array 1.
Loops ISYS 350. Two Types of Loops while loop for loop.
Array, ArrayList and List ISYS 350. Array An array allows you to store a group of items of the same type together. Processing a large number of items.
Arrays float Scores[9]; ? index: element // one dimensional array 2.
Barbara Ericson Georgia Tech Sept 2005
ESC101: Introduction to Computing
Array ISYS 350.
Two-Dimensional Arrays
Two Dimensional Array Mr. Jacobs.
Two-Dimension Arrays Computer Programming 2.
ECE Application Programming
CS 1430: Programming in C++.
Repeating Instructions And Advance collection
Engineering Problem Solving with C++, Etter/Ingber
Multidimensional Arrays Vectors of Vectors
Loops ISYS 350.
Loop Continue ISYS 350.
Loops ISYS 350.
Loop Continue ISYS 350.
Lecture Set 10 Windows Controls and Forms
Multidimensional Arrays
Loops ISYS 350.
Loop Continue.
ECE 103 Engineering Programming Chapter 19 Nested Loops
INC 161 , CPE 100 Computer Programming
Loop Continue ISYS 350.
Loops ISYS 350.
Loop Continue ISYS 350.
Loops ISYS 350.
Array ISYS 350.
EECE.2160 ECE Application Programming
Review of Previous Lesson
Loops ISYS 350.
Loop Continue ISYS 350.
Loop Continue ISYS 350.
Presentation transcript:

Loop Continue ISYS 350

Straight Line Depreciation Table

dataGridView Control Properties ColumnCount: specify the number of columns dataGridView1.ColumnCount = 4; Columns collection each column is identified by an index, first column index is 0 Each column has a HeaderText property: Ex. dataGridView1.Columns[0].HeaderText = "Year"; Rows collection Clear all rows: dataGridView1.Rows.Clear(); each row is identified by an index, first row index is 0 Adding a blank row: dataGridView1.Rows.Add(); Each Row has a Cells collection Each cell is identified by an index Has a value property: dataGridView1.Rows[year - 1].Cells[0].Value = year;

Future Value Table FV = PV * (1 +Rate) Year

Code Example dataGridView1.ColumnCount = 2; dataGridView1.Columns[0].HeaderText = "Year"; dataGridView1.Columns[1].HeaderText = "Future Value"; double pv, rate, lastYear, fv; pv = double.Parse(textBox1.Text); rate = double.Parse(textBox2.Text); lastYear = double.Parse(textBox3.Text); dataGridView1.Rows.Clear(); for (int year = 1; year <= lastYear; year++) { dataGridView1.Rows.Add(); fv = pv * Math.Pow(1 + rate, year); dataGridView1.Rows[year - 1].Cells[0].Value = year; dataGridView1.Rows[year - 1].Cells[1].Value = fv.ToString("c"); }

Depreciation Table Code Example dataGridView1.ColumnCount = 4; dataGridView1.Columns[0].HeaderText = "Year"; dataGridView1.Columns[1].HeaderText = "Value at Begining of Year"; dataGridView1.Columns[2].HeaderText = "Depreciation During Year"; dataGridView1.Columns[3].HeaderText = "Total depreciation to End of Year"; double value, life, depreciation, totalDepreciation=0; value = double.Parse(textBox1.Text); life = double.Parse(textBox2.Text); depreciation = value / life; dataGridView1.Rows.Clear(); for (int year = 1; year <= life; year++) { dataGridView1.Rows.Add(); dataGridView1.Rows[year - 1].Cells[0].Value = year; dataGridView1.Rows[year - 1].Cells[1].Value = value.ToString("c"); dataGridView1.Rows[year-1].Cells[2].Value = depreciation.ToString("c"); totalDepreciation += depreciation; dataGridView1.Rows[year - 1].Cells[3].Value = totalDepreciation.ToString("c"); value -= depreciation; }

Alternating Row Color dataGridView1.ColumnCount = 2; dataGridView1.Columns[0].HeaderText = "Year"; dataGridView1.Columns[1].HeaderText = "Future Value"; double pv, rate, lastYear, fv; pv = double.Parse(textBox1.Text); rate = double.Parse(textBox2.Text); lastYear = double.Parse(textBox3.Text); dataGridView1.Rows.Clear(); for (int year = 1; year <= lastYear; year++) { dataGridView1.Rows.Add(); fv = pv * Math.Pow(1 + rate, year); dataGridView1.Rows[year - 1].Cells[0].Value = year; dataGridView1.Rows[year - 1].Cells[1].Value = fv.ToString("c"); if (year % 2 == 0) dataGridView1.Rows[year - 1].DefaultCellStyle.BackColor = Color.AliceBlue; else dataGridView1.Rows[year - 1].DefaultCellStyle.BackColor = Color.Pink; }

A Loop that is Inside Another Loop is Called a Nested Loop

Nested Loop Example A clock is an example of a nested loop For each hour, Minute hand moves 60 times for each hour for (int hour = 0; hour < 24; hour++) { for (int minute = 0; minute < 60; minute++) MessageBox.Show("Hour: " + hour.ToString() + " Minute: " + minute.ToString()); }

Using dataGridView

double rate, year, presentValue, futureValue; presentValue = double.Parse(textBox1.Text); dataGridView1.ColumnCount = 5; dataGridView1.Columns[0].HeaderText = "Rate/Year"; dataGridView1.Columns[1].HeaderText = "5"; dataGridView1.Columns[2].HeaderText = "10"; dataGridView1.Columns[3].HeaderText = "15"; dataGridView1.Columns[4].HeaderText = "20"; int rowIndex = 0, colIndex; dataGridView1.Rows.Clear(); for (rate = 0.03; rate <= 0.05; rate += 0.005) { dataGridView1.Rows.Add(); colIndex = 0; dataGridView1.Rows[rowIndex].Cells[colIndex].Value = rate.ToString("p2"); for (year = 5; year <= 20; year += 5) futureValue = presentValue * Math.Pow(1 + rate, year); colIndex += 1; dataGridView1.Rows[rowIndex].Cells[colIndex].Value = futureValue.ToString("c"); } rowIndex += 1;

Code Example:loop control variable used as row/column index int rows = 9, cols = 10, Product; dataGridView1.ColumnCount = cols; dataGridView1.Columns[0].HeaderText = ""; dataGridView1.Columns[0].Width = 25; for (int col = 2; col <= cols; col++) { dataGridView1.Columns[col-1].HeaderText = (col-1).ToString(); dataGridView1.Columns[col-1].Width = 25; } for (int rowIndex = 1; rowIndex <= rows; rowIndex++) dataGridView1.Rows.Add(); dataGridView1.Rows[rowIndex - 1].Cells[0].Value = rowIndex.ToString(); for (int colIndex = 2; colIndex <= cols; colIndex++) Product= rowIndex * (colIndex-1); dataGridView1.Rows[rowIndex - 1].Cells[colIndex-1].Value = Product.ToString();