上海交通大学交大密西根 联合学院·一 ◆ 181 UM-SJTU Joint Institute University of Michigan Shanghal Jiao Tong University class Definition (MsgConsoleT.h) class is a keyword defined in C++for user defined data type public is an attribute specifier keyword defined in C++; public versus private which is default in class member attribute disp (is defined to display the execution solution of the class class MsgConsoleT:public ConsoleT{ public: void disp(string name){ printLine (name,"welsome to the Vg101 class!",endl); Please input your first name here (no spaces>: samson samson,welsome to the Ug101 class! #endif
class Definition ( Definition (MsgConsoleT.h MsgConsoleT.h) class is a keyword defined in C++ for user defined data type public is an attribute specifier keyword defined in C++; public versus private which is default in class member attribute disp () is defined to display the execution solution of the class
上海交通大学交大密西根 联合学院 11 UM-SJTU Joint Institute University of Michigan Shanghal Jiao Tong University Different Programming Process In his Pulitzer-prizewinning book,computer scientist Douglas Hofstadter identifies two concepts-holism and reductionism-that turn out to be important as you begin to learn about programming. Holism is the most natural thing in the world to grasp. It's simply the belief that "the whole is greater than the sum of its parts'”. Reductionism is the most natural thing in the world to grasp.It's simply the belief that "a whole can be understood completely if you understand its parts,and the nature of their‘sum
Different Programming Process Different Programming Process • In his Pulitzer-prizewinning book, computer scientist Douglas Hofstadter identifies two concepts—holism and reductionism—that turn out to be important as you begin to learn about programming. • Holism is the most natural thing in the world to grasp. It’s simply the belief that “the whole is greater than the sum of its parts”. • Reductionism is the most natural thing in the world to grasp. It’s simply the belief that “a whole can be understood completely if you understand its parts, and the nature of their ‘sum’
Adding Two Integers #include <vg101class.h> #include "AddIntConsoleT.h" using namespace stdj ∥add two Integers int main (void) AddIntConsoleT consolej int int1,int2,intSumj console.printLine (This program will compute the sum ofn'); console.printLine (two integers specified by the user.nin") int1 console.readInt (Please input the first integer); int2=console.readInt (Please input the second integer") intSum =int1+int2; console.disp (int1,int2,intSum); return 0;
Adding Two Integers Adding Two Integers
上海交通大学交大密西根 联合学院·一 ◆] 181 UM-SJTU Joint Institute University of Michigan Shanghal Jiao Tong University class Definition (AddIntConsoleT.h) class AddIntConsoleT:public ConsoleT public: void disp (int intSum){ printLine (int1,"+"int2,"="intSum,endD); When you define a class to be a subclass of another one, it inherits all the data and functions of the other one. printLine is defined in ConsoleT and could be used in AddIntConsoleT just like it is defined in t
class AddIntConsoleT : public ConsoleT { // member data defined here // member function defined here }; class Definition ( Definition (AddIntConsole ConsoleT.h) class AddIntConsoleT: public ConsoleT { public: void disp (int intSum) { printLine (int1, " + ", int2, " = ", intSum, endl); } }; When you define a class to be a subclass of another one, it inherits all the data and functions of the other one. printLine () is defined in ConsoleT and could be used in AddIntConsoleT just like it is defined in t
上海交通大学交大密西根 联合学院 81 UM-SJTU Joint Institute University of Michigan Shanghal Jiao Tong University Object Definition General syntax: Modifier class/type object/var initial value Examples: AddIntConsoleT console; int int1,int2,intSum=0; All objects/variables sharing the same class/type will have the similar property defined in that class/type. The first line defined an object of class AddIntConsoleT(ype)and the second line defined 3 integer variables You can also initialize a variable while you declare it like intSum 0;
Object Definition Object Definition • General syntax: – Modifier class/type object/var = initial value – Examples: • AddIntConsoleT console; • int int1, int2, intSum = 0; • All objects/variables sharing the same class/type will have the similar property defined in that class/type. • The first line defined an object of class AddIntConsoleT(ype) and the second line defined 3 integer variables • You can also initialize a variable while you declare it like intSum = 0;