Classes 2 - PowerPoint PPT Presentation

1 / 4
About This Presentation
Title:

Classes 2

Description:

friend ostream& operator (ostream&, const Vector); Constructors ... v1 and v2 are objects of class Vector. cout 'adding ' endl; v1.adding(v2); cout v1; ... – PowerPoint PPT presentation

Number of Views:21
Avg rating:3.0/5.0
Slides: 5
Provided by: Office2004476
Category:
Tags: class | classes

less

Transcript and Presenter's Notes

Title: Classes 2


1
Classes 2
  • CMPSC 201C

2
Class Declaration
class Vector public Vector() x y z
0 Vector (double,double,double)
double getX() const return x double getY()
const return y double getZ() const return
z double magnitude() const private
double x,y,z friend istream operator gtgt
(istream, Vector) friend ostream operator
ltlt (ostream, const Vector)
Constructors
Prototypes of member functions
Data Members
Prototypes of friend functions
3
Using our New Function
  • Calling it from the main

// v1 and v2 are objects of class Vector cout ltlt
"adding " ltlt endl v1.adding(v2) cout ltlt v1
4
New Function
  • In our example we had 4 member functions.
  • We are adding a new member

double getX() const return x double
getY() const return y double getZ() const
return z double magnitude() const
  • - remember this function is called
  • in a way similar to
  • v1.adding(v2)
  • x, y and z are v1s attributes
  • v1 is being modified
  • vec2s members are referenced by using dot (.)

Prototype void adding(Vector) Function void
Vectoradding(Vector vec2) xxvec2.x
yyvec2.y zzvec2.z
Write a Comment
User Comments (0)
About PowerShow.com