Web page: http://www.cs.colorado.edu/~sbrandt/1300
Function definition vs. function use
-----
Syntax
#include
double pow(double x, double y);
long double powl(long double x, long double y);
Description
Calculates x to the power of y.
powl is the long double version; it takes long double arguments and
returns a long double result.
This function can be used with bcd and complex types.
Return Value
On success, pow and powl return the value calculated of x to the power
of y.
Sometimes the arguments passed to these functions produce results that
overflow or are incalculable. When the correct value would overflow,
the functions return the value HUGE_VAL (pow) or _LHUGE_VAL
(powl). Results of excessively large magnitude can cause the global
variable errno to be set to
ERANGE Result out of range
If the argument x passed to pow or powl is real and less than 0, and y
is not a whole number, or you call pow(0,0), the global variable errno
is set to
EDOM Domain error
Error handling for these functions can be modified through the
functions _matherr and _matherrl.
-----
-
The Syntax section tells us:
-
- How to use the function
- What include file we need (math.h)
- The type that the function returns (double)
- The number of parameters to the function (2)
- The types of any parameters to the function (double)
-
The Description section tells us:
-
- In detail what the function does
- The meanings of any parameters
-
The Return Value section tells us:
-
- What the function returns
- How to interpret the returned value
- Error codes that could be returned
Object-Oriented Programming
Classes allow for a fundamentally different way of programming -
Object-Oriented programming
Data is organized into objects that represent a conceptual unit.
Member functions perform the allowed operations on the data.
The implementation details of the object are hidden from the rest of the program.
The member functions comprise a well-defined interface to the object.
The implementation details can change without affecting the rest of the program.
Can be easily reused.
Examples of objects
Imaginary Numbers(Real, Imag - add(), subtract(), multiply(), divide())
Card catalog entry(Title, author, # of pages, in/out - reserve(), return())
Equipment List(Item, value, location, status - move(), new_value(), broken(), fixed())
Room reservation(Size, location, equipment, reservation - reserve(), unreserve(), print_schedule())
Architectural job(customer, start date, end date, drawings, timesheet, estimate, actual cost, rate... -- set*(),
get_drawing(), put_drawing(), change_estimate(), get_actual_cost(), add_hours() )
Clock( -- current_time)
Gradebook(Student, id, list of grade objects, overall grade, -- set*, print_grade());
Grade object(exam, value, grade - set_value(), set_grade(), get_normalized_value);
Square(length, color, -- set*(), draw())
...
Example: Imaginary Numbers
Example: Cin examples with strings