Start learning today, and be successful in your academic & professional career. Start Today!

• ## Related Services

### Start Learning Now

Our free lessons will get you started (Adobe Flash® required).

### Membership Overview

• *Ask questions and get answers from the community and our teachers!
• Practice questions with step-by-step solutions.
• Track your course viewing progress.
• Learn at your own pace... anytime, anywhere!

• Implement the following overloaded operators to each of the classes created in the previous lesson:
• = (assignment)
• == (equality) for the “Auto” class, compare each location to within some margin of error such as 0.001. Decide on an attribute important enough for comparison for the other classes
• != (inequality) opposite of (==)
• << (output to stream)
Decide whether to use the “Print” method you should have already written or output in a different format, such as a format that can be parsed easily when input using (>>).
• Use the assignment operator to copy your “Auto” objects into several instances.
• Create a program that loops in a similar fashion to the previous lesson, except each Auto will be updated in each loop, and each Auto will have slightly different pedal pressures so they will travel at different speeds.
• At each loop iteration, compare the locations of each auto to each of the others, and if any two are in the same location, print out a message to that effect
• Design test loops such that you will know in advance which two autos should pass each other, thus having at least one non-trivial case where they are in the same location.
• For the “Auto” class, also implement the less-than (<) operator. Use the location attribute where a larger location is “less than” a smaller location.
• After running the loops above, add each Auto to a Vector, then call the Vector’s “sort” method.
• Print each Auto in the Vector – the ones that print first are the “winners”, since their greater overall speeds allowed them to travel the farthest.
• Extra: in the output operator (<<), output each attribute separated by commas. E.g., instead of something like:
• Name: {auto name} Location: {location} Speed: {speed} Acceleration: {acceleration}
• or whatever format you chose, print it in this format:
{auto name} , {location} , {speed} , {acceleration}
• Leave the “Print” method in the more human-readable format
• As the code is processing the loops, in each iteration of each loop, direct the output to a file – use a different file for each auto instance
• This is known as a “CSV” or Comma Separated File. You can load this file into a spreadsheet program such as Excel, and use its graphing capabilities to make some pretty spectacular looking graphs

Lecture Slides are screen-captured images of important points in the lecture. Students can download and print out these lecture slide images to do practice problems as well as take notes while watching the lecture.

• Intro 0:00
• Overview 0:13
• When Not to Overload Operators 4:32
• Arithmetic Operators Should Only Apply to 'Numeric' Kinds of Classes
• Complex Number
• When It Can Be a Good Idea 7:42
• Your Class is Inherently Numeric In Nature
• Some Operators Still Make Sense to be Overloaded
• Kinds of Operators to Overload 11:03
• Binary Operator
• Unary Operator
• Non-Member Functions
• Example: Named Vector 15:03
• Named Vector is a Directional Vector with a Name
• Directional Vectors
• Assignment Operator= 20:26
• Deep Copy
• Copy Constructor
• Example Member Function
• Example 'Equal' Member Method
• Other Comparison Methods Can Call This One
• Example: 'Less Than' Member Method
• '@=' Operator
• Operations Work Symmetrically
• '@=' Is Member Function with Full Access
• '@' is Non-Member Function
• Multiple a Vector by a Number to Make it Larger
• Need Two Symmetrical Non-Member Functions
• No Parameter for the Operator@ Function
• Unary Operators with Different Semantics for Prefix and Postfix
• '++' and '--'
• Add 1.0 to X/Y Components Before Accessing Value for Caller
• Also Include the Operator-- to Subtract 1.0
• Give It a Dummy Operator
• Make Non-Member Function a 'Friend' to Access Private Members of Your Class
• Useful for Saving an Object to a File
• Include Non-Member 'Friend' Function in Class
• Implement Function in the Compilation Unit
• Allows Output of Your Objects with Other Data
• Array Operator[] 1:00:55
• Example: The Standard Library Vector
• Named Vector
• Overload Array Operator [] 1:03:19
• Implement Operator[] As a Member Function
• Write the Code
• It Lets You Define a Non-Int for the 'Array Index'
• Function Operator() 1:06:39
• Examples
• Define (idx)