CSCI 1300
Lecture Notes


9/9/97

Administrative Stuff

Function Definition vs. Function Use

Object-Oriented Programming

  • Examples of Objects



    Administrative Stuff

  • How to learn C++ (and how to get an A in this class)
  • Attend all lectures and recitations.
  • Read all readings carefully.
  • Create small programs of your own that test the various concepts that you are learning.
  • Changes to handing in programming assignments
  • Programming assignments due before 5:00 p.m. on Friday of the week they are due (I'll make this clear for each assignment).
  • May email text copy of assignments to Bob (rcooksey@cs.colorado.edu) OR
  • Demo them during lab hours (and turn in paper copy). You must make an appointment to demo your program. If you don't make an appointment and they are not available when you show up in the lab, then you will receive a 0 for the assignment.
  • 2nd assignment due this Friday (Sept. 12).
  • Reading: 5.1, 5.2, 5.3, 5.5, and 5.8
  • Programming Assignment 3 due Friday, Sept. 19.
  • QUIZ 1 on Tues. Sept 16.
  • Note: Don't worry about class constructors, we'll cover those later.
  • 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