Support

Support Options

Submit a Support Ticket

 

C++ Classes

In object oriented programming, classes are data structures that are able to perform, or do stuff with the information it holds. These classes can be structured so that it’s properties and behavior are available to other classes or only itself. These and other features of object oriented programming make C++ a language suitable for large projects which need the coordination of several programmers and the modularization of tasks.

An example of a class is a shape class. A class called triangle, for example, can be a class which holds the properties of a triangle. Then the class can calculate the area of the described triangle through class functions, also called methods. These are declared within the class definition and defined later on the program.

Example of triangle class:


class triangle {

double base;

double height;

double getArea();

}

double getArea() {

double area = 0;

area = (base * height) / 2;

return area;

}

  1. Programming

Comments on this entry

There are no comments at this time.

Post a comment

Please keep comments relevant to this entry.

Line breaks and paragraphs are automatically converted. URLs (starting with http://) or email addresses will automatically be linked.

nanoHUB.org, a resource for nanoscience and nanotechnology, is supported by the National Science Foundation and other funding agencies. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the National Science Foundation.