Download presentation
Presentation is loading. Please wait.
Published byLambert Carroll Modified over 9 years ago
2
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);
3
One Way (if statements) Two Way if else Multiple Way if else if else or switch case
4
IOMANIP With the deriective #include We gain several functions that allow for output manipulation fixed, setprecision(#), setw(#), showpoint, hidepoint,
5
left right internal
10
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.
11
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.
12
Double › double currency = 5.25; or 5.00 or 4 Double is able to hold decimal places Float › float number = 2523.23424; Float can hold more information than double, but also takes more memory to declare
13
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 =
14
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.
15
Think of them as Rows or Columns… › What if you wanted to keep both Rows and Columns in a list of a single array?
16
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"};
17
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}
18
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; }
20
print e and element at e is e<11 e=0 e++ yes no There are 11 elements, 0 to 10
21
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
22
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
23
for(int i = 0; i < 5; i++) › for(int j = 0; j < 10; j++) myTable [i][j] = 0;
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.