Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSC 107 - Programming for Science Lecture 37 : Course Review.

Similar presentations


Presentation on theme: "CSC 107 - Programming for Science Lecture 37 : Course Review."— Presentation transcript:

1 CSC 107 - Programming for Science Lecture 37 : Course Review

2 Final Exam Tuesday, Dec. 12 from 1 - 3 in OM 208 Plan for exam to take full 2 hours Exam covers material from entire semester  Format will be like that of 2 midterms  Still open-book, open-note, closed-computer

3 Discover how computers can solve important scientific problems Learn basics of software development Have fun Objectives Met in CSC107 Discover how computers can solve important scientific problems Learn basics of software development Have fun

4 Parts of a Program Should include liberal dose of comments  2 types to help document what is going on: // This comment continues to the line’s end /* This goes until it is closed */ Also begin with preprocessor directives  Define what functions program can use #include #include #include #include #include

5 Symbolic Constants Code “pre-processed” before compilation  Makes code simpler & easier to read Begins #define then the name and value  Name traditionally in ALL CAPITAL letters  Can be any type and need not be literal  Must be contained on own line #define NAME “bob” #define PI 3.141516 #define INDIANA_PI (22.0/7.0)

6 Macros Symbolic constant that takes a parameter #define SQUARED(x) (x * x) #define VELOCITY(init,a,t) (init+(a*t)) #define RAND_X(x) (rand() % x) #define RAND_RNG(lo,hi) ((rand()%(hi- lo))+lo) #define MAX(x,y) ((x > y) ? x : y) Parameter replaced by value passed in  Need to be very careful about this! i = MAX(i, random()); i = ((i > rand() ? i : rand());

7 Pointers Pointer is another set of types  Value of pointer is another memory location  Make aliases of a variable Pointers declared with asterisk ‘*’ before variable’s name Value is a memory location  Can get variable’s memory location using &

8 Creating struct Declare struct outside of any function  Declared after #includes & #defines Each struct must be given a name Can have 1 or more fields  Each field has name & data type  Fields can be listed in any order  Fields declared as if it were a variable  Each struct variable gets own copy of fields

9 Using structs Each field has its own value  Refer to using variable.field  Fields set & used on their individually  Requires actual variable to access Each variable gets copy of every field  No relationship between fields in different variables  No relationship between different fields in one variable

10 Data Types Each variable also has data type  Specifies how program treats variable’s value C includes 8 built-in data types  char, short, int, long, long long, float, double, long double  Ranges for each type NOT specified; may change from machine to machine struct allows programmer-defined data type Can also have pointer or arrays of any data type

11 Variable Declarations Functions begin with variable declarations  Declarations must be at start of function  Function use parameters & declared variables Each declaration includes two parts 1. Type of data that variable contains 2. Name of the variable

12 Names in C Begin with letter or underscore (_)  Then combine letters, numbers, & underscore Names are case-sensitive  Mass, mass, & masS treated as different Function’s variables’ names must be unique  Cannot know which of my 1,000 “bob” variables to use Cannot use C’s reserved words  (p. 38 should say “int”, not “ints”)

13 Declaring Array Variable Declare array variable before use  Declaration must also include literal size  Variable is an array of the requested type  Locations are variables of that type int sampleArray[10]; struct person class[30]; Only creates location between 0 & size-1  Cannot find an array’s size  Will not warn when accessing beyond size

14 Functions At least one programmer-defined function: int main(void) Must declare & define function to use  Built-in functions automatically via “.h” files Programmer-defined functions defined outside of each other return_type function_name(parameters) { declarations; statements; }

15 Return Type & Parameters Function must declare a return type  Can be any data type or void When not void, must return value  return expression; ends function execution and returns result of expression Functions can have 0 or more parameters  0 parameters noted using void keyword  Else list type & name of each parameter  Separate parameters in listing by comma

16 Hints for Studying The exam will NOT require:  Memorizing any functions  Memorizing any code  All but most simplistic material on struct The exam WILL require:  Knowing what the built-in functions do and how to use them  How to write and use all the C constructs we discussed

17 Studying For the Exam 1. What does this do? Review examples and make sure you can explain the results Generate traces to verify your understanding 2. How is it used? And why is it used? 3. When do we use it? Why is it written that way?

18 In Conclusion… CSC107 Final Exam: Tues., Dec. 12 from 1:00–3:00 in OM 208 Bring 1 (or more) pencils for the final Do well on all your exams Have a good Christmas break Consider taking further CSC courses  We’d love to see all of you again!


Download ppt "CSC 107 - Programming for Science Lecture 37 : Course Review."

Similar presentations


Ads by Google