Presentation is loading. Please wait.

Presentation is loading. Please wait.

Research Topics in Computational Science. Agenda Survey Overview.

Similar presentations


Presentation on theme: "Research Topics in Computational Science. Agenda Survey Overview."— Presentation transcript:

1 Research Topics in Computational Science

2 Agenda Survey Overview

3 Notes on the Survey: End on Time – I will try to end 10 min early for work & qus This isn’t too slow – Nobody said slow, but some said fast Upload Class Code – More time on my code (I will slow down) Go Quicker: with questions Go Slower: with in class coding

4 Today’s Agenda Code with notes – practice for homework set Download the PPT to follow along with while coding

5 Indexing And Arrays In C we start counting at 0 The “1 st” value is actually the “0 th ” value in C

6 Array Indecies double x = {0.0, 3.14, …, 1.1, 2.7} 0.0 x[0] 3.14 x[1] …1.1 x[n-2] 2.7 x[n-1] The computer needs to set aside memory, then the values can be placed in memory. For an array of n elements we start at element 0 and access up to element n-1.

7 Arrays An array is a data object of a fixed size to hold many variables of the same type int[] a, b, c; // Will create 3 integer arrays This doesn’t allocate memory for the array a = new int[10]; Allocates memory for 10 ints in array a int[] a = {0,1}; //declare, allocate, assign values

8 Lists List – Creates an int list List – Creates a double list List – creates a list of strings List – creates a list of the type specified between <> We can create lists of any object We can have a list of buttons or images

9 List Functions x = myList[3]; – gets the value at index 3 from the list myList.Add(3.14); – Adds the value 3.14 to the list myList.Remove(3.14); – removes first occurance of 3.14 from the list myList.RemoveAt(3); – removes the item myList[3]

10 c++, c--, ++c, --c Only used for “int” c++ and ++c will add 1 to the variable c – c++ will use c, THEN add 1 – ++c will add 1 to c, then use it c-- and --c will subtract 1 from the variable c – c-- will use c, then subtract 1 – --c will subtract 1, then use c Example: c = 0; mbox(c++);//displays 0 mbox(c);// displays 1 mbox(++c);//displays 2

11 For Loop This will loop a specified number of times, AND increment a variable (usually i, j, or k) There is a standard loop that is used MOST of the time You can change as needed

12 For Code for (int i=0; i<5; i++) { mbox(“Hello” + name[i]); } This will say hello to the first five names in the array “name” Start at i=0 Continue while i<5 At the end of every loop do the operation i++

13 For Each Loop This will loop through each element of an array or list This can be very useful when we don’t know how many things are in our list/array

14 ForEach Code int cider = 0; foreach(int age in ages){ if(age<20) cider++; /* count the number of cider drinkers */ } We have to declare the type, here it is an int We have to give a temp name, age is a clear name for this We have to give the name of our array/list

15 While Loop While loops can run forever! – Becareful of infinite loops These will run while a statement is true

16 While Loop Example bool myval = 1; while( myVal < 100 ) { myVal = myVal * 2; } This will find the smallest power of 2 greater than 100. After each loop it checks the while

17 Do While Loop (aka do loop) This loop will ALWAYS execute one time At the end of the loop it checks to see if it should run again

18 Do While Loop myVal = 200; do { myVal *= 2; } while (myVal < 100); This does the same thing as the last loop. Even though 200 will give a false value for “while” it will still do the loop one time

19 Switch Control Select based on matching input This is good when you have a lot of cases to be tested for.

20 Switch Code switch( word ) { case “boy”: // do this break; case “girl”: // do this break; default: // do this break; } If the variable word is the same as “boy” it will do the first statement it will try every CASE until it finds one that matches or the end. Every case must have a break.


Download ppt "Research Topics in Computational Science. Agenda Survey Overview."

Similar presentations


Ads by Google