Presentation is loading. Please wait.

Presentation is loading. Please wait.

Wednesday, 12/4/02, Slide #1 CS 106 Intro to Comp. Sci. 1 Wednesday, 12/4/02  Questions?  Return Test #2  General discussion of HW #05  Introduction.

Similar presentations


Presentation on theme: "Wednesday, 12/4/02, Slide #1 CS 106 Intro to Comp. Sci. 1 Wednesday, 12/4/02  Questions?  Return Test #2  General discussion of HW #05  Introduction."— Presentation transcript:

1 Wednesday, 12/4/02, Slide #1 CS 106 Intro to Comp. Sci. 1 Wednesday, 12/4/02  Questions?  Return Test #2  General discussion of HW #05  Introduction to operators  Reminders:  HW #05 due Monday at 5  Lab Friday as usual (on Operators in C++)  Exam is on Wed, Dec 18 at 1:30.

2 Wednesday, 12/4/02, Slide #2 Implementing ListClass  Default constructor is already complete  Input – Ask for Size, then fill in  Output – just what it says…  Length – Same as private Size  AddToList – Remember Size changes  Delete – Items must slide down  Search – Void function reports either index of item found or lack of success  Sort – just what it says….

3 Wednesday, 12/4/02, Slide #3 The testing program  Be sure to run the given exe file (Does it all work?) and to look at ListFuncs.cpp as a sample.  The menu approach works best.  Remember that, though it would be nice if everything worked perfectly, you may not be that lucky. Get the functions working one at a time, starting with input and output.  To compile, however, you must at least have “stub” implementations of all functions.

4 Wednesday, 12/4/02, Slide #4 New topic: Operators in C++ Classes  Think back to our first C++ class: Complex  We defined functions to add, subtract, multiply, input, and output complex objects.  Instead of the dot syntax, could we instead have used +, -, *, >>, and >> ?  Answer: Yes!!

5 Wednesday, 12/4/02, Slide #5 Operator Syntax  If the left hand “operand” is a member of our class (as is the case for +, -, and *), the operator is a “member operator” and can be defined inside the class definition  The prototype syntax is (for example): Complex Operator + (Complex x);  The implementation syntax is: Complex Complex::Operator + (Complex x);

6 Wednesday, 12/4/02, Slide #6 Operator Syntax: Input and Output  Input and output (extraction and insertion) are different since the left-hand operand is not a class member. Now in the header file you must place the prototype outside of the class definition, and both operands must be parameters.  Prototype and implementation syntax are the same, for example: istream& operator >> (istream& in, Complex x)  Let’s try it on Complex.h, etc.!!


Download ppt "Wednesday, 12/4/02, Slide #1 CS 106 Intro to Comp. Sci. 1 Wednesday, 12/4/02  Questions?  Return Test #2  General discussion of HW #05  Introduction."

Similar presentations


Ads by Google