Modular Concept- Problems Decoupled Data and operations The resulting module structure is oriented on the operations rather than the actual data a The defined operations specify the data to be used
6 Modular Concept - Problems ◼ Decoupled Data and Operations ◼ The resulting module structure is oriented on the operations rather than the actual data ◼ The defined operations specify the data to be used
Object-Oriented Concept(C++) pro object data object data data object data Objects of the program interact by sending messages to each other
7 Object-Oriented Concept (C++) ◼ Objects of the program interact by sending messages to each other
Basic ctt Inherit all c syntax Primitive data types Supported data types: int, long, short, float double, char, bool and enum The size of data types is platform-dependent Basic expression syntax Defining the usual arithmetic and logical operations such as +r &,!,and| Defining bit-wise operations, such as & I, and Basic statement syntax If-else, for, while, and do-while
8 Basic C++ ◼ Inherit all C syntax ◼ Primitive data types ◼ Supported data types: int, long, short, float, double, char, bool, and enum ◼ The size of data types is platform-dependent ◼ Basic expression syntax ◼ Defining the usual arithmetic and logical operations such as +, -, /, %, *, &&, !, and || ◼ Defining bit-wise operations, such as &, |, and ~ ◼ Basic statement syntax ◼ If-else, for, while, and do-while
Basic C++(cont) ■ Add a new comment mark ∥/For1 line comment /.*/for a group of line comment New data type Reference data type & Much likes pointer nt ix/*ix is real variable * int&rx=ⅸ;/rxis"aias"forⅸ* ⅸ=1;/ also rx==1* rx=2:/alsoⅸ==2* const support for constant declaration, just likes C
9 Basic C++ (cont) ◼ Add a new comment mark ◼ // For 1 line comment ◼ /*… */ for a group of line comment ◼ New data type ◼ Reference data type “&”. Much likes pointer int ix; /* ix is "real" variable */ int & rx = ix; /* rx is "alias" for ix */ ix = 1; /* also rx == 1 */ rx = 2; /* also ix == 2 */ ◼ const support for constant declaration, just likes C
Class Definitions AC++ class consists of data members and methods(member functions) class Intcell Initializer list used to initialize the data Avoid implicit type conversion members directly public explicit Intcell( int initialvalye=0) storedvalue( initialvalue y[] Member functions int read( )const return storedValue iNdicates that the member's invocation does void write( int x) not change any of the data members storedvalue private int storedvalue Data member(s)
10 Class Definitions ◼ A C++ class consists of data members and methods (member functions). class IntCell { public: explicit IntCell( int initialValue = 0 ) : storedValue( initialValue ) {} int read( ) const { return storedValue;} void write( int x ) { storedValue = x; } private: int storedValue; } Member functions Data member(s) Indicates that the member’s invocation does not change any of the data members. Avoid implicit type conversion Initializer list: used to initialize the data members directly