上海交通大学交大密西根 联合学院·一 81 UM-SJTU Joint Institute ■ University of Michigan Shanghal Jiao Tong University Class Structure The structure of C++class hierarchy resembles the biological classification scheme introduced by Scandinavian botanist Carl Linnaeus in the 18th century.Linnaeus's contribution was to recognize that organisms fit into a hierarchical classification scheme in which the placement of individual species reflects anatomical similarities. Carl Linnaeus(1707-1778)
Class Structure Class Structure • The structure of C++ class hierarchy resembles the biological classification scheme introduced by Scandinavian botanist Carl Linnaeus in the 18th century. Linnaeus’s contribution was to recognize that organisms fit into a hierarchical classification scheme in which the placement of individual species reflects anatomical similarities. Carl Linnaeus (1707–1778)
Biological Class Hierarchy Living Things Kingdom Plants Animals Fungi Phylum Annelida Brachiopoda Arthropoda Mollusca Chordata Order Crustacea Insecta Arachnida Class Hymenoptera Family Classification of the red ant Formicidae Note that there can be many Iridomyrmex purpureus individual red ants,each of which is an instance of the Genus Iridomyrmex same basic class. Species purpureus
Biological Class Hierarchy Biological Class Hierarchy Living Things Plants Animals Fungi Annelida Brachiopoda Arthropoda Mollusca Chordata Crustacea Insecta Arachnida Hymenoptera Formicidae Iridomyrmex purpureus Kingdom Phylum Order Class Family Genus Species Classification of the red ant Iridomyrmex purpureus Every red ant is also an animal, an arthropod, and an insect, as well as the other superclasses in the chain. Note that there can be many individual red ants, each of which is an instance of the same basic class
The Program Hierarchy C++class hierarchies are Every GM car is also a similar to the biological MovingObjT Passengercar,an Automobile, class hierarchy from the and a MovingObject. That previous slide. This A means that every GM car can diagram, for example, have property specified in shows the hierarchy AutomobileT AutomobileT.The same is true formed for passenger cars for any car 0 made by A Volkewagon or Toyota. PassengerCarT Volkwagon GM Toyota
The Program Hierarchy The Program Hierarchy MovingObjT AutomobileT PassengerCarT Volkwagon GM Toyota C++ class hierarchies are similar to the biological class hierarchy from the previous slide. This diagram, for example, shows the hierarchy formed for passenger cars Every GM car is also a PassengerCar, an Automobile, and a MovingObject. That means that every GM car can have property specified in AutomobileT. The same is true for any car made by Volkewagon or Toyota
上海交通大学交大密西根 联合学院·一 ◆ 81 UM-SJTU Joint Institute University of Michigan Shanghal Jiao Tong University Expressions in C++ The heart of the Add2Integers program from Chapter 2 is the line intSum int1 int2; that performs the actual addition. The int1 int2 that appears to the right of the equal sign is an example of an expression,which specifies the operations involved in the computation. ● An expression in C++consists of terms joined together by operators. Each term must be one of the following: A constant (such as 3.14159265 or "hello,world") A variable name (such as int1,int2,or intSum) A function calls that returns a values (such as readInt) An expression enclosed in parentheses
Expressions in C++ Expressions in C++ • The heart of the Add2Integers program from Chapter 2 is the line intSum = int1 + int2; that performs the actual addition. • The int1 + int2 that appears to the right of the equal sign is an example of an expression, which specifies the operations involved in the computation. • An expression in C++ consists of terms joined together by operators. • Each term must be one of the following: – A constant (such as 3.14159265 or "hello, world") – A variable name (such as int1, int2, or intSum) – A function calls that returns a values (such as readInt) – An expression enclosed in parentheses
上海交通大学交大密西根 联合学院 81 UM-SJTU Joint Institute University of Michigan Shanghal Jiao Tong University Primitive Data Types ● Although complex data values are represented using objects,C++defines a set of primitive types to represent simple data. Of the eight primitive types available in C++,the programs in this text use only the following four: int:This type is used to represent integers,which are whole numbers such as 17 or-53. double:This type is used to represent numbers that include a decimal fraction,such as 3.14159265.In C++,such values are called floating-point numbers;the name double comes from the fact that the representation uses twice the minimum precision. bool:This type represents a logical value (true or false). char:This type represents a single character
Primitive Data Types Primitive Data Types • Although complex data values are represented using objects, C++ defines a set of primitive types to represent simple data. • Of the eight primitive types available in C++, the programs in this text use only the following four: – int: This type is used to represent integers, which are whole numbers such as 17 or –53. – double: This type is used to represent numbers that include a decimal fraction, such as 3.14159265. In C++, such values are called floating-point numbers; the name double comes from the fact that the representation uses twice the minimum precision. – bool: This type represents a logical value (true or false). – char: This type represents a single character