Using inheritance for computing with physical quantities: an interdisciplinary project

  • Authors:
  • Seth Bergmann

  • Affiliations:
  • Rowan University, Glassboro NJ

  • Venue:
  • SIGCSE '98 Proceedings of the twenty-ninth SIGCSE technical symposium on Computer science education
  • Year:
  • 1998

Quantified Score

Hi-index 0.00

Visualization

Abstract

This paper involves an interdisciplinary project in computer science and physics. Students in introductory physics courses need to be able to deal with dimensioned quantities (often called "dimensional analysis"), and to solve problems using the correct units for various physical quantities. Computer science students need to understand concepts of object-oriented programming, including the notion of inheritance. In this paper we present a project in which physical quantities such as distance, time, mass, speed, force, power, etc. are represented as objects. The student designing the classes can ensure that the client always combines quantities in an appropriate fashion (e.g. a force must be computed as a mass multiplied by an acceleration). The student designing the classes can also allow the client to compute physical quantities using different units (e.g., the addition of three distances: 1 inch + 2 meters + 3 feet). This is done by defining subclasses Meters, Miles, and Feet, all of which inherit from the class Distance, thus providing the student with a nice example of the proper use of inheritance.The relevant classes, with test driver software, have been implemented and are available at the URL: http://www.rowan.edu/~bergmann The software has been implemented in both C++ and Java, though this paper will use the C++ version in its exposition.