Skip to main content

An Introduction to Classes

  • Chapter
  • First Online:
Guide to Scientific Computing in C++

Part of the book series: Undergraduate Topics in Computer Science ((UTICS))

  • 216k Accesses

Abstract

One of the key features of the C++ programming language is that it is object-oriented. Up until now we have largely ignored this feature, making only passing reference to it in earlier chapters. In this chapter we discuss in more detail three properties of object-orientation: modularity; abstraction; and encapsulation. This allows us to motivate the need for developing classes: entities where the data, and the operations on the data, are stored in one place. Access privileges to the members of a class are introduced: these prevent a user of a class from inadvertently corrupting the data or functionality of the class. We conclude the chapter by developing a class of complex numbers. This allows us to introduce operator overloading: a feature that permits us to define what we mean by addition, subtraction, multiplication and division of complex numbers, allowing much more natural looking C++ code to be written when performing these operations on complex numbers.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 1.

    The Generalised Minimal RESidual technique—commonly known as GMRES—is an iterative technique for solving linear systems. See, for example, Trefethen and Bau [4] for more details.

  2. 2.

    A unary operator has one input, hence -a is the unary minus operator applied to a.

  3. 3.

    A binary operator has two inputs, hence a+b is the binary addition operator applied to a and b.

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Joe Pitt-Francis .

Rights and permissions

Reprints and permissions

Copyright information

© 2017 Springer International Publishing AG, part of Springer Nature

About this chapter

Check for updates. Verify currency and authenticity via CrossMark

Cite this chapter

Pitt-Francis, J., Whiteley, J. (2017). An Introduction to Classes. In: Guide to Scientific Computing in C++. Undergraduate Topics in Computer Science. Springer, Cham. https://doi.org/10.1007/978-3-319-73132-2_6

Download citation

  • DOI: https://doi.org/10.1007/978-3-319-73132-2_6

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-319-73131-5

  • Online ISBN: 978-3-319-73132-2

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics