 For Loops › for (variable set; condition; incremental or decrement){ // loop beginning › } // loop end  While loops › while (condition) { // beginning.

Slides:



Advertisements
Similar presentations
Copyright © 2002 Pearson Education, Inc. Slide 1.
Advertisements

Etter/Ingber Arrays and Matrices. Etter/Ingber One-Dimensional Arrays 4 An array is an indexed data structure 4 All variables stored in an array are of.
Introduction to C Systems Programming Concepts. Introduction to C A simple C Program A simple C Program –Variable Declarations –printf ( ) Compiling and.
1 Arrays Chapter 9. 2 Outline  The array structure (Section 9.1)  Array declaration  Array initialization  Array subscripts  Sequential access to.
Dale/Weems/Headington
CSE202: Lecture 2The Ohio State University1 Variables and C++ Data Types.
1 CIS 205 Practice Test George Lamperti A word that has a predefined meaning in a C++ program and cannot be used as a variable name is known as.
Arrays. Arrays  When a value is to be used in a program, a variable is declared to hold that value  What about storing the results of exams for a large.
ECE122 L11: For loops and Arrays March 8, 2007 ECE 122 Engineering Problem Solving with Java Lecture 11 For Loops and Arrays.
Multiple-Subscripted Array
PHYS 2020 Making Choices; Arrays. Arrays  An array is very much like a matrix.  In the C language, an array is a collection of variables, all of the.
Chapter 9: Arrays and Strings
Chapter 9: Arrays and Strings
Libraries Programs that other people write that help you. #include // enables C++ #include // enables human-readable text #include // enables math functions.
Arrays.
Input and Output in Console Mode UNIVERSITY OF THE PUNJAB (GUJRANWALA CAMPUS) ADNAN BABAR MT14028 CR
© Copyright 2013 by Pearson Education, Inc. All Rights Reserved.1 Chapter 4 Mathematical Functions, Characters, and Strings.
Chapter 3: Data Types and Operators JavaScript - Introductory.
Arrays in C++ Numeric Character. Structured Data Type A structured data type is a type that stores a collection of individual components with one variable.
CS1 Lesson 2 Introduction to C++ CS1 Lesson 2 -- John Cole1.
C Programming n General Information on C n Data Types n Arithmetic Operators n Relational Operators n if, if-else, for, while by Kulapan Waranyuwat.
1 Chapter 3 Numeric Types, Expressions, and Output Dale/Weems/Headington.
Palindromes revisited Here's a simpler program for checking palindromes: int nums[100]; int i = 0, a; cin >> a; while(a > 0) { nums[i++] = a; cin >> a;
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
C++ Programming: Basic Elements of C++.
CSE1222: Lecture 2The Ohio State University1. mathExample2.cpp // math example #include using namespace std; int main() { cout
Copyright © Nancy Acemian 2004 For Loops-Break-Continue COMP For loop is a counter controlled loop. For loop is a pretest loop. Used when number.
CHAPTER 7 arrays I NTRODUCTION T O C OMPUTER P ROGRAMMING (CSC425)
CSC 107 – Programming For Science. The Week’s Goal.
Introduction to Java Java Translation Program Structure
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.
C++ Lecture 1 Friday, 4 July History of C++ l Built on top of C l C was developed in early 70s from B and BCPL l Object oriented programming paradigm.
Arrays and Strings. Why? Consider a class of 30 students, each has a score for hw1  Do we want to have 30 variables with different names?  Would it.
CSC1201: Programming Language 2 Lecture 1 Level 2 Course Nouf Aljaffan (C) CSC 1201 Course at KSU1.
CSC 107 – Programming For Science. Announcements.
Chapter 3 – Variables and Arithmetic Operations. Variable Rules u Must declare all variable names –List name and type u Keep length to 31 characters –Older.
C++ Basics. Compilation What does compilation do? g++ hello.cpp g++ -o hello.cpp hello.
Arrays Dr. Jose Annunziato. Arrays Up to this point we have been working with individual primitive data types Arrays allow working with multiple instances.
PROGRAM ESSENTIALS. TOKENS  SMALLEST UNITS OF A PROGRAM LANGUAGE  Special Symbols  Mathematical Operators  Punctuation  Word Symbols  Key Words.
1 Chapter 12 Arrays. 2 C++ Data Types structured array struct union class address pointer reference simple integral enum char short int long bool floating.
 Variables can store data of different types, and different data types can do different things.  PHP supports the following data types:  String  Integer.
Lecture 5 Computer programming -1-. Input \ Output statement 1- Input (cin) : Use to input data from keyboard. Example : cin >> age; 2- Output (cout):
Literals A literal (sometimes called a constant) is a symbol which evaluates to itself, i.e., it is what it appears to be. Examples: 5 int literal
Visual C# 2005 Using Arrays. Visual C# Objectives Declare an array and assign values to array elements Initialize an array Use subscripts to access.
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
Chad’s C++ Tutorial Demo Outline. 1. What is C++? C++ is an object-oriented programming (OOP) language that is viewed by many as the best language for.
1 A Simple “Hello World” Example #include // input-output library using namespace std; int main() // function main { cout
1 C++ Data Types structured array struct union class address pointer reference simple integral enum char short int long bool floating float double long.
Introduction to programming in java Lecture 21 Arrays – Part 1.
Computer Skills2 / Scientific Colleges 1 Arrays Topics to cover: Arrays Data Types One-dimensional Arrays Two-dimensional Arrays.
Arrays An array is a sequence of objects all of which have the same type. The objects are called the elements of the array and are numbered consecutively.
Data Storage So far variables have been able to store only one value at a time. What do you do if you have many similar values that all need to be stored?
CSCI 125 & 161 / ENGR 144 Lecture 6 Martin van Bommel.
7 - Programming 7J, K, L, M, N, O – Handling Data.
Chapter 6: Using Arrays.
Variables Mr. Crone.
Two Dimensional Array Mr. Jacobs.
Documentation Need to have documentation in all programs
Programming fundamentals 2 Chapter 1:Array
Arrays, For loop While loop Do while loop
2.1 Parts of a C++ Program.
Data type List Definition:
Formatting the Output The C++ standard library supplies many manipulators: endl, setw, fixed, showpoint, setprecesion. If we want to use endl, fixed, or.
Chapter 2: Introduction to C++.
Fundamental Programming
Arrays Arrays A few types Structures of related data items
Fundamental Programming
Java: Variables, Input and Arrays
Programming Fundamental
Class code for pythonroom.com cchsp2cs
Presentation transcript:

 For Loops › for (variable set; condition; incremental or decrement){ // loop beginning › } // loop end  While loops › while (condition) { // beginning › }// end of loop  Do While › do{ // beginning › }while(condition);

 One Way (if statements)  Two Way if else  Multiple Way if else if else or switch case

 IOMANIP With the deriective #include We gain several functions that allow for output manipulation fixed, setprecision(#), setw(#), showpoint, hidepoint,

 left  right  internal

 Boolean › bool x = true; also x =1; › bool y = false; also y = 0;  Characters › char a = ‘Y’;  This means that the variable a holds Capital Y, you compare against a Capital Y with single quotes around the letter to denote Character, it can be, number, letter, or symbol.

 String › string s = “Yes”; also s = “Go go oG”; › String is a group of characters, you denote a string with double quotes.  Integer › Int x = 5;  Integers are whole numbers, no decimal numbers, but both positive and negative.

 Double › double currency = 5.25; or 5.00 or 4  Double is able to hold decimal places  Float › float number = ;  Float can hold more information than double, but also takes more memory to declare

 Arrays are of any data type and are cells that are called by index. › Integer array that holds 5 values is declared › int arrayName [5] = {0,1,2,3,4}; › You call the value 3 by calling its index › arrayName [index] = 3;  What does Index =

 Think of arrays as a list of numbers, where you keep count. › Best way to deal with arrays is generally in for loops, where you can repeat actions a set number of times.

 Think of them as Rows or Columns… › What if you wanted to keep both Rows and Columns in a list of a single array?

 An array is a sequence of data › 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 is a sequence of ints › "Matthew", "Mark", "Luke", "John" is a sequence of strings int fibonacci[] = {1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89}; string books[] = {"Matthew", "Mark", "Luke", "John"};

 Class of dataint, float, string  Identifier ages, heights  Subscript operator [ ] (square brackets)  Size (length)10  Initial values{1, 1, 2, 3, 5, 8} int ages[10]; int fibonacci[] = {1, 1, 2, 3, 5, 8}; string books[] = {"Matthew", "Mark"}; int numbers[8] = {1, 1, 2, 3, 5}

elements subscript operator  We access elements of an array with the array's identifier and the subscript operator [] zero  Array elements count from zero (0) cout << "Book 0 is " << books[0] << '\n'; cout << "Book 3 is " << books[3] << '\n'; for (int e=0; e<11; e++){ // use elements 0-10 cout << "Element " << e << " is " << fibonacci[e] << endl; }

print e and element at e is e<11 e=0 e++ yes no There are 11 elements, 0 to 10

 We can set the value of an array element the same way fibonacci[0]=1; cout << fibonacci[0]; We get the value of an array element with the subscript operator

 The name sounds strange, the declaration is a little strange, but here is the best part. › Keeping a list of 5 columns and 10 rows is as simple as creating a single array › Declaring the appropriate data type  double myTable [5] [10];  Now you 50 junk values

 for(int i = 0; i < 5; i++) › for(int j = 0; j < 10; j++)  myTable [i][j] = 0;