PowerPoint Presentation

Size: px
Start display at page:

Download "PowerPoint Presentation"

Transcription

1 程序设计 II 第 10 讲运算符重载与类型转换 计算机学院黄章进

2 内容 10.1 基本概念 10.2 输入和输出运算符 10.3 算术和关系运算符 10.4 赋值运算符 10.5 下标运算符 10.6 自增和自减运算符 10.7 成员访问运算符 10.8 函数调用运算符 10.9 类型转换运算符 2

3 基本概念 重载运算符函数的声明形式 : 返回类型 operator 运算符 ( 形参表 ) { // 函数体 } 3

4 基本概念 只能重载已有的运算符 不允许重载作用域 (::) 成员访问 (.* 与. ) 和条件 (?:) 等 4 个运算符 有四个运算符 (+, -, *, &) 既是一元运算符也是二元运算符 重载运算符的优先级和结合律和内置运算符一致 不能改变运算对象数量, 且重载运算符的运算对象至少有一个是类类型 // error: cannot redefine the built-in operator for ints int operator+(int, int); 4

5 基本概念 重载运算符函数的形参数与运算符的运算对象数一样多 除了函数调用运算符 operator() 外, 其他重载运算符不能含有默认实参 运算符可以重载为类的非静态成员函数 成员运算符函数的 ( 显式 ) 形参数比运算符的运算对象数少 1 个 第一个 ( 左侧 ) 运算对象绑定到隐式的 this 运算符函数也可以重载为非成员函数 至少有一个类类型的形参 5

6 直接调用重载的运算 符函数 基本概念 能像调用普通函数一样直接调用非成员运算符函数 // equivalent calls to a nonmember operator function data1 + data2; // normal expression operator+(data1, data2); // equivalent function call 也可以显式地调用成员运算符函数 data1 += data2; // expression-based ''call'' data1.operator+=(data2); // equivalent call to a member operator function 6

7 有些运算符不应被重载 基本概念 使用重载运算符本质上是函数调用, 内置运算符指定的运算对象的求值顺序不适用于重载运算符 逻辑与 (&&) 和逻辑或 ( ) 的短路求值属性 逗号 (,) 运算符的求值顺序 通常情况下, 不应重载逗号 (,) 取地址 (&) 逻辑与 (&&) 和逻辑或 ( ) 运算符 重载后运算符的行为异于常态 7

8 使用与内置类型一致 的含义 基本概念 在确定类需要哪些操作后, 操作是定义成普通函数还是重载运算符呢? 在逻辑上与运算符相关的操作适合定义成重载的运算符 : 如果类执行 IO 操作, 定义移位运算符使其与内置类型的 IO 保持一致 如果类有检查相等性的操作, 定义 operator==; 通常也应该有 operator!= 如果类有排序操作, 定义 operator<; 通常也应有其他所有的关系运算符 重载运算符的返回类型通常应与其内置版本的返回类型兼容 逻辑和关系运算符应返回 bool, 算法运算符应返回类类型的值,( 复合 ) 赋值运算符应返回左侧运算对象的引用 8

9 重载为成员或非成员 基本概念 运算符重载为成员还是普通非成员函数的一些准则 : 赋值 (=) 下标 ([]) 调用 (()) 和成员访问箭头 (- >) 运算符必须定义为成员函数 复合赋值运算符一般来说应是成员函数 改变对象状态或与给定类型密切相关的运算符, 如自增 (++) 自减 (--) 和解引用 (*) 运算符通常应该是成员函数 具有对称性的运算符可能类型转换任意一侧的运算对象, 例如算术 相等性 关系和位运算符等, 通常应定义为普通的非成员函数 9

10 输入和输出运算符 运算符重载和类型转换 IO 标准库分别使用 >> 和 << 执行输入和输出操作 IO 库定义了用它们读写内置类型的版本 与 iostream 库兼容的输入输出运算符必须是普通的非成员函数 IO 运算符通常需读写类的非公有数据成员, 所以常声明为友元 输出运算符负责打印对象的内容而非控制格式, 通常不应打印换行符 输入运算符必须处理一些输入可能失败的情形, 而输出运算符一般不需要 10

11 书店销售数据类 class Sales_data { public: Sales_data() {}; Sales_data(const std::string &s, unsigned n, double p): bookno(s), units_sold(n), revenue(p*n) { } Sales_data(const std::string &s): bookno(s) { } std::string isbn() const { return bookno; } private: double avg_price() const { return units_sold? revenue/units_sold : 0; } std::string bookno; unsigned units_sold; double revenue; }; 11

12 重载输出运算符 << 输入和输出运算符 输出运算符的第一个形参是非常量 ostream 对象的引用 第二个形参是要打印类类型的 const 引用 operator<< 一般返回 ostream 的引用 ostream &operator<<(ostream &os, const Sales_data &item) { os << item.isbn() << " " << item.units_sold << " " << item.revenue << " " << item.avg_price(); return os; } 12

13 重载输入运算符 >> 输入和输出运算符 第一个形参是非常量 istream 对象的引用 ; 第二个形参是要读入的 ( 非常量 ) 对象的引用 ; 返回 istream 的引用 istream &operator>>(istream &is, Sales_data &item) { double price; // no need to initialize; we'll read into price before we use it is >> item.bookno >> item.units_sold >> price; if (is) // check that the inputs succeeded item.revenue = item.units_sold * price; else item = Sales_data(); // input failed: give the object the default state return is; } 13

14 输入时的错误 重载输入运算符 >> 执行输入运算符时可能发生如下错误 当流含有错误类型的数据时, 读取操作可能失败 当读取操作到达文件末尾或者遇到输入流的其他错误时, 也会失败 if (is) else // check that the inputs succeeded item.revenue = item.units_sold * price; item = Sales_data(); // input failed: give the object the default state 14

15 算术和关系运算符 运算符重载和类型转换 通常把算术和关系运算符定义为非成员函数, 以允许对左侧或右侧运算对象进行类型转换 形参通常都是 const 的引用 算术和关系运算符不改变运算对象的状态 算法运算符一般返回类类型的值 关系运算符返回 bool 值 15

16 算术运算符 算术和关系运算符 算术运算符对它的两个运算对象进行计算得到一个新值 新值存于局部变量, 返回其副本作为结果 如果类定义了算术运算符, 一般也会定义对应的复合赋值运算符 常使用复合赋值来定义算术运算符 // assumes that both objects refer to the same book Sales_data operator+(const Sales_data &lhs, const Sales_data &rhs) { } Sales_data sum = lhs; // copy data members from lhs into sum sum += rhs; // add rhs into sum return sum; 16

17 相等运算符 算术和关系运算符 只有当所有对应的成员都相等时, 才认为两个对象相等 bool operator==(const Sales_data &lhs, const Sales_data &rhs) { return lhs.isbn() == rhs.isbn() && lhs.units_sold == rhs.units_sold && lhs.revenue == rhs.revenue; } bool operator!=(const Sales_data &lhs, const Sales_data &rhs) { return!(lhs == rhs); } 17

18 相等运算符 算术和关系运算符 一些设计准则 如果类含有判断两个对象是否相等的操作, 则应把函数定义成 operator== 而非一个普通的命名函数 如果类定义了 operator==, 它也应该定义 operator!= 相等和不相等运算符中的一个应把工作委托给另外一个 如果类定义了 operator==, 则该运算符应能判断给定对象是否包含等价的数据 相等运算符应该具有传递性 18

19 关系运算符 算术和关系运算符 定义了相等运算符的类也常常 ( 但不总是 ) 包含关系运算符 标准库中关联容器和一些算法要用到小于运算符, 所以定义 operator< 会比较有用 通常情况下, 关系运算符应该 定义逻辑合理的顺序关系, 使其与关联容易中对关键字的要求一致 定义的顺序关系应与类中 ( 若有 ) 相等运算符相容 如果两个对象是!= 的, 则一个应 < 另外一个 19

20 赋值运算符 运算符重载和类型转换 赋值运算符必须定义为成员函数 拷贝赋值运算符把类的一个对象赋值给该类的另一个对象 类还可以定义其他赋值运算符, 以使用别的类型作为右侧运算对象 必须返回对 *this 的引用 20

21 赋值运算符 运算符重载和类型转换 string 库重载了多个赋值运算符函数 // illustration of assignment operators for class string class string { public: string& operator=(const string &); // s1 = s2; string& operator=(const char *); // s1 = "str"; string& operator=(char); // s1 = 'c'; //... }; 支持如下的赋值操作 : string car ("Volks"); car = "Studebaker"; // string = const char* string model; model = 'T'; // string = char 21

22 复合赋值运算符 运算符重载和类型转换 复合赋值运算符不要求是类的成员函数, 但倾向于把包括复合赋值在内的所有赋值运算符定义在类内 复合赋值运算符返回左侧运算对象的引用 // member binary operator: left-hand operand is bound to the implicit this pointer // assumes that both objects refer to the same book Sales_data& Sales_data::operator+=(const Sales_data &rhs) { units_sold += rhs.units_sold; revenue += rhs.revenue; return *this; } 22

23 下标运算符 运算符重载和类型转换 表示容器的类通过位置来访问元素, 通常会定义下标运算符 operator[] 下标运算符必须是非静态成员函数 下标形参可以是任意类型 下标运算符返回所访问元素的引用 通常定义两个版本 非常量版本返回普通引用 常量版本返回常量引用 23

24 下标运算符 运算符重载和类型转换 class HasPtr { public: HasPtr(const std::string &s = std::string()): ps(new std::string(s)), i(0) { } char& operator[](std::size_t n) { return ps[n]; } // n should be a valid index const char& operator[](std::size_t n) const { return ps[n]; } // other members as before private: std::string *ps; int i; }; 24

25 自增和自减运算符 运算符重载和类型转换 迭代器类通常会实现自增 (++) 运算符和自减 (--) 运算符 C++ 不要求它们必须是成员函数, 但常被定义为成员函数 通常同时定义前置版本和后置版本 前置运算符返回自增或自减后对象的引用 后置运算符返回对象的原值 ( 自增或自减之前的值 ) 25

26 定义前置自增 / 自减运算符 自增和自减运算符 class HasPtr { public: // increment and decrement HasPtr& operator++(); // prefix operators HasPtr& operator--(); // other members as before private: std::string *ps; int i; }; 26

27 定义前置自增 / 自减运算符 自增和自减运算符 // prefix: return a reference to the incremented / decremented object HasPtr& HasPtr::operator++() { // if i already points past the end of the container, can't increment it ++i; // advance the current state return *this; } HasPtr& HasPtr::operator--() { // if i is zero, decrementing it will yield an invalid subscript --i; // move the current state back one element return *this; } 27

28 区分前置和后置运算符 自增和自减运算符 后置版本接受一个额外 ( 不被使用 ) 的 int 类型的形参 使用后置运算符时, 编译器为这个形参提供一个值为 0 的实参 class HasPtr { public: }; // increment and decrement HasPtr& operator++(int); HasPtr& operator--(int); // other members as before // postfix operators 28

29 定义后置版本 自增和自减运算符 // postfix: increment/decrement the object but return the unchanged value HasPtr HasPtr::operator++(int) { HasPtr ret = *this; // save the current value ++*this; // advance one element; prefix ++ checks the increment return ret; // return the saved state } HasPtr HasPtr::operator--(int) { HasPtr ret = *this; // save the current value --*this; // move backward one element; prefix -- checks the decrement return ret; // return the saved state } 29

30 显式调用后置运算符 自增和自减运算符 后置版本必须在自增 / 自减前保存对象的当前状态 保存后, 可以调用各自的前置版本完成实际的工作 通过函数调用方式调用后置版本时, 必须为整型形参传递一个值 HasPtr hp("hello World!"); hp++; hp.operator++(0); // call postfix operator++ ++hp; hp.operator++(); // call prefix operator++ 30

31 成员访问运算符 运算符重载和类型转换 解引用 (*) 和箭头 (->) 运算符常用在迭代器类及智能指针类中 箭头运算符必须是类的成员 解引用运算符通常也是 ( 非必须 ) 类的成员 31

32 成员访问运算符 运算符重载和类型转换 class HasPtr { public: std::string& operator*() const { return *ps; // (*ps) is the string to which this object points } std::string* operator->() const { // delegate the real work to the dereference operator return & this->operator*(); // equivalent to return ps; } // other members as before private: std::string *ps; int i; }; 32

33 箭头运算符返回值的限定 成员访问运算符 重载的箭头运算符必须返回指向类对象的指针或者一个重载了 operator-> 的类的对象 箭头运算符是一种特殊的二元运算符, 右侧运算对象是标识符, 而不是值 重载时, 箭头运算符看作一元后置运算符 根据 point 的类型,point->men 等价于 (*point).mem; // point is a built-in pointer type point.operator->()->mem; // point is an object of class type 33

34 函数调用运算符 运算符重载和类型转换 如果类重载了函数调用运算符 (), 则该类的对象称作函数对象 (function object) 函数调用运算符必须是非静态成员函数 调用运算符函数可以重载 struct absint { int operator()(int val) const { return val < 0? -val : val; } }; 使用调用运算符的方式是像函数调用一样令函数对象作用于一个实参列表 int i = -42; absint absobj; // object that has a function-call operator int ui = absobj(i); // passes i to absobj.operator() 34

35 含有状态的函数对象类 函数调用运算符 函数对象类除了 operator() 之外可以包含其他成员 数据成员被用于定制调用运算符中的操作 class PrintString { public: PrintString(ostream &o = cout, char c = ' '): os(o), sep(c) { } void operator()(const string &s) const { os << s << sep; } private: }; ostream &os; // stream on which to write char sep; // character to print after each output 35

36 含有状态的函数对象类 函数调用运算符 定义 PrintString 的对象时, 分隔符和输出流可以使用默认值也可以提供值 string s("hello World!"); PrintString printer; // uses the defaults; prints to cout printer(s); PrintString errors(cerr, '\n'); errors(s); cerr // prints s followed by a space on cout // prints s followed by a newline on 36

37 类型转换运算符 运算符重载和类型转换 类型转换运算符 (conversion operator) 是特殊的成员函数, 将类类型的值转换成其他类型 类型转换函数的一般形式为 : operator type() const; type 表示能作为函数返回类型 (void 除外 ) 的任意类型 没有显式的返回类型 ( 隐含为 type) 和形参 通常被定义成 const 成员 37

38 定义含有类型转换运 算符的类 类型转换运算符 定义一个表示 间整数的类 class SmallInt { public: SmallInt(int i = 0): val(i) // 转换构造函数 { if (i < 0 i > 255) throw std::out_of_range("bad SmallInt value"); } operator int() const { return val; } private: std::size_t val; }; 定义了 SmallInt 和 int 类型间的相互转换 38

39 定义含有类型转换运 算符的类 类型转换运算符 尽管编译器一次只能执行一个用户定义的类型转换, 但隐式的用户定义转换可以置于一个标准 ( 内置 ) 类型转换之前或之后一起应用 SmallInt si; si = 4; // implicitly converts 4 to SmallInt then calls SmallInt::operator= si + 3; // implicitly converts si to int followed by integer addition // the double argument is converted to int using the built-in conversion SmallInt si = 3.14; // calls the SmallInt(int) constructor // the SmallInt conversion operator converts si to int; si ; // that int is converted to double using the built-in conversion 39

40 运算符重载基本规则 一元运算符可以是不带参数的成员函数或带一个参数的非成员函数 对前置一元运算符 可以解释为 或 可以解释为 x.operator@(int) 或 operator@(x, int) 二元运算符可以是带一个参数的成员函数或带两个参数的非成员函数 可以解释为 x.operator@(y) 或 operator@(x, y) 重载的运算符应尽量模拟运算符对内置类型的行为 40

41 运算符重载基本规则 operator= operator[] operator() operator-> 和 operator type 只能定义为成员函数 operator-> 的返回值必须是一个指针或能使用 -> 的对象 重载 operator++ 和 operator-- 时带一个 int 形参表示后置, 不带参数表示前置 除 operator new 和 operator delete 外, 重载的运算符参数中至少要有一个非内置数据类型 41

Microsoft PowerPoint - 8. 运算符重载 Operator Overloading.pptx

Microsoft PowerPoint - 8. 运算符重载 Operator Overloading.pptx 运算符重载 Operator Overloading class Point { public: ; double x_, y_; Why Operator Overloading? Point (double x =0, double y = 0):x_(x),y_(y) { int main(){ Point a(1., 2), b(3,4); Point c = a + b; return 0;

More information

运算符重载 为什么要 运算符重载 那些运算符可以重载, 哪些不可以 如何实现运算符重载 实现方式 : 成员函数与非成员函数 类型转换 怎样实现对象与基本数据类型数据的运算 2

运算符重载 为什么要 运算符重载 那些运算符可以重载, 哪些不可以 如何实现运算符重载 实现方式 : 成员函数与非成员函数 类型转换 怎样实现对象与基本数据类型数据的运算 2 第十一讲 运算符重载 与类型转换 运算符重载 为什么要 运算符重载 那些运算符可以重载, 哪些不可以 如何实现运算符重载 实现方式 : 成员函数与非成员函数 类型转换 怎样实现对象与基本数据类型数据的运算 2 为什么要运算符重载 预定义的运算符只针对基本数据类型, 若要对类的对象进行类似的运算, 需要重新定义运算符的功能 运算符重载实质就是函数重载 : 对已有的运算符赋予多重含义, 使得同一个运算符作用于不同类型的数据时导致不同的行为

More information

Microsoft PowerPoint - string_kruse [兼容模式]

Microsoft PowerPoint - string_kruse [兼容模式] Strings Strings in C not encapsulated Every C-string has type char *. Hence, a C-string references an address in memory, the first of a contiguous set of bytes that store the characters making up the string.

More information

OOP with Java 通知 Project 4: 4 月 18 日晚 9 点 关于抄袭 没有分数

OOP with Java 通知 Project 4: 4 月 18 日晚 9 点 关于抄袭 没有分数 OOP with Java Yuanbin Wu cs@ecnu OOP with Java 通知 Project 4: 4 月 18 日晚 9 点 关于抄袭 没有分数 复习 类的复用 组合 (composition): has-a 关系 class MyType { public int i; public double d; public char c; public void set(double

More information

C++ 程序设计 告别 OJ1 - 参考答案 MASTER 2019 年 5 月 3 日 1

C++ 程序设计 告别 OJ1 - 参考答案 MASTER 2019 年 5 月 3 日 1 C++ 程序设计 告别 OJ1 - 参考答案 MASTER 2019 年 月 3 日 1 1 INPUTOUTPUT 1 InputOutput 题目描述 用 cin 输入你的姓名 ( 没有空格 ) 和年龄 ( 整数 ), 并用 cout 输出 输入输出符合以下范例 输入 master 999 输出 I am master, 999 years old. 注意 "," 后面有一个空格,"." 结束,

More information

OOP with Java 通知 Project 4: 4 月 19 日晚 9 点

OOP with Java 通知 Project 4: 4 月 19 日晚 9 点 OOP with Java Yuanbin Wu cs@ecnu OOP with Java 通知 Project 4: 4 月 19 日晚 9 点 复习 类的复用 组合 (composition): has-a 关系 class MyType { public int i; public double d; public char c; public void set(double x) { d

More information

C++ 程序设计 实验 2 - 参考答案 MASTER 2017 年 5 月 21 日 1

C++ 程序设计 实验 2 - 参考答案 MASTER 2017 年 5 月 21 日 1 C++ 程序设计 实验 2 - 参考答案 MASTER 2017 年 5 月 21 日 1 1 CRECT 类 1 CRect 类 设计矩形类, 包含 长度和宽度信息 基本构造函数 基础属性的访问接口 ( 读 / 写, Read/Write, Get/Set) 计算周长和面积 ( 注 : 基本构造函数, 一个无参数的默认构造函数, 以及一个初始化数据成员的构造函数如果数据成员的初始化有多种形式, 就提供多个构造函数

More information

C/C++ - 函数

C/C++ - 函数 C/C++ Table of contents 1. 2. 3. & 4. 5. 1 2 3 # include # define SIZE 50 int main ( void ) { float list [ SIZE ]; readlist (list, SIZE ); sort (list, SIZE ); average (list, SIZE ); bargragh

More information

Microsoft Word - ch04三校.doc

Microsoft Word - ch04三校.doc 4-1 4-1-1 (Object) (State) (Behavior) ( ) ( ) ( method) ( properties) ( functions) 4-2 4-1-2 (Message) ( ) ( ) ( ) A B A ( ) ( ) ( YourCar) ( changegear) ( lowergear) 4-1-3 (Class) (Blueprint) 4-3 changegear

More information

C++ 程序设计 OJ1 - 参考答案 MASTER 2019 年 5 月 3 日 1

C++ 程序设计 OJ1 - 参考答案 MASTER 2019 年 5 月 3 日 1 C++ 程序设计 OJ1 - 参考答案 MASTER 2019 年 5 月 3 日 1 1 CIRCLE 1 Circle 描述 编写一个圆类 Circle, 实现半径的输入 面积的计算和输出 输入 圆的半径 (double 类型 ) 输出 圆的面积 ( 保留小数点后两位 ) 样例输入 3 样例输出 28.27 提示 圆周率的取值需要比较精确, 以保证计算结果的精度 #include

More information

C/C++语言 - 运算符、表达式和语句

C/C++语言 - 运算符、表达式和语句 C/C++ Table of contents 1. 2. 3. 4. C C++ 5. 6. 7. 1 i // shoe1.c: # include # define ADJUST 7. 64 # define SCALE 0. 325 int main ( void ) { double shoe, foot ; shoe = 9. 0; foot = SCALE * shoe

More information

WWW PHP Comments Literals Identifiers Keywords Variables Constants Data Types Operators & Expressions 2

WWW PHP Comments Literals Identifiers Keywords Variables Constants Data Types Operators & Expressions 2 WWW PHP 2003 1 Comments Literals Identifiers Keywords Variables Constants Data Types Operators & Expressions 2 Comments PHP Shell Style: # C++ Style: // C Style: /* */ $value = $p * exp($r * $t); # $value

More information

CC213

CC213 : (Ken-Yi Lee), E-mail: feis.tw@gmail.com 49 [P.51] C/C++ [P.52] [P.53] [P.55] (int) [P.57] (float/double) [P.58] printf scanf [P.59] [P.61] ( / ) [P.62] (char) [P.65] : +-*/% [P.67] : = [P.68] : ,

More information

北京大学

北京大学 1 运算符重载 基本概念 郭炜刘家瑛 北京大学程序设计实习 运算符 C++ 预定义表示对数据的运算 +, -, *, /, %, ^, &, ~,!,, =, ,!= 只能用于基本的数据类型 整型, 实型, 字符型, 逻辑型 2 自定义数据类型与运算符重载 C++ 提供了数据抽象的手段 : 用户自己定义数据类型 -- 类 调用类的成员函数 操作它的对象 类的成员函数 操作对象时, 很不方便

More information

C/C++ - 文件IO

C/C++ - 文件IO C/C++ IO Table of contents 1. 2. 3. 4. 1 C ASCII ASCII ASCII 2 10000 00100111 00010000 31H, 30H, 30H, 30H, 30H 1, 0, 0, 0, 0 ASCII 3 4 5 UNIX ANSI C 5 FILE FILE 6 stdio.h typedef struct { int level ;

More information

C++ 程序设计 实验 3 - 参考答案 MASTER 2017 年 5 月 21 日 1

C++ 程序设计 实验 3 - 参考答案 MASTER 2017 年 5 月 21 日 1 C++ 程序设计 实验 3 - 参考答案 MASTER 2017 年 5 月 21 日 1 1 圆 1 圆 设计圆类 包含 包含基本属性和基本属性访问接口 计算面积和周长接口 2 1 圆 1 #include 2 using namespace std ; 3 c l a s s CCircle 4 { 5 p r i v a t e : 6 double r ; 7 const

More information

新版 明解C++入門編

新版 明解C++入門編 511!... 43, 85!=... 42 "... 118 " "... 337 " "... 8, 290 #... 71 #... 413 #define... 128, 236, 413 #endif... 412 #ifndef... 412 #if... 412 #include... 6, 337 #undef... 413 %... 23, 27 %=... 97 &... 243,

More information

Microsoft PowerPoint - 6. 用户定义类型User-defined Datatypes.ppt [兼容模式]

Microsoft PowerPoint - 6. 用户定义类型User-defined Datatypes.ppt [兼容模式] 用户定义类型 User-defined Datatypes classes and structs 几何向量 (Geometry Vector) 二维平面上的向量由起点和终点构成 每个点包含两个坐标 (x, y), 因此一个向量需要四个实数表示 Start= (0.9,1.5) Start= (0.4,0.8) int main() { double xstart = 0.4; double xend

More information

Strings

Strings Inheritance Cheng-Chin Chiang Relationships among Classes A 類 別 使 用 B 類 別 學 生 使 用 手 機 傳 遞 訊 息 公 司 使 用 金 庫 儲 存 重 要 文 件 人 類 使 用 交 通 工 具 旅 行 A 類 別 中 有 B 類 別 汽 車 有 輪 子 三 角 形 有 三 個 頂 點 電 腦 內 有 中 央 處 理 單 元 A

More information

IO

IO 1 C/C++ C FILE* fscanf fgets fread fprintf fputs fwrite C++ ifstream ofstream >>

More information

OOP with Java 通知 Project 3: 3 月 29 日晚 9 点 4 月 1 日上课

OOP with Java 通知 Project 3: 3 月 29 日晚 9 点 4 月 1 日上课 OOP with Java Yuanbin Wu cs@ecnu OOP with Java 通知 Project 3: 3 月 29 日晚 9 点 4 月 1 日上课 复习 Java 包 创建包 : package 语句, 包结构与目录结构一致 使用包 : import restaurant/ - people/ - Cook.class - Waiter.class - tools/ - Fork.class

More information

chap07.key

chap07.key #include void two(); void three(); int main() printf("i'm in main.\n"); two(); return 0; void two() printf("i'm in two.\n"); three(); void three() printf("i'm in three.\n"); void, int 标识符逗号分隔,

More information

C/C++ - 字符输入输出和字符确认

C/C++ - 字符输入输出和字符确认 C/C++ Table of contents 1. 2. getchar() putchar() 3. (Buffer) 4. 5. 6. 7. 8. 1 2 3 1 // pseudo code 2 read a character 3 while there is more input 4 increment character count 5 if a line has been read,

More information

PowerPoint Presentation

PowerPoint Presentation C++ 程序设计 第 7 章类 计算机学院黄章进 zhuang@ustc.edu.cn 内容 类 7.1 定义抽象数据类型 7.2 访问控制与封装 7.3 类的其他特性 7.4 类的作用域 7.5 构造函数再探 7.6 类的静态成员 2 定义抽象数据类型 C++ 中使用类 (class) 定义自己的数据类型 类的基本思想是数据抽象 (data abstraction) 和封装 (encapsulation)

More information

c_cpp

c_cpp C C++ C C++ C++ (object oriented) C C++.cpp C C++ C C++ : for (int i=0;i

More information

C++ 程式設計

C++ 程式設計 C C 料, 數, - 列 串 理 列 main 數串列 什 pointer) 數, 數, 數 數 省 不 不, 數 (1) 數, 不 數 * 料 * 數 int *int_ptr; char *ch_ptr; float *float_ptr; double *double_ptr; 數 (2) int i=3; int *ptr; ptr=&i; 1000 1012 ptr 數, 數 1004

More information

1 Framework.NET Framework Microsoft Windows.NET Framework.NET Framework NOTE.NET NET Framework.NET Framework 2.0 ( 3 ).NET Framework 2.0.NET F

1 Framework.NET Framework Microsoft Windows.NET Framework.NET Framework NOTE.NET NET Framework.NET Framework 2.0 ( 3 ).NET Framework 2.0.NET F 1 Framework.NET Framework Microsoft Windows.NET Framework.NET Framework NOTE.NET 2.0 2.0.NET Framework.NET Framework 2.0 ( 3).NET Framework 2.0.NET Framework ( System ) o o o o o o Boxing UnBoxing() o

More information

Microsoft Word - chap10.doc

Microsoft Word - chap10.doc 78 10. Inheritance in C++ 我 們 已 介 紹 了 物 件 導 向 程 式 的 第 一 個 主 要 特 性, 即 程 式 可 模 組 化 成 為 類 別 ( 物 件 ), 類 別 具 有 資 料 封 裝 的 特 性 接 下 來 我 們 要 介 紹 物 件 導 向 程 式 的 另 一 個 主 要 特 性, 那 就 是 類 別 具 有 繼 承 的 功 能 繼 承 就 是 重 複

More information

C/C++程序设计 - 字符串与格式化输入/输出

C/C++程序设计 - 字符串与格式化输入/输出 C/C++ / Table of contents 1. 2. 3. 4. 1 i # include # include // density of human body : 1. 04 e3 kg / m ^3 # define DENSITY 1. 04 e3 int main ( void ) { float weight, volume ; int

More information

Microsoft PowerPoint - 3. 函数Functionl.ppt [兼容模式]

Microsoft PowerPoint - 3. 函数Functionl.ppt [兼容模式] 函数 Function 如何重用代码 How to reuse code 3 4 = 3*3*3*3 3 4,6 5 : 拷贝 - 粘帖代码 (Copy-paste code) 3 4,6 5,12 10 : 拷贝 - 粘帖代码 (Copy-paste code) Bad! 使用函数 (with a function) 使用函数 (with a function) 使用函数 (with a function)

More information

Microsoft PowerPoint - ch6 [相容模式]

Microsoft PowerPoint - ch6 [相容模式] UiBinder wzyang@asia.edu.tw UiBinder Java GWT UiBinder XML UI i18n (widget) 1 2 UiBinder HelloWidget.ui.xml: UI HelloWidgetBinder HelloWidget.java XML UI Owner class ( Composite ) UI XML UiBinder: Owner

More information

FY.DOC

FY.DOC 高 职 高 专 21 世 纪 规 划 教 材 C++ 程 序 设 计 邓 振 杰 主 编 贾 振 华 孟 庆 敏 副 主 编 人 民 邮 电 出 版 社 内 容 提 要 本 书 系 统 地 介 绍 C++ 语 言 的 基 本 概 念 基 本 语 法 和 编 程 方 法, 深 入 浅 出 地 讲 述 C++ 语 言 面 向 对 象 的 重 要 特 征 : 类 和 对 象 抽 象 封 装 继 承 等 主

More information

OOP with Java 通知 Project 4: 5 月 2 日晚 9 点

OOP with Java 通知 Project 4: 5 月 2 日晚 9 点 OOP with Java Yuanbin Wu cs@ecnu OOP with Java 通知 Project 4: 5 月 2 日晚 9 点 复习 类的复用 组合 (composition): has-a 关系 class MyType { public int i; public double d; public char c; public void set(double x) { d =

More information

Microsoft PowerPoint - 5. 指针Pointers.ppt [兼容模式]

Microsoft PowerPoint - 5. 指针Pointers.ppt [兼容模式] 指针 Pointers 变量指针与指针变量 Pointer of a variable 变量与内存 (Variables and Memory) 当你声明一个变量时, 计算机将给该变量一个内存, 可以存储变量的值 当你使用变量时, 计算机将做两步操作 : - 根据变量名查找其对应的地址 ; - 通过地址对该地址的变量内容进行读 (retrieve) 或写 (set) 变量的地址称为变量的指针! C++

More information

程序设计语言及基础

程序设计语言及基础 Chapter 10 Classes: A Deeper Look, Part 2 http://jssec.seu.edu.cn 杨明 yangming2002@seu.edu.cn OBJECTIVES To specify const (constant) objects and const member functions. To create objects composed of other

More information

Fun Time (1) What happens in memory? 1 i n t i ; 2 s h o r t j ; 3 double k ; 4 char c = a ; 5 i = 3; j = 2; 6 k = i j ; H.-T. Lin (NTU CSIE) Referenc

Fun Time (1) What happens in memory? 1 i n t i ; 2 s h o r t j ; 3 double k ; 4 char c = a ; 5 i = 3; j = 2; 6 k = i j ; H.-T. Lin (NTU CSIE) Referenc References (Section 5.2) Hsuan-Tien Lin Deptartment of CSIE, NTU OOP Class, March 15-16, 2010 H.-T. Lin (NTU CSIE) References OOP 03/15-16/2010 0 / 22 Fun Time (1) What happens in memory? 1 i n t i ; 2

More information

C++ 程序设计 告别 OJ2 - 参考答案 MASTER 2019 年 5 月 3 日 1

C++ 程序设计 告别 OJ2 - 参考答案 MASTER 2019 年 5 月 3 日 1 C++ 程序设计 告别 OJ2 - 参考答案 MASTER 2019 年 5 月 3 日 1 1 TEMPLATE 1 Template 描述 使用模板函数求最大值 使用如下 main 函数对程序进行测试 int main() { double a, b; cin >> a >> b; cout c >> d; cout

More information

CHAPTER VC#

CHAPTER VC# 1. 2. 3. 4. CHAPTER 2-1 2-2 2-3 2-4 VC# 2-5 2-6 2-7 2-8 Visual C# 2008 2-1 Visual C# 0~100 (-32768~+32767) 2 4 VC# (Overflow) 2-1 2-2 2-1 2-1.1 2-1 1 10 10!(1 10) 2-3 Visual C# 2008 10! 32767 short( )

More information

北京大学

北京大学 1 string 类 郭炜刘家瑛 北京大学程序设计实习 string 类 string 类是一个模板类, 它的定义如下 : typedef basic_string string; 使用 string 类要包含头文件 string 对象的初始化 : string s1("hello"); // 一个参数的构造函数 string s2(8, x ); // 两个参数的构造函数

More information

untitled

untitled 1 Outline 數 料 數 數 列 亂數 練 數 數 數 來 數 數 來 數 料 利 料 來 數 A-Z a-z _ () 不 數 0-9 數 不 數 SCHOOL School school 數 讀 school_name schoolname 易 不 C# my name 7_eleven B&Q new C# (1) public protected private params override

More information

Microsoft PowerPoint - 第06讲_继承.ppt [兼容模式]

Microsoft PowerPoint - 第06讲_继承.ppt [兼容模式] 程序设计实习 (I): C++ 程序设计 第六讲继承 上节内容回顾 三种运算符重载的实现方式 重载为普通函数 重载为成员函数 重载为友元 常见的运算符重载 流运算符 (>>

More information

02

02 Thinking in C++: Volume One: Introduction to Standard C++, Second Edition & Volume Two: Practical Programming C++ C C++ C++ 3 3 C C class C++ C++ C++ C++ string vector 2.1 interpreter compiler 2.1.1 BASIC

More information

C/C++语言 - C/C++数据

C/C++语言 - C/C++数据 C/C++ C/C++ Table of contents 1. 2. 3. 4. char 5. 1 C = 5 (F 32). 9 F C 2 1 // fal2cel. c: Convert Fah temperature to Cel temperature 2 # include < stdio.h> 3 int main ( void ) 4 { 5 float fah, cel ;

More information

Microsoft PowerPoint - 07 派生数据类型

Microsoft PowerPoint - 07 派生数据类型 能源与动力工程学院 目录 派生类型 陈 斌 固有数据类型 数值型 (numerical) 整型 INTEGER 实型 REAL 复数型 COMPLEX 非数值型 字符型 CHARACTER 逻辑型 ( 布尔型 )LOGICAL 自定义数据类型 ( 派生类型, derived type) 派生类型是指用户利用 Fortran 系统内部类型, 如整型 实型 复数型 逻辑型 字符型等的组合自行创建出一个新的数据类型,

More information

Scott Effective C++ C++ C++ Roger Orr OR/2 ISO C++ Effective Modern C++ C++ C++ Scoot 42 Bart Vandewoestyne C++ C++ Scott Effective Modern C++ Damien

Scott Effective C++ C++ C++ Roger Orr OR/2 ISO C++ Effective Modern C++ C++ C++ Scoot 42 Bart Vandewoestyne C++ C++ Scott Effective Modern C++ Damien Effective Modern C++ C++ C++ C++11/C++14 C++ Scott Meyers Gerhard Kreuzer Siemens AG Effective Modern C++ Effective Modern C++ Andrei Alexandrescu Facebook Modern C++ Design C++ C++ Nevin Liber DRW Trading

More information

Microsoft PowerPoint - 10 模板 Template.pptx

Microsoft PowerPoint - 10 模板 Template.pptx 模板 Tempalte 泛型编程的需要 Why Templates? 设想你对整数类型实现了一个排序算法 : void sort(int *is,int n); 用该函数可以对实 复数或工资单排序吗? 模板可以复用源代码 - 泛型编程. inline void Swap( int &x, int &y){ int t = x; x = y; y =t; inline void Swap(double

More information

科学计算的语言-FORTRAN95

科学计算的语言-FORTRAN95 科 学 计 算 的 语 言 -FORTRAN95 目 录 第 一 篇 闲 话 第 1 章 目 的 是 计 算 第 2 章 FORTRAN95 如 何 描 述 计 算 第 3 章 FORTRAN 的 编 译 系 统 第 二 篇 计 算 的 叙 述 第 4 章 FORTRAN95 语 言 的 形 貌 第 5 章 准 备 数 据 第 6 章 构 造 数 据 第 7 章 声 明 数 据 第 8 章 构 造

More information

无类继承.key

无类继承.key 无类继承 JavaScript 面向对象的根基 周爱 民 / aimingoo aiming@gmail.com https://aimingoo.github.io https://github.com/aimingoo rand = new Person("Rand McKinnon",... https://docs.oracle.com/cd/e19957-01/816-6408-10/object.htm#1193255

More information

新・解きながら学ぶJava

新・解きながら学ぶJava 481! 41, 74!= 40, 270 " 4 % 23, 25 %% 121 %c 425 %d 121 %o 121 %x 121 & 199 && 48 ' 81, 425 ( ) 14, 17 ( ) 128 ( ) 183 * 23 */ 3, 390 ++ 79 ++ 80 += 93 + 22 + 23 + 279 + 14 + 124 + 7, 148, 16 -- 79 --

More information

OOP with Java 通知 Project 2 提交时间 : 3 月 14 日晚 9 点 另一名助教 : 王桢 学习使用文本编辑器 学习使用 cmd: Power shell 阅读参考资料

OOP with Java 通知 Project 2 提交时间 : 3 月 14 日晚 9 点 另一名助教 : 王桢   学习使用文本编辑器 学习使用 cmd: Power shell 阅读参考资料 OOP with Java Yuanbin Wu cs@ecnu OOP with Java 通知 Project 2 提交时间 : 3 月 14 日晚 9 点 另一名助教 : 王桢 Email: 51141201063@ecnu.cn 学习使用文本编辑器 学习使用 cmd: Power shell 阅读参考资料 OOP with Java Java 类型 引用 不可变类型 对象存储位置 作用域 OOP

More information

上海交通大学

上海交通大学 一 读程序, 写结果 ( 每题 4 分, 共 40 分 ) 1. 写出下列程序运行结果 class test friend test operator+(const test &p1, const test &p2) return test(p1.data1 + p2.data1, p1.data2 + p2.data2); friend ostream &operator

More information

ebook39-5

ebook39-5 5 3 last-in-first-out, LIFO 3-1 L i n e a r L i s t 3-8 C h a i n 3 3. 8. 3 C + + 5.1 [ ] s t a c k t o p b o t t o m 5-1a 5-1a E D 5-1b 5-1b E E 5-1a 5-1b 5-1c E t o p D t o p D C C B B B t o p A b o

More information

前言 C# C# C# C C# C# C# C# C# microservices C# More Effective C# More Effective C# C# C# C# Effective C# 50 C# C# 7 Effective vii

前言 C# C# C# C C# C# C# C# C# microservices C# More Effective C# More Effective C# C# C# C# Effective C# 50 C# C# 7 Effective vii 前言 C# C# C# C C# C# C# C# C# microservices C# More Effective C# More Effective C# C# C# C# Effective C# 50 C# C# 7 Effective vii C# 7 More Effective C# C# C# C# C# C# Common Language Runtime CLR just-in-time

More information

没有幻灯片标题

没有幻灯片标题 指针作为函数参数 : 原因 : 1 需要修改一个或多个值,( 用 return 语句不能解决问题 ) 2 执行效率的角度 使用方法 : 在函数原型以及函数首部中需要声明能够接受指针值的形参, 具体的写法为 : 数据类型 * 形参名 如果有多个指针型形参, 则用逗号分隔, 例如 : void swap(int *p1, int *p2) 它说明了形参 p1 p2 是指向整型变量的指针 在函数调用时,

More information

Chapter 9: Objects and Classes

Chapter 9: Objects and Classes Fortran Algol Pascal Modula-2 BCPL C Simula SmallTalk C++ Ada Java C# C Fortran 5.1 message A B 5.2 1 class Vehicle subclass Car object mycar public class Vehicle extends Object{ public int WheelNum

More information

PowerPoint Presentation

PowerPoint Presentation 第六章簡介運算子超載 (Operator Overloading) 6-1 運算子超載的基礎 6-2 超載二元運算子 6-3 超載邏輯與關係運算子 6-4 超載一元運算子 6-5 使用夥伴函數 6-6 細部檢視指定運算子 6-7 超載註標運算子 6-1 運算子超載的基礎 甚麼是運算子超載? 讓運算子 ( 符號 ) 有不同的意義 EX: 運算子的預設意義 ( 以 + 與 = 為例 ) class frac

More information

幻灯片 1

幻灯片 1 第三课类和对象 ( 封装 ) 互联网新技术在线教育领航者 1 内容概述 1. 封装的概念 2. 访问控制 3. 栈类的封装 4. 构造与析构 5.myString 构造函数 6. 构造与析构的次序 7. 类文件写法 8. 对象的内存 9.this 指针初探 10. 构造函数初始值列表 11. 拷贝构造和赋值运算符重载 12. 浅拷贝 13. 深拷贝 14. 成员函数内联 15. 友元 16.const

More information

Microsoft PowerPoint - L17_Inheritance_v4.pptx

Microsoft PowerPoint - L17_Inheritance_v4.pptx C++ Programming Lecture 17 Wei Liu ( 刘 威 ) Dept. of Electronics and Information Eng. Huazhong University of Science and Technology May. 2015 Lecture 17 Chapter 20. Object-Oriented Programming: Inheritance

More information

C 1

C 1 C homepage: xpzhangme 2018 5 30 C 1 C min(x, y) double C // min c # include # include double min ( double x, double y); int main ( int argc, char * argv []) { double x, y; if( argc!=

More information

EJB-Programming-3.PDF

EJB-Programming-3.PDF :, JBuilder EJB 2.x CMP EJB Relationships JBuilder EJB Test Client EJB EJB Seminar CMP Entity Beans Value Object Design Pattern J2EE Design Patterns Value Object Value Object Factory J2EE EJB Test Client

More information

C++ 程序设计 实验 1 - 参考答案 MASTER 2017 年 5 月 21 日 1

C++ 程序设计 实验 1 - 参考答案 MASTER 2017 年 5 月 21 日 1 C++ 程序设计 实验 1 - 参考答案 MASTER 2017 年 5 月 21 日 1 1 简单图形 1 简单图形 输入图形的行数 ( 如下图 7 行 ), 输出如下图所示图形 * *** ***** ******* ***** *** * 2 1 简单图形 1 #inc lude 2 using namespace std ; 3 4 // 注意变量命名的方式 5 //

More information

概述

概述 OPC Version 1.6 build 0910 KOSRDK Knight OPC Server Rapid Development Toolkits Knight Workgroup, eehoo Technology 2002-9 OPC 1...4 2 API...5 2.1...5 2.2...5 2.2.1 KOS_Init...5 2.2.2 KOS_InitB...5 2.2.3

More information

2013 C 1 # include <stdio.h> 2 int main ( void ) 3 { 4 int cases, a, b, i; 5 scanf ("%d", & cases ); 6 for (i = 0;i < cases ;i ++) 7 { 8 scanf ("%d %d

2013 C 1 # include <stdio.h> 2 int main ( void ) 3 { 4 int cases, a, b, i; 5 scanf (%d, & cases ); 6 for (i = 0;i < cases ;i ++) 7 { 8 scanf (%d %d 2013 18 ( ) 1. C pa.c, pb.c, 2. C++ pa.cpp, pb.cpp, Compilation Error cin scanf Time Limit Exceeded 1: A 5 B 5 C 5 D 5 E 5 F 5 1 2013 C 1 # include 2 int main ( void ) 3 { 4 int cases, a, b,

More information

OOP with Java 通知 Project 4: 5 月 2 日晚 9 点

OOP with Java 通知 Project 4: 5 月 2 日晚 9 点 OOP with Java Yuanbin Wu cs@ecnu OOP with Java 通知 Project 4: 5 月 2 日晚 9 点 复习 Java 包 创建包 : package 语句, 包结构与目录结构一致 使用包 : import restaurant/ - people/ - Cook.class - Waiter.class - tools/ - Fork.class - Table.class

More information

Microsoft PowerPoint - 01_Introduction.ppt

Microsoft PowerPoint - 01_Introduction.ppt Hello, World C 程序设计语言 第 1 章章观其大略 孙志岗 sun@hit.edu.cn http://sunner.cn prf("hello,, world\n"); 超级无敌考考你 : 如何把 hello 和 world 分别打印在两行? 2004-12-19 A Tutorial Introduction 2 hello.c 打印华氏温度与摄氏温度对照表 计算公式 : C=(5/9)(

More information

untitled

untitled 3 C++ 3.1 3.2 3.3 3.4 new delete 3.5 this 3.6 3.7 3.1 3.1 class struct union struct union C class C++ C++ 3.1 3.1 #include struct STRING { typedef char *CHARPTR; // CHARPTR s; // int strlen(

More information

Go构建日请求千亿微服务最佳实践的副本

Go构建日请求千亿微服务最佳实践的副本 Go 构建 请求千亿级微服务实践 项超 100+ 700 万 3000 亿 Goroutine & Channel Goroutine Channel Goroutine func gen() chan int { out := make(chan int) go func(){ for i:=0; i

More information

第3章.doc

第3章.doc 3 3 3 3.1 3 IT Trend C++ Java SAP Advantech ERPCRM C++ C++ Synopsys C++ NEC C C++PHP C++Java C++Java VIA C++ 3COM C++ SPSS C++ Sybase C++LinuxUNIX Motorola C++ IBM C++Java Oracle Java HP C++ C++ Yahoo

More information

Microsoft Word - 第3章.doc

Microsoft Word - 第3章.doc 第 3 章 lambda 表达式及其应用 lambda 表达式是 Java 8 提供的一种新特性, 它使得 Java 也能像 C# 和 C++ 语言一样进行简单的 函数式编程, 这不仅简化了某些通用结构的实现方式, 也大大增强了 Java 语言的表达功能 3.1 lambda 表达式简介 lambda 表达式是基于数学中的 λ 演算得名, 本质上就是一个没有方法名的匿名方法 例如, 有一个方法定义如下

More information

Computer Architecture

Computer Architecture ECE 3120 Computer Systems Assembly Programming Manjeera Jeedigunta http://blogs.cae.tntech.edu/msjeedigun21 Email: msjeedigun21@tntech.edu Tel: 931-372-6181, Prescott Hall 120 Prev: Basic computer concepts

More information

Microsoft Word - 第3章.doc

Microsoft Word - 第3章.doc Java C++ Pascal C# C# if if if for while do while foreach while do while C# 3.1.1 ; 3-1 ischeck Test() While ischeck while static bool ischeck = true; public static void Test() while (ischeck) ; ischeck

More information

untitled

untitled A, 3+A printf( ABCDEF ) 3+ printf( ABCDEF ) 2.1 C++ main main main) * ( ) ( ) [ ].* ->* ()[] [][] ** *& char (f)(int); ( ) (f) (f) f (int) f int char f char f(int) (f) char (*f)(int); (*f) (int) (

More information

Strings

Strings Polymorphism and Virtual Functions Cheng-Chin Chiang Virtual Function Basics 多 型 (Polymorphism) 賦 予 一 個 函 數 多 種 意 涵, 存 在 於 同 一 類 別 之 內 祖 先 類 別 與 後 代 類 別 間 物 件 導 向 程 式 設 計 基 本 原 理 虛 擬 函 數 (Virtual Function)

More information

Microsoft PowerPoint - Lecture7II.ppt

Microsoft PowerPoint - Lecture7II.ppt Lecture 8II SUDOKU PUZZLE SUDOKU New Play Check 軟體實作與計算實驗 1 4x4 Sudoku row column 3 2 } 4 } block 1 4 軟體實作與計算實驗 2 Sudoku Puzzle Numbers in the puzzle belong {1,2,3,4} Constraints Each column must contain

More information

OOP with Java 通知 Project 3 提交时间 3 月 29 日晚 9 点 Piazza Project 2 投票

OOP with Java 通知 Project 3 提交时间 3 月 29 日晚 9 点 Piazza Project 2 投票 OOP with Java Yuanbin Wu cs@ecnu OOP with Java 通知 Project 3 提交时间 3 月 29 日晚 9 点 Piazza Project 2 投票 复习 创建对象 构造函数 函数重载 : 函数 = 函数名 + 参数列表 public class MyType { int i; double d; char c; void set(double x)

More information

AN INTRODUCTION TO PHYSICAL COMPUTING USING ARDUINO, GRASSHOPPER, AND FIREFLY (CHINESE EDITION ) INTERACTIVE PROTOTYPING

AN INTRODUCTION TO PHYSICAL COMPUTING USING ARDUINO, GRASSHOPPER, AND FIREFLY (CHINESE EDITION ) INTERACTIVE PROTOTYPING AN INTRODUCTION TO PHYSICAL COMPUTING USING ARDUINO, GRASSHOPPER, AND FIREFLY (CHINESE EDITION ) INTERACTIVE PROTOTYPING 前言 - Andrew Payne 目录 1 2 Firefly Basics 3 COMPONENT TOOLBOX 目录 4 RESOURCES 致谢

More information

extend

extend (object oriented) Encapsulation Inheritance Polymorphism Dynamic Binding (base class) (derived class) 1 class Base { int I; void X(); void Y(); class Derived: public Base { private: int j; void z(); Derived

More information

WWW PHP

WWW PHP WWW PHP 2003 1 2 function function_name (parameter 1, parameter 2, parameter n ) statement list function_name sin, Sin, SIN parameter 1, parameter 2, parameter n 0 1 1 PHP HTML 3 function strcat ($left,

More information

NOWOER.OM m/n m/=n m/n m%=n m%n m%=n m%n m/=n 4. enum string x1, x2, x3=10, x4, x5, x; 函数外部问 x 等于什么? 随机值 5. unsigned char *p1; unsigned long *p

NOWOER.OM m/n m/=n m/n m%=n m%n m%=n m%n m/=n 4. enum string x1, x2, x3=10, x4, x5, x; 函数外部问 x 等于什么? 随机值 5. unsigned char *p1; unsigned long *p NOWOER.OM /++ 程师能 评估. 单项选择题 1. 下 描述正确的是 int *p1 = new int[10]; int *p2 = new int[10](); p1 和 p2 申请的空间 的值都是随机值 p1 和 p2 申请的空间 的值都已经初始化 p1 申请的空间 的值是随机值,p2 申请的空间 的值已经初始化 p1 申请的空间 的值已经初始化,p2 申请的空间 的值是随机值 2.

More information

CHAPTER 1

CHAPTER 1 CHAPTER 1 1-1 System Development Life Cycle; SDLC SDLC Waterfall Model Shelly 1995 1. Preliminary Investigation 2. System Analysis 3. System Design 4. System Development 5. System Implementation and Evaluation

More information

Microsoft Word - 物件導向編程精要.doc

Microsoft Word - 物件導向編程精要.doc Essential Object-Oriented Programming Josh Ko 2007.03.11 object-oriented programming C++ Java OO class object OOP Ruby duck typing complexity abstraction paradigm objects objects model object-oriented

More information

Guava学习之Resources

Guava学习之Resources Resources 提供提供操作 classpath 路径下所有资源的方法 除非另有说明, 否则类中所有方法的参数都不能为 null 虽然有些方法的参数是 URL 类型的, 但是这些方法实现通常不是以 HTTP 完成的 ; 同时这些资源也非 classpath 路径下的 下面两个函数都是根据资源的名称得到其绝对路径, 从函数里面可以看出,Resources 类中的 getresource 函数都是基于

More information

Microsoft Word - 970617cppFinalSolution.doc

Microsoft Word - 970617cppFinalSolution.doc 國 立 台 灣 海 洋 大 學 資 訊 工 程 系 C++ 程 式 設 計 期 末 考 參 考 答 案 姓 名 : 系 級 : 學 號 : 97/06/17 考 試 時 間 :10:00 12:10 試 題 敘 述 蠻 多 的, 看 清 楚 題 目 問 什 麼, 針 對 重 點 回 答 是 很 重 要 的 ; 不 確 定 的 請 一 定 要 當 場 提 出 來, 不 要 白 花 力 氣 在 誤 會

More information

untitled

untitled 不 料 料 例 : ( 料 ) 串 度 8 年 數 串 度 4 串 度 數 數 9- ( ) 利 數 struct { ; ; 數 struct 數 ; 9-2 數 利 數 C struct 數 ; C++ 數 ; struct 省略 9-3 例 ( 料 例 ) struct people{ char name[]; int age; char address[4]; char phone[]; int

More information

Microsoft PowerPoint - Model Checking a Lazy Concurrent List-Based Set Algorithm.ppt [Compatibility Mode]

Microsoft PowerPoint - Model Checking a Lazy Concurrent List-Based Set Algorithm.ppt [Compatibility Mode] Model Checking a Lazy Concurrent List-Based Set Algorithm ZHANG Shaojie, LIU Yang National University of Singapore Agenda Introduction Background Ourapproach Overview Linearizabilitydefinition Modelinglanguage

More information

C 1 # include <stdio.h> 2 int main ( void ) { 4 int cases, i; 5 long long a, b; 6 scanf ("%d", & cases ); 7 for (i = 0;i < cases ;i ++) 8 { 9

C 1 # include <stdio.h> 2 int main ( void ) { 4 int cases, i; 5 long long a, b; 6 scanf (%d, & cases ); 7 for (i = 0;i < cases ;i ++) 8 { 9 201 201 21 ( ) 1. C pa.c, pb.c, 2. C++ pa.cpp, pb.cpp Compilation Error long long cin scanf Time Limit Exceeded 1: A 1 B 1 C 5 D RPG 10 E 10 F 1 G II 1 1 201 201 C 1 # include 2 int main ( void

More information

基于ECO的UML模型驱动的数据库应用开发1.doc

基于ECO的UML模型驱动的数据库应用开发1.doc ECO UML () Object RDBMS Mapping.Net Framework Java C# RAD DataSetOleDbConnection DataGrod RAD Client/Server RAD RAD DataReader["Spell"].ToString() AObj.XXX bug sql UML OR Mapping RAD Lazy load round trip

More information

3.1 num = 3 ch = 'C' 2

3.1 num = 3 ch = 'C' 2 Java 1 3.1 num = 3 ch = 'C' 2 final 3.1 final : final final double PI=3.1415926; 3 3.2 4 int 3.2 (long int) (int) (short int) (byte) short sum; // sum 5 3.2 Java int long num=32967359818l; C:\java\app3_2.java:6:

More information

Microsoft Word - 01.DOC

Microsoft Word - 01.DOC 第 1 章 JavaScript 简 介 JavaScript 是 NetScape 公 司 为 Navigator 浏 览 器 开 发 的, 是 写 在 HTML 文 件 中 的 一 种 脚 本 语 言, 能 实 现 网 页 内 容 的 交 互 显 示 当 用 户 在 客 户 端 显 示 该 网 页 时, 浏 览 器 就 会 执 行 JavaScript 程 序, 用 户 通 过 交 互 式 的

More information

C++ 程序设计 OJ2 - 参考答案 MASTER 2019 年 5 月 3 日 1

C++ 程序设计 OJ2 - 参考答案 MASTER 2019 年 5 月 3 日 1 C++ 程序设计 OJ2 - 参考答案 MASTER 2019 年 5 月 3 日 1 1 PERSON 1 Person 题目描述 编写程序, 定义一个基类 Person, 包含 name 和 age 两个数据成员 ; 再由它派生出学生类 Student 和教师类 Teacher, 其中学生类添加学号 no 数据, 教师类添加职称 title 数据 ; 要求每个类均有构造函数 析构函数和显示数据的函数

More information

OOP with Java 通知 : Project 2 提交时间 : 3 月 15 日晚 9 点

OOP with Java 通知 : Project 2 提交时间 : 3 月 15 日晚 9 点 OOP with Java Yuanbin Wu cs@ecnu OOP with Java 通知 : Project 2 提交时间 : 3 月 15 日晚 9 点 复习 : Java 类型 基本类型 boolean, char, 封装 (wrappers) 类 (class) 定义 class MyType { int i; double d; 数据 (Fields) char c; void set(double

More information

Microsoft Word - Learn Objective-C.doc

Microsoft Word - Learn Objective-C.doc Learn Objective C http://cocoadevcentral.com/d/learn_objectivec/ Objective C Objective C Mac C Objective CC C Scott Stevenson [object method]; [object methodwithinput:input]; output = [object methodwithoutput];

More information

OOP with Java 通知 : Project 2 提交时间 : 3 月 14 日晚 9 点 另一名助教 : 王桢

OOP with Java 通知 : Project 2 提交时间 : 3 月 14 日晚 9 点 另一名助教 : 王桢 OOP with Java Yuanbin Wu cs@ecnu OOP with Java 通知 : Project 2 提交时间 : 3 月 14 日晚 9 点 另一名助教 : 王桢 Email: 51141201063@ecnu.cn 复习 : Java 类型 基本类型 boolean, char, 封装 (wrappers) 类 (class) 定义 class MyType { int i;

More information

W. Richard Stevens UNIX Sockets API echo Sockets TCP OOB IO C struct C/C++ UNIX fork() select(2)/poll(2)/epoll(4) IO IO CPU 100% libevent UNIX CPU IO

W. Richard Stevens UNIX Sockets API echo Sockets TCP OOB IO C struct C/C++ UNIX fork() select(2)/poll(2)/epoll(4) IO IO CPU 100% libevent UNIX CPU IO Linux muduo C++ (giantchen@gmail.com) 2012-09-30 C++ TCP C++ x86-64 Linux TCP one loop per thread Linux native muduo C++ IT 5 C++ muduo 2 C++ C++ Primer 4 W. Richard Stevens UNIX Sockets API echo Sockets

More information

Microsoft PowerPoint - CPP-Ch Print.ppt [兼容模式]

Microsoft PowerPoint - CPP-Ch Print.ppt [兼容模式] Chapter 17 File Processing http://jssec.seu.edu.cn 杨明 yangming2002@seu.edu.cn OBJECTIVES To create, read, write and update files. Sequential file processing. Random-access file processing. To use high-performance

More information

树木(一)

树木(一) ISBN 7-80173-166-2/ S 01 698.00 I..................................................................... ...... 177...................................................... II 177

More information

untitled

untitled ISBN L-0000-00785/ II246.4 : 15 00 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59

More information

untitled

untitled ISBN L-0000-00714/ II242.43 : 15 00 5 6 12 16 21 26 31 36 41 1 47 52 58 63 69 75 80 86 91 96 100 105 110 2 115 120 125 130 134 138 142 146 150 155 159 164 3 168 172 177 181 186 190 193 197 202 207 212

More information