1 / 11

Lecture 10: Don't Reinvent the Wheel

Lecture 10: Don't Reinvent the Wheel. Exam Results. Homework #3. Due on Monday, March 2, 2009 -- 8:00pm Exclusive OR logic ( XOR) A XOR B = ((A && !B) || (!A && B)). B. A. Software Engineer one of 10 hot jobs.

everly
Download Presentation

Lecture 10: Don't Reinvent the Wheel

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 10: Don't Reinvent the Wheel

  2. Exam Results

  3. Homework #3 • Due on Monday, March 2, 2009 -- 8:00pm • Exclusive OR logic (XOR) A XOR B = ((A && !B) || (!A && B)) B A Software Engineer one of 10 hot jobs http://hotjobs.yahoo.com/career-articles-wanted_you_10_jobs_where_employers_come_looking_for_you-668

  4. Using Functions • Easy management of large program development • Programs solving real-world problems are large. • Solution: divide-and-conquer • Construct a large program from smaller pieces or modules. • Each piece is more manageable. • Modules in C are called functions. Year Operating System SLOC (Million) 1993 Windows NT 3.1 4-5 1994 Windows NT 3.5 7-8 1996 Windows NT 4.0 11-12 2000 Windows 2000 more than 29 2001 Windows XP 40 2003 Windows Server 2003 50 Operating System SLOC (Million) Red Hat Linux 6.2 17 Red Hat Linux 7.1 30 OpenSolaris 9.7 FreeBSD 8.8 Mac OS X 10.4 86 Linux kernel 2.6.0 5.2 SLOC: source lines of code

  5. Using Functions • Avoid re-inventing the wheel • Using existing functions as building-blocks to create new programs • “Prepackaged” functions in the C Standard Library can be used. • User-defined functions can also be used.

  6. C Standard Library • A rich collection of functions • Common mathematical calculations • String manipulations • Character manipulations • Input/output • Others • Provide many of the capabilities one need. http://en.wikipedia.org/wiki/C_standard_library

  7. Function Calls • Invoking functions (by a function call) • Provide function name and arguments (data) • Function performs operations or manipulations • Function returns results • A common analogy of function call: • Boss asks worker to complete a task. Worker gets information, does task, returns result. Information hiding: boss does not know details. The calling function, or caller Hierarchical boss function/worker function relationship The called function, or callee

  8. Math Library Functions • Math library functions • Perform common mathematical calculations • #include <math.h> • While compiling, use the option -lm to link the math library. • Format for calling functions • FunctionName( argument ); • If multiple arguments, use comma-separated list • Example printf(“%.2f”, sqrt( 900.0 )); • Calls function sqrt, which returns the square root of its argument. • All math functions return data type double. • Arguments may be constants, variables, or expressions

  9. Commonly Used Math Library Functions

  10. Commonly Used Math Library Functions

  11. Law of Cosines Leg 1 Leg 2 Hypotenuse

More Related