Classes - PowerPoint PPT Presentation

1 / 9
About This Presentation
Title:

Classes

Description:

Classes. the full enchilada. Chapter 20. Agenda. Review. Constructor functions. Accessor functions ... Review--You can use the public functions defined for ... – PowerPoint PPT presentation

Number of Views:26
Avg rating:3.0/5.0
Slides: 10
Provided by: solo50
Category:

less

Transcript and Presenter's Notes

Title: Classes


1
Classes the full enchiladaChapter 20
2
Agenda
  • Review ?
  • Constructor functions
  • Accessor functions
  • Modifier functions
  • input/output functions
  • Summary

3
Review--Modeling a Balloon in C
  • class Balloon
  • public
  • void initialize(int initRad)
  • void inflate(int howMuch)
  • void pop( )
  • void display()
  • private
  • int radius

Member Functions
Member Data
4
Review--You can use the public functions defined
for the class
  • Balloon bal
  • bal.initialize(5)
  • bal.inflate(15)
  • bal.pop()

5
Review--Implement the initialize and inflate
functions
  • void Ballooninitialize(int initRad)
  • radius initRad
  • void Ballooninflate(int howMuch)
  • radius radius howMuch

This says it is a member function of Class
Balloon
Notice how the parameter modifiesthe member data
6
A client program is one that uses a class
  • int main()
  • Balloon myBalloon
  • myBalloon.initialize(3)
  • coutltlt"myBalloon currently has Radius "
  • myBalloon.display()
  • coutltlt"\nInflating myBalloon by 8 \n"
  • myBalloon.inflate(8)
  • coutltlt"Now myBalloon has Radius "
  • myBalloon.display()
  • coutltlt"\nPopping myBalloon \n"
  • myBalloon.pop()
  • coutltlt"myBalloon currently has Radius "
  • myBalloon.display()

7
Agenda
  • Review
  • Constructor functions ?
  • Accessor functions
  • Modifier functions
  • input/output functions
  • Summary

8
Fully defined Balloon class in C
  • class Balloon
  • public
  • // constructor functions
  • Balloon( ) // default constructor
  • Balloon(int initRad) // explicit constructor
  • // accessor functions
  • float volume( ) const // const means
    function cant
  • // change radius
  • int getRadius( ) const
  • // modifier functions
  • void inflate(int howMuch)
  • void pop( )
  • void setRadius(int r)
  • continued

9
Fully defined Balloon class in C
  • continued
  • // input/output functions
  • void display(ostream out)
  • void input(istream in)
  • private
  • int radius
  • // overloaded operators
  • ostream operatorltlt( ostream out, Balloon b)
  • istream operatorgtgt( istream in, Balloon b)
  • bool operator( Balloon b1, Balloon b2)
Write a Comment
User Comments (0)
About PowerShow.com