55 Pages

ICOM4015-lec04-f09

Course: ICOM 4015, Fall 2009
School: UPR Mayagüez
Rating:
 
 
 
 
 

Word Count: 3536

Document Preview

4015: ICOM Advanced Programming Lecture 4 Chapter Four: Fundamental Data Types ICOM 4015 Fall 2008 Big Java by Cay Horstmann Copyright 2008 by John Wiley & Sons. All rights reserved. Chapter Four: Fundamental Data Types ICOM 4015 Fall 2008 BigBig Javayby Cay Horstmann Java b Cay Horstmann Copyright 2008 by John Wiley & Sons. All rights reserved. Copyright 2008 by John Wiley & Sons. All...

Register Now

Unformatted Document Excerpt

Coursehero >> United States >> UPR Mayagüez >> ICOM 4015

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
4015: ICOM Advanced Programming Lecture 4 Chapter Four: Fundamental Data Types ICOM 4015 Fall 2008 Big Java by Cay Horstmann Copyright 2008 by John Wiley & Sons. All rights reserved. Chapter Four: Fundamental Data Types ICOM 4015 Fall 2008 BigBig Javayby Cay Horstmann Java b Cay Horstmann Copyright 2008 by John Wiley & Sons. All rights reserved. Copyright 2008 by John Wiley & Sons. All rights reserved. Chapter Goals To understand integer and floating-point numbers To recognize the limitations of the numeric types To become aware of causes for overflow and roundoff errors To understand the proper use of constants To write arithmetic expressions in Java To use the String type to define and manipulate character strings To learn how to read program input and produce formatted output ICOM 4015 Fall 2008 BigBig Javayby Cay Horstmann Java b Cay Horstmann Copyright 2008 by John Wiley & Sons. All rights reserved. Copyright 2008 by John Wiley & Sons. All rights reserved. Number Types int: integers, no fractional part 1, -4, 0 double: floating-point numbers (double precision) 0.5, -3.11111, 4.3E24, 1E-14 A numeric computation overflows if the result falls outside the range for the number type int n = 1000000; System.out.println(n * n); // prints -727379968 Java: 8 primitive types, including four integer types and two floating point types ICOM 4015 Fall 2008 BigBig Javayby Cay Horstmann Java b Cay Horstmann Copyright 2008 by John Wiley & Sons. All rights reserved. Copyright 2008 by John Wiley & Sons. All rights reserved. Primitive Types Type int Description The integer type, with range -2,147,483,648 . . . 2,147,483,647 The type describing a single byte, with range -128 . . . 127 The short integer type, with range -32768 . . . 32767 The long integer type, with range -9,223,372,036,854,775,808 . . . -9,223,372,036,854,775,807 Size 4 bytes 1 byte 2 bytes 8 bytes byte short long double The double-precision floating-point type, with a range of about 10308 and 8 about 15 significant decimal digits bytes The single-precision floating-point type, with a range of about 1038 and about 7 significant decimal digits The character type, representing code units in the Unicode encoding scheme The type with the two truth values false and true ICOM 4015 Fall 2008 float 4 bytes 2 bytes 1 bit char boolean BigBig Javayby Cay Horstmann Java b Cay Horstmann Copyright 2008 by John Wiley & Sons. All rights reserved. Copyright 2008 by John Wiley & Sons. All rights reserved. Number Types: Floating-point Types Rounding errors occur when an exact conversion between numbers is not possible Java: Illegal to assign a floating-point expression to an integer variable double balance = 13.75; int dollars = balance; // Error double f = 4.35; System.out.println(100 * f); // prints 434.99999999999994 Casts: used to convert a value to a different type int dollars = (int) balance; // OK Cast discards fractional part. Continued BigBig Javayby Cay Horstmann Java b Cay Horstmann Copyright 2008 by John Wiley & Sons. All rights reserved. Copyright 2008 by John Wiley & Sons. All rights reserved. ICOM 4015 Fall 2008 Number Types: Floating-point Types (cont.) Math.round converts a floating-point number to nearest integer long rounded = Math.round(balance); // if balance is 13.75, then // rounded is set to 14 ICOM 4015 Fall 2008 BigBig Javayby Cay Horstmann Java b Cay Horstmann Copyright 2008 by John Wiley & Sons. All rights reserved. Copyright 2008 by John Wiley & Sons. All rights reserved. Syntax 4.1 Cast (typeName) expression Example: (int) (balance * 100) Purpose: To convert an expression to a different type. ICOM 4015 Fall 2008 BigBig Javayby Cay Horstmann Java b Cay Horstmann Copyright 2008 by John Wiley & Sons. All rights reserved. Copyright 2008 by John Wiley & Sons. All rights reserved. Self Check 4.1 Which are the most commonly used number types in Java? Answer: int and double ICOM 4015 Fall 2008 BigBig Javayby Cay Horstmann Java b Cay Horstmann Copyright 2008 by John Wiley & Sons. All rights reserved. Copyright 2008 by John Wiley & Sons. All rights reserved. Self Check 4.2 When does the cast (long) x yield a different result from the call Math.round(x)? Answer: When the fractional part of x is 0.5 ICOM 4015 Fall 2008 BigBig Javayby Cay Horstmann Java b Cay Horstmann Copyright 2008 by John Wiley & Sons. All rights reserved. Copyright 2008 by John Wiley & Sons. All rights reserved. Self Check 4.3 How do you round the double value x to the nearest int value, assuming that you know that it is less than 2 109? Answer: By using a cast: (int) Math.round(x) ICOM 4015 Fall 2008 BigBig Javayby Cay Horstmann Java b Cay Horstmann Copyright 2008 by John Wiley & Sons. All rights reserved. Copyright 2008 by John Wiley & Sons. All rights reserved. Constants: final A final variable is a constant Once its value has been set, it cannot be changed Named constants make programs easier to read and maintain Convention: use all-uppercase names for constants final double QUARTER_VALUE = 0.25; final double DIME_VALUE = 0.1; final double NICKEL_VALUE = 0.05; final double PENNY_VALUE = 0.01; payment = dollars + quarters * QUARTER_VALUE + dimes * DIME_VALUE + nickels * NICKEL_VALUE + pennies * PENNY_VALUE; ICOM 4015 Fall 2008 BigBig Javayby Cay Horstmann Java b Cay Horstmann Copyright 2008 by John Wiley & Sons. All rights reserved. Copyright 2008 by John Wiley & Sons. All rights reserved. Constants: static final If constant values are needed in several methods, declare them together with the instance fields of a class and tag them as static and final Give static final constants public access to enable other classes to use them public class Math { ... public static final double E = 2.7182818284590452354; public static final double PI = 3.14159265358979323846; } double circumference = Math.PI * diameter; ICOM 4015 Fall 2008 BigBig Javayby Cay Horstmann Java b Cay Horstmann Copyright 2008 by John Wiley & Sons. All rights reserved. Copyright 2008 by John Wiley & Sons. All rights reserved. Syntax 4.2 Constant Definition In a method: final typeName variableName = expression; In a class: accessSpecifier static final typeName variableName = expression; Example: final double NICKEL_VALUE = 0.05; public static final double LITERS_PER_GALLON = 3.785; Purpose: To define a constant in a method or a class. ICOM 4015 Fall 2008 BigBig Javayby Cay Horstmann Java b Cay Horstmann Copyright 2008 by John Wiley & Sons. All rights reserved. Copyright 2008 by John Wiley & Sons. All rights reserved. ch04/cashregister/CashRegister.java 01: 02: 03: 04: 05: 06: 07: 08: 09: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: /** A cash register totals up sales and computes change due. */ public class CashRegister { /** Constructs a cash register with no money in it. */ public CashRegister() { purchase = 0; payment = 0; } /** Records the purchase price of an item. @param amount the price of the purchased item */ public void recordPurchase(double amount) { purchase = purchase + amount; } ICOM 4015 Fall 2008 Continued BigBig Javayby Cay Horstmann Java b Cay Horstmann Copyright 2008 by John Wiley & Sons. All rights reserved. Copyright 2008 by John Wiley & Sons. All rights reserved. ch04/cashregister/CashRegister.java (cont.) 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: /** Enters the payment received from the customer. @param dollars the number of dollars in the payment @param quarters the number of quarters in the payment @param dimes the number of dimes in the payment @param nickels the number of nickels in the payment @param pennies the number of pennies in the payment */ public void enterPayment(int dollars, int quarters, int dimes, int nickels, int pennies) { payment = dollars + quarters * QUARTER_VALUE + dimes * DIME_VALUE + nickels * NICKEL_VALUE + pennies * PENNY_VALUE; } /** Computes the change due and resets the machine for the next customer. @return the change due to the customer */ public double giveChange() { ICOM 4015 Fall 2008 Continued BigBig Javayby Cay Horstmann Java b Cay Horstmann Copyright 2008 by John Wiley & Sons. All rights reserved. Copyright 2008 by John Wiley & Sons. All rights reserved. ch04/cashregister/CashRegister.java (cont.) 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: } double change = payment - purchase; purchase = 0; payment = 0; return change; } public public public public static static static static final final final final double double double double QUARTER_VALUE = 0.25; DIME_VALUE = 0.1; NICKEL_VALUE = 0.05; PENNY_VALUE = 0.01; private double purchase; private double payment; ICOM 4015 Fall 2008 BigBig Javayby Cay Horstmann Java b Cay Horstmann Copyright 2008 by John Wiley & Sons. All rights reserved. Copyright 2008 by John Wiley & Sons. All rights reserved. ch04/cashregister/CashRegisterTester.java 01: 02: 03: 04: 05: 06: 07: 08: 09: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: /** This class tests the CashRegister class. */ public class CashRegisterTester { public static void main(String[] args) { CashRegister register = new CashRegister(); register.recordPurchase(0.75); register.recordPurchase(1.50); register.enterPayment(2, 0, 5, 0, 0); System.out.print("Change: "); System.out.println(register.giveChange()); System.out.println("Expected: 0.25"); register.recordPurchase(2.25); register.recordPurchase(19.25); register.enterPayment(23, 2, 0, 0, 0); System.out.print("Change: "); System.out.println(register.giveChange()); System.out.println("Expected: 2.0"); } ICOM 4015 Fall 2008 } BigBig Javayby Cay Horstmann Java b Cay Horstmann Copyright 2008 by John Wiley & Sons. All rights reserved. Copyright 2008 by John Wiley & Sons. All rights reserved. ch04/cashregister/CashRegisterTester.java (cont.) Output: Change: 0.25 Expected: 0.25 Change: 2.0 Expected: 2.0 ICOM 4015 Fall 2008 BigBig Javayby Cay Horstmann Java b Cay Horstmann Copyright 2008 by John Wiley & Sons. All rights reserved. Copyright 2008 by John Wiley & Sons. All rights reserved. Self Check 4.4 What is the difference between the following two statements? final double CM_PER_INCH = 2.54; and public static final double CM_PER_INCH = 2.54; Answer: The first definition is used inside a method, the second inside a class. ICOM 4015 Fall 2008 BigBig Javayby Cay Horstmann Java b Cay Horstmann Copyright 2008 by John Wiley & Sons. All rights reserved. Copyright 2008 by John Wiley & Sons. All rights reserved. Self Check 4.5 What is wrong with the following statement? double circumference = 3.14 * diameter; Answer: (1) You should use a named constant, not the "magic number" 3.14 (2) 3.14 is not an accurate representation of . ICOM 4015 Fall 2008 BigBig Javayby Cay Horstmann Java b Cay Horstmann Copyright 2008 by John Wiley & Sons. All rights reserved. Copyright 2008 by John Wiley & Sons. All rights reserved. Assignment, Increment, and Decrement Assignment is not the same as mathematical equality: items = items + 1; items++ is the same as items = items + 1 items-- subtracts 1 from items ICOM 4015 Fall 2008 BigBig Javayby Cay Horstmann Java b Cay Horstmann Copyright 2008 by John Wiley & Sons. All rights reserved. Copyright 2008 by John Wiley & Sons. All rights reserved. Assignment, Increment, and Decrement ICOM 4015 Fall 2008 BigBig Javayby Cay Horstmann Java b Cay Horstmann Copyright 2008 by John Wiley & Sons. All rights reserved. Copyright 2008 by John Wiley & Sons. All rights reserved. Self Check 4.6 What is the meaning of the following statement? balance = balance + amount; Answer: The statement adds the amount value to the balance variable. ICOM 4015 Fall 2008 BigBig Javayby Cay Horstmann Java b Cay Horstmann Copyright 2008 by John Wiley & Sons. All rights reserved. Copyright 2008 by John Wiley & Sons. All rights reserved. Self Check 4.7 What is the value of n after the following sequence of statements? n--; n++; n--; Answer: One less than it was before. ICOM 4015 Fall 2008 BigBig Javayby Cay Horstmann Java b Cay Horstmann Copyright 2008 by John Wiley & Sons. All rights reserved. Copyright by 2008 John Wiley & Sons. All rights reserved. Arithmetic Operations / is the division operator If both arguments are integers, the result is an integer. The remainder is discarded 7.0 / 4 yields 1.75 7 / 4 yields 1 Get the remainder with % (pronounced "modulo") 7 % 4 is 3 ICOM 4015 Fall 2008 BigBig Javayby Cay Horstmann Java b Cay Horstmann Copyright 2008 by John Wiley & Sons. All rights reserved. Copyright 2008 by John Wiley & Sons. All rights reserved. Arithmetic Operations final final final final int int int int PENNIES_PER_NICKEL = 5; PENNIES_PER_DIME = 10; PENNIES_PER_QUARTER = 25; PENNIES_PER_DOLLAR = 100; // Compute total value in pennies int total = dollars * PENNIES_PER_DOLLAR + quarters * PENNIES_PER_QUARTER + nickels * PENNIES_PER_NICKEL + dimes * PENNIES_PER_DIME + pennies; // Use integer division to convert to dollars, cents int dollars = total / PENNIES_PER_DOLLAR; int cents = total % PENNIES_PER_DOLLAR; ICOM 4015 Fall 2008 BigBig Javayby Cay Horstmann Java b Cay Horstmann Copyright 2008 by John Wiley & Sons. All rights reserved. Copyright 2008 by John Wiley & Sons. All rights reserved. The Math class Math class: contains methods like sqrt and pow To compute xn, you write Math.pow(x, n) However, to compute x2 it is significantly more efficient simply to compute x * x To take the square root of a number, use the Math.sqrt; for example, Math.sqrt(x) In Java, can be represented as (-b + Math.sqrt(b * b - 4 * a * c)) / (2 * a) ICOM 4015 Fall 2008 BigBig Javayby Cay Horstmann Java b Cay Horstmann Copyright 2008 by John Wiley & Sons. All rights reserved. Copyright 2008 by John Wiley & Sons. All rights reserved. Mathematical Methods Function Math.sqrt(x) Math.pow(x, y) Math.exp(x) Math.log(x) Math.sin(x), Math.cos(x), Math.tan(x) Math.round(x) Math.min(x, y), Math.max(x, y) Returns square root power xy ex natural log sine, cosine, tangent (x in radians) closest integer to x minimum, maximum ICOM 4015 Fall 2008 BigBig Javayby Cay Horstmann Java b Cay Horstmann Copyright 2008 by John Wiley & Sons. All rights reserved. Copyright 2008 by John Wiley & Sons. All rights reserved. Analyzing an Expression ICOM 4015 Fall 2008 BigBig Javayby Cay Horstmann Java b Cay Horstmann Copyright 2008 by John Wiley & Sons. All rights reserved. Copyright 2008 by John Wiley & Sons. All rights reserved. Self Check 4.8 What is the value of 1729 / 100? Of 1729 % 100? Answer: 17 and 29 ICOM 4015 Fall 2008 BigBig Javayby Cay Horstmann Java b Cay Horstmann Copyright 2008 by John Wiley & Sons. All rights reserved. Copyright 2008 by John Wiley & Sons. All rights reserved. Self Check 4.9 Why doesn't the following statement compute the average of s1, s2, and s3? double average = s1 + s2 + s3 / 3; // Error Answer: Only s3 is divided by 3. To get the correct result, use parentheses. Moreover, if s1, s2, and s3 are integers, you must divide by 3.0 to avoid integer division: (s1 + s2 + s3) / 3.0 ICOM 4015 Fall 2008 BigBig Javayby Cay Horstmann Java b Cay Horstmann Copyright 2008 by John Wiley & Sons. All rights reserved. Copyright 2008 by John Wiley & Sons. All rights reserved. Self Check 4.10 What is the value of Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)) in mathematical notation? Answer: ICOM 4015 Fall 2008 BigBig Javayby Cay Horstmann Java b Cay Horstmann Copyright 2008 by John Wiley & Sons. All rights reserved. Copyright 2008 by John Wiley & Sons. All rights reserved. Calling Static Methods A static method does not operate on an object double x = 4; double root = x.sqrt(); // Error Static methods are defined inside classes Naming convention: Classes start with an uppercase letter; objects start with a lowercase letter Math System.out ICOM 4015 Fall 2008 BigBig Javayby Cay Horstmann Java b Cay Horstmann Copyright 2008 by John Wiley & Sons. All rights reserved. Copyright 2008 by John Wiley & Sons. All rights reserved. Syntax 4.3 Static Method Call ClassName.methodName(parameters) Example: Math.sqrt(4) Purpose: To invoke a static method (a method that does not operate on an object) and supply its parameters. ICOM 4015 Fall 2008 BigBig Javayby Cay Horstmann Java b Cay Horstmann Copyright 2008 by John Wiley & Sons. All rights reserved. Copyright 2008 by John Wiley & Sons. All rights reserved. Self Check 4.11 Why can't you call x.pow(y) to compute xy? Answer: x is a number, not an object, and you cannot invoke methods on numbers. ICOM 4015 Fall 2008 BigBig Javayby Cay Horstmann Java b Cay Horstmann Copyright 2008 by John Wiley & Sons. All rights reserved. Copyright 2008 by John Wiley & Sons. All rights reserved. Self Check 4.12 Is the call System.out.println(4) a static method call? Answer: No the println method is called on the object System.out. ICOM 4015 Fall 2008 BigBig Javayby Cay Horstmann Java b Cay Horstmann Copyright 2008 by John Wiley & Sons. All rights reserved. Copyright 2008 by John Wiley & Sons. All rights reserved. Strings A string is a sequence of characters Strings are objects of the String class String constants: "Hello, World!" String variables: String message = "Hello, World!"; String length: int n = message.length(); Empty string: "" ICOM 4015 Fall 2008 BigBig Javayby Cay Horstmann Java b Cay Horstmann Copyright 2008 by John Wiley & Sons. All rights reserved. Copyright 2008 by John Wiley & Sons. All rights reserved. Concatenation Use the + operator: String name = "Dave"; String message = "Hello, " + name; // message is "Hello, Dave" If one of the arguments of the + operator is a string, the other is converted to a string String a = "Agent"; int n = 7; String bond = a + n; // bond is "Agent7" ICOM 4015 Fall 2008 BigBig Javayby Cay Horstmann Java b Cay Horstmann Copyright 2008 by John Wiley & Sons. All rights reserved. Copyright 2008 by John Wiley & Sons. All rights reserved. Concatenation in Print Statements Useful to reduce the number of System.out.print instructions System.out.print("The total is "); System.out.println(total); versus System.out.println("The total is " + total); ICOM 4015 Fall 2008 BigBig Javayby Cay Horstmann Java b Cay Horstmann Copyright 2008 by John Wiley & Sons. All rights reserved. Copyright 2008 by John Wiley & Sons. All rights reserved. Converting between Strings and Numbers Convert to number: int n = Integer.parseInt(str); double x = Double.parseDouble(x); Convert to string: String str = "" + n; str = Integer.toString(n); ICOM 4015 Fall 2008 BigBig Javayby Cay Horstmann Java b Cay Horstmann Copyright 2008 by John Wiley & Sons. All rights reserved. Copyright 2008 by John Wiley & Sons. All rights reserved. Substrings String greeting = "Hello, World!"; String sub = greeting.substring(0, 5); // sub is "Hello" Supply start and past the end position First position is at 0 ICOM 4015 Fall 2008 Continued BigBig Javayby Cay Horstmann Java b Cay Horstmann Copyright 2008 by John Wiley & Sons. All rights reserved. Copyright 2008 by John Wiley & Sons. All rights reserved. Substrings (cont.) Substring length is past the end - start ICOM 4015 Fall 2008 BigBig Javayby Cay Horstmann Java b Cay Horstmann Copyright 2008 by John Wile...

Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

CSU Northridge - HFBIO - 002
APPLICATION FOR: Semester_ Year__ Date Submitted GRADUATE ASSISTANT/TEACHING ASSOCIATE APPLICATION CALIFORNIA STATE UNIVERSITY, NORTHRIDGE DEPARTMENT OF BIOLOGY (For students in the M.S. program in biology only)_ Last Name, First MI _ Number Street Name
illinoisstate.edu - ENGLISH - 349
Details about the English 349 Organizational EthnographyThe goal of your Organizational Ethnography is to characterize your organization and your prospective readers for yourself, for your teacher, and for your peer reviewers. Doing the ethnography invo
University of Toronto - CSC - 209
CSC209: Software tools CSC209 ReviewYeah! We made it!1 Unix files and directories permissions utilities/commands Shell programming quoting wild cards files2. and C programming . C basic syntax functions arrays structs strings pointers (!) function
University of Toronto - CSC - 209
University of Toronto - CSC - 209
ConcurrencyConcurrencyHaviland Ch. 8.3.3 The two key concepts driving computer systems and applications are communication: the conveying of information from one entity to another concurrency: the sharing of resources in the same time frame Concurrenc
University of Toronto - CSC - 209
The problemc1 server read(c1) blocked read(c2) writeI/O Multiplexingc2"gone for coffee"Haviland 7.1.6 When reading from multiple sources, blocking on one of the sources could be bad. An example of denial of service. One solution: one process for eve
University of Toronto - CSC - 209
Simple Web Request5LFKDUGV+RPH3DJHCommunicationSockets (Haviland Ch. 10)&RXUVHV5HVHDUFK12How do we find the server? Every computer on the Internet has an Internet address. Called an IP address (Internet Protocol) An IP address is four 8-bit numbe
University of Toronto - CSC - 209
SignalsSignalsHaviland Ch. 6 Unexpected/unpredictable asynchronous events floating point error death of a child interval timer expired (alarm clock) control-C (termination request) control-Z (suspend request)1 Events are called interrupts When the k
University of Toronto - CSC - 209
Exchanging data between processesInter-process CommunicationPipes (Haviland Ch. 7) After fork() is called we end up with two independent processes. We cannot use variables to communicate between processes since they each have separate address spaces, a
University of Toronto - CSC - 209
Compilers, Interpreters, LibrariesComparing compilers and interpreters Shared vs. non-shared libraries.1Layers of System Softwarecat less vi date gcc nedit grep ddd csh (or bash or ksh) libc C Interface to Unix system servicesUnix system services Uni
University of Toronto - CSC - 209
Layers of System SoftwareCompilers, Interpreters, LibrariesComparing compilers and interpreters Shared vs. non-shared libraries.catlessvidategccneditgrepdddcsh (or bash or ksh) libc C Interface to Unix system servicesUnix system services Unix
University of Toronto - CSC - 209
Pointers to FunctionsFunction PointersKing Chapter 17.7 Since a pointer is just an address, we can have pointers to functions!int cube(int x) cfw_ return x*x*x; int (*f)(int); /*Define a function pointer*/ f = cube; /* Call the function that f points
University of Toronto - CSC - 209
Function PointersKing Chapter 17.71Pointers to Functions Since a pointer is just an address, we can have pointers to functions!int cube(int x) cfw_ return x*x*x; int (*f)(int); /*Define a function pointer*/ f = cube; /* Call the function that f poin
University of Toronto - CSC - 209
External and static variables External variable: declared outside the body of a function File scope: visible from the point of the declaration to the end of the file. Static storage duration: through the duration of the program. External/global variables
University of Toronto - CSC - 209
External and static variables External variable: declared outside the body of a function File scope: visible from the point of the declaration to the end of the file. Static storage duration: through the duration of the program. External/global variables
University of Toronto - CSC - 209
209 - Tutorial Week 6Files and directories in COpening filesFILE *fopen(const char *filename, const char *mode); Filename: identifies file to open Mode: "r" for reading "w" for writing "a" for appendingClosing filesint fclose(FILE *stream);File Out
University of Toronto - CSC - 209
Note: Questions 1-3 are taken from the King book, pg. 2181. If i is a variable and p points to i, which of the following expressions are aliases for i? (a and g) What is the meaning of each expression? int i = 10; a) *p - 10 b) &p - address of p c
University of Toronto - CSC - 209
Static Allocation Recall: static allocation happens at compile time based on variable definitions.int x = 2; int a[4]; int *b; int main() cfw_SYMBOL TABLE: main 0x804837c x 0x8049588 b 0x8049688 a 0x804968c .text .data .bss .bss0x804837cmainDynamic
University of Toronto - CSC - 209
Pointers and Arrays Recall the pointer syntax: char *cptr; declares a pointer to a char allocates space to store a pointer (to a char) char c = 'a'; cptr = &c; cptr gets the value of the address of c the value stored at the memory location referred t
University of Toronto - CSC - 209
Strings Strings are not a built-in data type. C provides almost no special means of defining or working with strings. A string is an array of characters terminated with a null character ('\0')String literalschar *name = "csc209h"; printf("This is a str
University of Toronto - CSC - 209
Pointers and Arrays Recall the pointer syntax: char *cptr; declares a pointer to a char allocates space to store a pointer (to a char)Pointers and Arrayschar *cptr; char c = 'a'; cptr = &c; *cptr = 'b';Symbol Table cptr 0x80493e0 c 0x80494dc 0x80493
University of Toronto - CSC - 209
209 - Tutorial Week 4Assignment 1 More shell script examples C programmingCut#! /bin/sh # List all the users in /etc/passwd. FILENAME=/etc/passwd for user in $(cut -d: -f1 $FILENAME) do echo $user doneMore return valuesadduser() cfw_ USER=$1; PASSWD=
University of Toronto - CSC - 209
Cut 209 - Tutorial Week 4Assignment 1 More shell script examples C programming #! /bin/sh # List all the users in /etc/passwd. FILENAME=/etc/passwd for user in $(cut -d: -f1 $FILENAME) do echo $user doneMore return valuesadduser() cfw_ USER=$1; PASSWD=
University of Toronto - CSC - 209
The C Programming Language#include <stdio.h>Intro to Cint main() cfw_ int i; extern int gcd(int x, int y); for (i = 0; i < 20; i+) printf("gcd of 12 and 0 is 0\n", i, gcd(12,i); return (0); int gcd(int x, int y) cfw_ int t; while (y) cfw_ t = x; x = y
University of Toronto - CSC - 209
Shell ReviewShell is a simple process: prompt input and parse command cause specified command to be executed repeatSome user-friendly features: aliases, filename expansion, job numbers1PathsPath: a list of directories to look up commands to be exec
University of Toronto - CSC - 209
Shell ReviewShell is a simple process: prompt input and parse command cause specified command to be executed repeatPathsPath: a list of directories to look up commands to be executed csh: sh: set path = ( a b c ) PATH=a:b:cSome user-friendly feature
University of Toronto - CSC - 209
%!PS-Adobe-2.0 %Creator: dvips(k) 5.86 Copyright 1999 Radical Eye Software %Title: onlycheatsheet.dvi %Pages: 2 %PageOrder: Ascend %BoundingBox: 0 0 612 792 %EndComments %DVIPSWebPage: (www.radicaleye.com) %DVIPSCommandLine: dvips -t letter onlycheatsheet
University of Toronto - CSC - 209
209 - Tutorial week 3Some shell scripts1st program#!/bin/sh track=1 for file in *.mp3 do mv "$file" "$cfw_track.mp3" track=`expr $track + 1` doneA little more elaborate#!/bin/sh track=1 for file in *.mp3 do if test $track -lt 10 then mv "$file" "0$cf
University of Toronto - CSC - 209
%!PS-Adobe-2.0 %Creator: dvips(k) 5.86 Copyright 1999 Radical Eye Software %Title: final.dvi %Pages: 14 %PageOrder: Ascend %BoundingBox: 0 0 612 792 %EndComments %DVIPSWebPage: (www.radicaleye.com) %DVIPSCommandLine: dvips -t letter final.dvi -o final.ps
UNC - BWV - 938
Praeludium Nr. 6"Sechs kleine Prludien"Johann Sebastian Bach (165-1750) Bwv 938 BWV 9383 8Clavier3 8611161.212.Creative Commons Attribution-ShareAlike 3.0226313641461.2.Sheet music from www. MutopiaProject .org Free to download, Types
BU - CS - 552
IA-32 Intel Architecture Software Developers ManualVolume 3: System Programming GuideNOTE: The IA-32 Intel Architecture Developers Manual consists of three books: Basic Architecture, Order Number 245470-007; Instruction Set Reference Manual, Order Numbe
BU - CS - 552
IA-32 Intel Architecture Software Developers ManualVolume 2: Instruction Set ReferenceNOTE: The IA-32 Intel Architecture Software Developers Manual consists of three volumes: Basic Architecture, Order Number 245470-007; Instruction Set Reference, Order
BU - CS - 552
%!PSAdobe2.0 %Title: Threads paper (Times) %Creator: PrintMonitor %CreationDate: Thursday, February 11, 1993 %Pages: (atend) %BoundingBox: ? ? ? ? %PageBoundingBox: 30 31 582 761 %For: Andrew %DocumentProcSets: "(AppleDict md)" 71 0 % Copyright Apple Comp
Mobile - ANR - 0048
A L A B A M AA & MA N DA U B U R NU N I V E R S I T I E SWeed Management inANR-48Lakes and PondsFor a small farm pond, a drawdown every 3 or 4 years exposing at least one-half of the bottom may be helpful in controlling submerged vegetation. Condu
UC Davis - ECS - 150
I NSTALLING B OCHS AND M INIX ON W INDOWS XPP re pa re d F o r: La st R ev i s io n: EC S1 5 0 ( O p era t i ng Sy s t e ms ) P ro f e s so r Wu F a ll 2 0 0 3 0 2 O ct o b er 2 0 0 3P REPARATIONRequired Files: File NameBochs-2.0.2.exe minix.tar.gz fl
UC Davis - ECS - 150
Instructions on using Bochs 2.0 for your ECS 150 programming assignments- What is Bochs?Bochs is an IA-32 (x86) PC emulator. It includes emulation of the Intel x86 CPU, common I/O devices, and custom BIOS. Currently, Bochs can be compiled to emulate a 3
Oregon State - CS - 352
Requirements Engineering in the Year 00: A Research PerspectiveAxel van LamsweerdeDpartement dIngnierie Informatique Universit catholique de Louvain B-1348 Louvain-la-Neuve (Belgium) avl@info.ucl.ac.beABSTRACT Requirements engineering (RE) is concerned
Oregon State - CS - 352
Personas: Practice and TheoryJohn Pruitt Microsoft Corporation One Microsoft Way Redmond, WA 98052 USA +1 425 703 4938 jpruitt@microsoft.com Jonathan Grudin Microsoft Research One Microsoft Way Redmond, WA 98052 USA +1 425 706 0784 jgrudin@microsoft.com
Lake County - ECE - 313
SOLUTIONS TO Midterm I ECE 313 FALL 2007 1. True, True, False, False, True, True, True, False, False, True. Brief reasons: (i) P (E c F c ) = P (EF )c ) = 1 P (EF ). (ii) 1 P (E c |F c )P (F c ) = 1 P (E c F c ) = 1 P (E F )c ) = 1 1 + P (E F ). (iii) If
North Texas - FILES - 433
TEKS 6 D & FMendelian Genetics Pedigrees & KaryotypesTAKS Objective 2 The student will demonstrate an understandingof living systems and the environment.TEKS Science Concepts 6 D & FThe student knows the structures and functions of nucleic acids in t
CUNY Baruch - MAT - 231
%!PS-Adobe-2.0 %Creator: dvips(k) 5.86 Copyright 1999 Radical Eye Software %Title: rev3.dvi %Pages: 2 %PageOrder: Ascend %BoundingBox: 0 0 612 792 %DocumentFonts: CMBX12 CMR12 CMSY10 CMR10 CMMI10 CMBX10 CMSY8 CMR8 %+ MSBM10 CMMI8 EUSM10 CMMI12 CMEX10 %End
CUNY Baruch - MAT - 231
Math 231 Practice Test 2, 11/12/20051. Consider the vectors u = (1, 1, 0, 2) and v = (0, 0, 1, 5) in R4 . Find (i) u (2u 3v) (ii) u + v (iii) The unit vector in the direction of u v. (iv) The distance between u and v. (v) The scalar a such that u is orth
CUNY Baruch - MAT - 231
Math 231 Practice Test, 11/7/20041. Solve the system 2x + 3y - z = 1 3x + 5y + 2z = 8 x - 2y - 3z = -1by Cramer's rule.2. Consider the vectors u = (1, -1, 0, 2) and v = (0, 0, 1, 5) in R4 . Find (i) u (2u - 3v) (ii) u + v (iii) The unit vector in the d
CUNY Baruch - MAT - 231
Math 231 Practice Test 1, 9/29/20051. Consider the linear system 2x + 4y + 6z = 18 4x + 5y + 6z = 24 3x + y 2z = 4(i) Write this system as Ax = b by introducing the matrices A, x and b. (ii) Solve the system using Gauss-Jordan elimination (i.e., by redu
CUNY Baruch - MAT - 231
Math 231 Practice Test 1 SolutionsProblem 1. (i) Set 24 6 A = 4 5 6 3 1 2 x y x= z 18 24 . b= 4 . .9 . . . 12 . . . 23 .. . (ii) We form the augmented matrix [A . b] . 2 4 6 . 18 1 . 12 3 2 R1 . . . b] = 4 5 6 . [A . 4 5 6 . 24 . 3 1 2 . 4 . 3 1 2and r
CUNY Baruch - MAT - 231
Math 231 Practice Test, 9/28/20041. Consider the linear system 2x + 4y + 6z = 18 4x + 5y + 6z = 24 3x + y 2z = 4(i) Write this system as Ax = b by introducing the matrices A, x and b. (ii) Solve the system using Gauss-Jordan elimination (i.e., by reduci
CUNY Baruch - MAT - 231
Math 231 Second Midterm SolutionsProblem 1. Mark each of the following statements as true (T) or false (F). Briey say why you have made your choice. If the vectors v1 , v2 , v3 span a vector space V , then dim V = 3. False, because v1 , v2 , v3 may be li
CUNY Baruch - MAT - 231
Math 231 First Midterm SolutionsProblem 1. Mark each of the following statements as true (T) or false (F). Briey say why you have made your choice. Every system of 3 linear equations in 4 variables has a solution. False. For example, the system x + y + z
Lake County - CI - 399
1152 1588 1650 1335 1830 2064 2200 1580 2625 2600 1584 2034 2132 2400 4820 1000 1780 1517102 108 110.5 115 162 174 189 198 230 255 150 135 160 225 329 75 88 96350 300 250 200 150 100 50 0 0f(x) = 0.07x + 20.94 R = 0.77Column B Linear Regression for Co
Lake County - CI - 399
C&I 399 Section TSMSummer 2003 Tim Hendrix, Instructor Week Three Assignments: June 30 July 4 Monday: Post: Metalesson Post: Continue to work on Geometer's Sketchpad analysis of conic sections.Continue to get caught up on all of the reading and other a
University of Toronto - DGP - 384
CSC384: Lecture 8Last time Action Representation; planning as search Today STRIPS Planning, Regression planning Readings: Today: 8.3 (STRIPS planning in depth, regressionplanning, briefly resolution-based planning)STRIPS PlannerLast time, discussed in
Grinnell College - CSC - 151
Fundamentals of CS I (CS151 2001S)Format for Lab Write-UpsAt times during this semester, I will ask you to write up your laboratory exercises. This document provides some basic guidelines for laboratory writeups. File Types and Names Starting the File S
National Taiwan University - COB - 804
SEC Staff Accounting Bulletin: No. 99 MaterialitySECURITIES AND EXCHANGE COMMISSION 17 CFR Part 211 [Release No. SAB 99] Staff Accounting Bulletin No. 99 AGENCY: Securities and Exchange Commission ACTION: Publication of Staff Accounting Bulletin SUMMARY:
Grinnell College - CSC - 151
Fundamentals of CS I (CS151 2001S)Homework 1: A CS151 Web SiteAssigned: Thursday, 25 January 2001 Due: 9:00 a.m., Friday, 2 February 2001 No extensions! Summary: In this assignment, you will build a small Web site dedicated to some aspect of introductor
Grinnell College - CSC - 151
Fundamentals of CS I (CS151 2001S)Homework 5: Higher-Order ProceduresPreliminariesPreliminariesAssigned: Monday, 2 April 2001 Due: Friday, 6 April 2001 No extensions without prior permission! Summary: In this assignment, you will continue your investi
Grinnell College - CSC - 151
Fundamentals of CS I (CS151 2001S)Homework 6: ProjectsPreliminaries Assignment DetailsPreliminariesAssigned: Thursday, April 19, 2001 Due: Friday, May 4, 2001 No extensions without prior permission! Summary: In this assignment, you will apply your kno
Eckerd - PS - 302
PSB 302: SOCIAL PSYCHOLOGY Fall, 2008 INSTRUCTOR: OFFICE: PHONE: OFFICE HOURS: TEXT: Dr. Mark H. Davis (davismh@eckerd.edu) PSY 236 864-8263 Monday, 10:00 Noon; Thursday, 3:00 5:00 p.m. Social Psychology (4th Edition) by FranzoiPURPOSE OF THE COURSE This
Maryland - M - 111
Math 111: Introduction to Probability Quiz 8 - November 9, 2007Name:This quiz covers material from sections 8.18.3.1.(2 points) Circle the histogram that represents a probability distribution with the greater variance.2. (4 points) Acme Stanley Inves
UMass (Amherst) - ECE - 655
UNIVERSITY OF MASSACHUSETTS Department of Electrical and Computer Engineering Fault Tolerant Computing Homework 4 1. Show that the three cases enumerated in connection with the derivation of the hypercube network reliability lower bound, are mutually excl
UMass (Amherst) - ECE - 655
UNIVERSITY OF MASSACHUSETTS Department of Electrical and Computer Engineering Fault Tolerant Computing Homework 5 1. You have a task with execution time, T . You take N checkpoints, equally spaced through the lifetime of that task. The overhead for each c
UMass (Amherst) - ECE - 655
UNIVERSITY OF MASSACHUSETTS Department of Electrical and Computer Engineering Fault Tolerant Computing Homework 3 1. Given a number X and its residue modulo-3, C(X) = |X|3 ; how will the residue change when X is shifted by one bit position to the left if