Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 10: Don't Reinvent the Wheel. Exam Results.

Similar presentations

Presentation on theme: "Lecture 10: Don't Reinvent the Wheel. Exam Results."— Presentation transcript:

1 Lecture 10: Don't Reinvent the Wheel

2 Exam Results

3 Homework #3 Due on Monday, March 2, :00pm Exclusive OR logic (XOR) A XOR B = ((A && !B) || (!A && B)) B A wanted_you_10_jobs_where_employers_come_looking_ for_you-668 Software Engineer one of 10 hot jobs

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. YearOperating SystemSLOC (Million) 1993Windows NT Windows NT Windows NT Windows 2000more than Windows XP Windows Server Operating SystemSLOC (Million) Red Hat Linux Red Hat Linux OpenSolaris9.7 FreeBSD8.8 Mac OS X Linux kernel 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.

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. Hierarchical boss function/worker function relationship The calling function, or caller The called function, or callee

8 Math Library Functions Math library functions Perform common mathematical calculations #include 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( )); 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


11 Law of Cosines Leg 2 Leg 1 Hypotenuse

Download ppt "Lecture 10: Don't Reinvent the Wheel. Exam Results."

Similar presentations

Ads by Google