C++ 程序设计 OJ10 - 参考答案 MASTER 2019 年 6 月 17 日 1

Size: px
Start display at page:

Download "C++ 程序设计 OJ10 - 参考答案 MASTER 2019 年 6 月 17 日 1"

Transcription

1 C++ 程序设计 OJ10 - 参考答案 MASTER 2019 年 6 月 17 日 1

2 1 STRINGREVERSE 1 StringReverse 题目描述 利用 string 类对字符串进行 ( 按反转后字典序 ) 排序并输出, 例如两个字符串为 aab, cba, 则 cba 应该排在 aab 之前, 因为 cba 反转后为 abc, aab 反转后为 baa. 输入 第一行为一个整数 N, 表示字符串的数目 (0<N<50) 接下来是 N 行, 每行一个字符串, 其中字符串仅由小写字母组成, 每个字符串长度不超过 100, 所有字符串均不相同 输出 排完序以后的字符串, 每个字符串占一行 样例输入 6 cpp class object stl acm bjfu 样例输出 stl acm cpp class object bjfu 代码模板 提示 可用 reverse 函数实现反转, 具体用法请上网自己查 2

3 1 STRINGREVERSE 1 #i n c l u d e <iostream> 2 #i n c l u d e <s t r i n g > 3 #i n c l u d e <vector> 4 #i n c l u d e <algorithm> 5 using namespace std ; 6 7 i n t main ( ) 8 { 9 i n t n ; 10 while ( cin >> n) 11 { 12 vector<s t r i n g > s t r s (n) ; 13 f o r ( auto i = 0 ; i < n ; ++i ) 14 { 15 cin >> s t r s [ i ] ; 16 } 17 f o r ( auto i = 0 ; i < n ; i++) 18 { 19 r e v e r s e ( s t r s [ i ]. begin ( ), s t r s [ i ]. end ( ) ) ; 20 } 21 s o r t ( s t r s. begin ( ), s t r s. end ( ) ) ; 22 f o r ( auto i = 0 ; i < n ; i++) 23 { 24 r e v e r s e ( s t r s [ i ]. begin ( ), s t r s [ i ]. end ( ) ) ; 25 cout << s t r s [ i ] << endl ; 26 } 27 } 28 return 0 ; 29 } 3

4 2 RAILWAY 2 Railway 题目描述 某城市有一个火车站, 铁轨铺设如图所示 有 n 节车厢从 A 方向驶入车站, 按进站顺序编号为 1~n. 你的任务是让它们按照某种特定的顺序进入 B 方向的铁轨并驶出车站 为了重组车厢, 你可以借助中转站 C 这是一个可以停放任意多节车厢的车站, 但由于末端封顶, 驶入 C 的车厢必须按照相反的顺序驶出 C 对于每个车厢, 一旦从 A 移入 C, 就不能再回到 A 了 ; 一旦从 C 移入 B, 就不能回到 C 了 换句话说, 在任一时刻, 只有两种选择 :A->C 和 C->B 输入 输入包含多组测试数据, 每组数据的第一行是一个正整数 n(1<n<1000), 第二行是 1~n 这 n 个整数的一个全排列 输出 对于每一组测试数据, 如果能按要求完成车厢重组, 请输出 Yes, 否则输出 No, 每组输出占一行 样例输入 样例输出 Yes No Yes 提示 可以使用 stack 实现 4

5 2 RAILWAY 1 #i n c l u d e <iostream> 2 #i n c l u d e <stack> 3 #i n c l u d e <vector> 4 using namespace std ; 5 6 i n t main ( ) 7 { 8 i n t n ; 9 while ( cin >> n) 10 { 11 stack<int > c ; 12 vector<int > a, b ; 13 i n t temp ; 14 f o r ( i n t i = 0 ; i < n ; ++i ) 15 { 16 cin >> temp ; 17 b. push_back (temp) ; 18 a. push_back ( i + 1) ; 19 } 20 i n t i = 0, j = 0 ; 21 while ( i!= n) 22 { 23 c. push ( a [ i ++]) ; 24 while (! c. empty ( ) && c. top ( ) == b [ j ] ) 25 { 26 c. pop ( ) ; 27 j++; 28 } } 31 i f ( c. empty ( ) ) 32 cout << " Yes" << endl ; 33 e l s e 34 cout << "No" << endl ; 35 } 36 return 0 ; 37 } 5

6 3 FILE 3 File 题目描述 编写程序, 打开一个英文的文本文件, 在其中每一行的前面加上行号和一个空格符 将你的代码填在下面的注释处 ``` void FileTest() { // 此处写处理文件的代码 return; } int main() { FileTest(); cout << "Hello C++" << endl; return 0; } ``` 输入 null 输出 Hello C++ 样例输入 null 样例输出 Hello C++ 提示 6

7 3 FILE 1 #i n c l u d e <iostream> 2 #i n c l u d e <fstream> 3 #i n c l u d e <s t r i n g > 4 using namespace std ; 5 6 void FileTest ( ) 7 { 8 // 此处写处理文件的代码 9 i f s t r e a m i n f i l e ; 10 i n f i l e. open ( "in.txt" ) ; 11 i f (! i n f i l e. is_open ( ) ) return ; ofstream o u t f i l e ; 14 o u t f i l e. open ( "out.txt" ) ; 15 i f ( o u t f i l e. f a i l ( ) ) return ; i n t count = 0 ; 18 s t r i n g l i n e ; // 定义字符串 g e t l i n e ( i n f i l e, l i n e ) ; 21 count++; 22 while (! i n f i l e. e o f ( ) ) 23 { 24 o u t f i l e << count << " " << l i n e << endl ; 25 g e t l i n e ( i n f i l e, l i n e ) ; 26 count++; 27 } i n f i l e. c l o s e ( ) ; 30 o u t f i l e. c l o s e ( ) ; 31 return ; 32 } 33 i n t main ( ) 34 { 35 FileTest ( ) ; 36 cout << " Hello C++" << endl ; 37 return 0 ; 38 } 7

8 4 SWAP 4 Swap 题目描述 用函数模板的方式实现对不同数据类型的数组中的数据进行输入 从小到大排序和输出 使用如下主函数测试你的模板设计一个函数模板 Swap, 实现任意数据类型的两个数据的交换, 分别用 int 型 double 型和 char 型的数据进行测试 main 函数如下 : int main() { int a1, a2; cin >> a1 >> a2; Swap(a1, a2); cout << a1 << "," << a2 << endl; double b1, b2; cin >> b1 >> b2; Swap(b1, b2); cout << b1 << "," << b2 << endl; char c1, c2; cin >> c1 >> c2; Swap(c1, c2); cout << c1 << "," << c2 << endl; } return 0; 输入 输入有三行, 第一行两个整数, 第二行两个浮点数, 第三行两个字符 输出 输出三组输入交换之后的结果, 每组用逗号隔开 样例输入 a b 样例输出 3,2 2.3,1.2 b,a 8

9 4 SWAP 1 #i n c l u d e <iostream> 2 using namespace std ; template <c l a s s T> 6 void Swap(T &a, T &b) 7 { 8 T temp = a ; 9 a = b ; 10 b = temp ; 11 } i n t main ( ) 15 { 16 i n t a1, a2 ; 17 cin >> a1 >> a2 ; 18 Swap( a1, a2 ) ; 19 cout << a1 << "," << a2 << endl ; double b1, b2 ; 22 cin >> b1 >> b2 ; 23 Swap( b1, b2 ) ; 24 cout << b1 << "," << b2 << endl ; char c1, c2 ; 27 cin >> c1 >> c2 ; 28 Swap( c1, c2 ) ; 29 cout << c1 << "," << c2 << endl ; return 0 ; 32 } 9

10 5 LISTCLASSTEMPLATE 5 ListClassTemplate 题目描述 设计一个单向链表的类模板, 类模板的说明如下 : template <class T> class List{ private: T data; List * next; static List * tail; // 指向最后一个结点 static List * head; // 指向头结点 public: List():next(NULL) // 构造头结点 { head = tail = this; } List(T newnode):data(newnode),next(null) // 构造新结点 {} void Append(T node); // 往后面添加结点 bool Insert(T node, T posnode); // 在结点 posnode 第一次出现的后面插入新结点, 插入成功返回 true, 否则 false void DeleteNode(T node); // 删除结点, 注意可能有多个相同的结点需要删除 void DeleteList(); // 删除整个链表 void DisplayList(); // 显示链表 }; 你的任务是实现这个类模板中的成员函数, 然后使用如下所示的 main() 函数测试你实现的类模板 int main() { List<int> list1; list1.append(1); list1.deletenode(1); list1.append(2); list1.append(3); list1.append(4); list1.insert(10,2); list1.append(5); list1.append(3); list1.append(3); list1.displaylist(); list1.deletenode(3); list1.displaylist(); list1.deletelist(); list1.displaylist(); List<char> list2; list2.append('a'); list2.append('b'); list2.append('c'); list2.append('d'); list2.insert('e','b'); list2.insert('f','d'); list2.append('g'); list2.append('g'); list2.append('g'); list2.displaylist(); list2.deletenode('g'); list2.displaylist(); list2.deletelist(); list2.displaylist(); } 输入 return 0; 10

11 5 LISTCLASSTEMPLATE 1 #i n c l u d e <iostream> 2 using namespace std ; 3 4 template <c l a s s T> 5 c l a s s L i s t { 6 p r i v a t e : 7 T data ; 8 L i s t * next ; 9 s t a t i c L i s t * t a i l ; // 指向最后一个结点 10 s t a t i c L i s t * head ; // 指向头结点 11 public : 12 L i s t ( ) : next (NULL) // 构造头结点 13 { 14 head = t a i l = t h i s ; 15 } 16 L i s t (T newnode ) : data ( newnode ), next (NULL) // 构造新结点 17 {} 18 void Append(T node ) ; // 往后面添加结点 19 bool I n s e r t (T node, T posnode ) ; // 在结点 posnode 第一次出现的后面插入新结点, 插 入成功返回 true, 否则 f a l s e 20 void DeleteNode (T node ) ; // 删除结点, 注意可能有多个相同的结点需要删除 21 void D e l e t e L i s t ( ) ; // 删除整个链表 22 void DisplayList ( ) ; // 显示链表 23 } ; template <c l a s s T> 26 List<T> * List<T>:: t a i l ; 27 template <c l a s s T> 28 List<T> * List<T>:: head ; template <c l a s s T> 31 void List <T>:: Append(T node ) 32 { 33 t a i l >next = new L i s t ( node ) ; 34 t a i l = t a i l >next ; 35 } template <c l a s s T> 38 bool List<T>:: I n s e r t (T node, T posnode ) 39 { 40 f o r ( L i s t * f i n d = head >next ; f i n d!= NULL; f i n d = find >next ) 41 i f ( find >data == posnode ) // 找到了插入的位置 42 { 43 L i s t * temp = new L i s t ( node ) ; 44 i f ( find >next == NULL) // posnode 是最后一个结点, 此时需要修改 t a i l 45 { 46 temp >next = NULL; 47 find >next = t a i l = temp ; 48 return true ; 11

12 5 LISTCLASSTEMPLATE 49 } e l s e { // 不是最后一个结点, 只是中间结点, 不需 要修改 t a i l 50 temp >next = find >next ; 51 find >next = temp ; 52 return true ; 53 } 54 } 55 return f a l s e ; 56 } template <c l a s s T> 59 void List <T>:: DeleteNode (T node ) 60 { 61 L i s t * f i n d = head >next, * pre = head ; 62 while ( f i n d!= NULL) 63 { 64 i f ( find >data == node ) 65 { 66 i f ( find >next == NULL) // 要删除的是最后一个结点, 需要修改 t a i l 67 { 68 pre >next = NULL; 69 t a i l = pre ; 70 d e l e t e f i n d ; 71 f i n d = NULL; 72 } e l s e { // 要删除的不是最后一个结点 73 pre >next = find >next ; 74 d e l e t e f i n d ; 75 f i n d = pre >next ; 76 } 77 } e l s e { // 不是需要删除的结点 78 pre = f i n d ; 79 f i n d = find >next ; 80 } 81 } 82 } template <c l a s s T> 85 void List<T>:: D e l e t e L i s t ( ) 86 { 87 L i s t * current = head >next ; 88 L i s t * temp ; 89 while ( current!= NULL) 90 { 91 temp = current ; 92 head >next = current >next ; 93 current = current >next ; 94 d e l e t e temp ; 95 } 96 t a i l = head ; 12

13 5 LISTCLASSTEMPLATE 97 head >next = NULL; 98 } template <c l a s s T> 101 void List<T>:: DisplayList ( ) 102 { 103 f o r ( L i s t * temp = head >next ; temp!= NULL; temp = temp >next ) 104 cout<<temp >data<<" " ; 105 cout<<endl ; 106 } i n t main ( ) 109 { 110 List<int> l i s t 1 ; 111 l i s t 1. Append (1) ; 112 l i s t 1. DeleteNode (1) ; 113 l i s t 1. Append (2) ; 114 l i s t 1. Append (3) ; 115 l i s t 1. Append (4) ; 116 l i s t 1. I n s e r t (10,2) ; 117 l i s t 1. Append (5) ; 118 l i s t 1. Append (3) ; 119 l i s t 1. Append (3) ; 120 l i s t 1. DisplayList ( ) ; 121 l i s t 1. DeleteNode (3) ; 122 l i s t 1. DisplayList ( ) ; 123 l i s t 1. D e l e t e L i s t ( ) ; 124 l i s t 1. DisplayList ( ) ; List<char> l i s t 2 ; 127 l i s t 2. Append( 'A') ; 128 l i s t 2. Append( 'B') ; 129 l i s t 2. Append( 'C') ; 130 l i s t 2. Append( 'D') ; 131 l i s t 2. I n s e r t ( 'E', 'B') ; 132 l i s t 2. I n s e r t ( 'F', 'D') ; 133 l i s t 2. Append( 'G') ; 134 l i s t 2. Append( 'G') ; 135 l i s t 2. Append( 'G') ; 136 l i s t 2. DisplayList ( ) ; 137 l i s t 2. DeleteNode ( 'G') ; 138 l i s t 2. DisplayList ( ) ; 139 l i s t 2. D e l e t e L i s t ( ) ; 140 l i s t 2. DisplayList ( ) ; return 0 ; 143 } 13

14 6 MYQUEUE 6 MyQueue 题目描述 设计一个 MyQueue 类模板, 类模板说明如下 : template <class Type> class MyQueue; template <class Type> std::ostream & operator<<(std::ostream &, const MyQueue<Type> &); template <class Type> class QueueItem { // private class: no public section friend class MyQueue<Type>;// 友元类 QueueItem(const Type &t) :item(t), next(0) {} // 构造函数,next 指针为空指针, 将 t 的值赋给 item Type item; //value stored in this element QueueItem *next; // pointer to next element in the MyQueue // 通过友元函数重载 << 运算符模板函数, 要写上 << 后的 <Type> friend std::ostream & operator<< <Type> (std::ostream &, const MyQueue<Type> &); }; template <class Type> class MyQueue { public: MyQueue() : head(0), tail(0) {} // Empty MyQueue MyQueue(const MyQueue &Q) :head(0), tail(0) { CopyElements(Q); };// 拷贝构造函数 MyQueue & operator=(const MyQueue &);// 重载 = 运算符 ~MyQueue() { Destroy(); } // return element from head of MyQueue Type & Front() { return head->item; } const Type & Front() const { return head->item; } void Push(const Type &); //add element to back of MyQueue void Pop(); // remove element from head of MyQueue bool Empty() const { return head == 0; } void Display() const; private: QueueItem<Type> *head; QueueItem<Type> *tail; void Destroy(); //delete all the elements void CopyElements(const MyQueue &); friend std::ostream & operator<< <Type> (std::ostream &, const MyQueue<Type> &); }; 实现这个类模板中的成员函数, 然后使用如下所示的 main() 函数测试这一类模板 int main() { MyQueue<int> qi; qi.push(1); qi.push(2); qi.push(3); qi.push(4); qi.push(5); qi.pop(); qi.display(); cout<<"\n"; cout<<qi; cout<<endl; MyQueue<int> qi2(qi); qi2.display(); cout<<endl; MyQueue<int> qi3; qi3 = qi; cout<<qi3; 14

15 6 MYQUEUE 1 #i n c l u d e <iostream> 2 using namespace std ; 3 4 template <c l a s s Type> c l a s s MyQueue ; 5 template <c l a s s Type> 6 std : : ostream & operator <<(std : : ostream &, const MyQueue<Type> &) ; 7 template <c l a s s Type> c l a s s QueueItem { 8 // p r i v a t e c l a s s : no p u b l i c s e c t i o n 9 f r i e n d c l a s s MyQueue<Type>;// 友元类 10 QueueItem ( const Type &t ) : item ( t ), next (0) {} // 构造函数, next 指针为空指针, 将 t 的值赋给 item 11 Type item ; // value s t o r e d in t h i s element 12 QueueItem * next ; // p o i n t e r to next element in the MyQueue // 通过友元函数重载 << 运算符模板函数, 要写上 << 后的 <Type> 15 f r i e n d std : : ostream & operator<< <Type> ( std : : ostream &, const MyQueue<Type> &) ; 16 } ; template <c l a s s Type> c l a s s MyQueue { 19 public : 20 MyQueue( ) : head (0), t a i l (0) {} // Empty MyQueue 21 MyQueue( const MyQueue &Q) : head (0), t a i l (0) { CopyElements (Q) ; } ; // 拷贝构造函数 22 MyQueue & operator=(const MyQueue &) ; // 重载 = 运算符 23 ~MyQueue( ) { Destroy ( ) ; } 24 // return element from head of MyQueue 25 Type & Front ( ) { return head >item ; } 26 const Type & Front ( ) const { r e t u r n head >item ; } 27 void Push ( const Type &) ; // add element to back o f MyQueue 28 void Pop ( ) ; // remove element from head o f MyQueue 29 bool Empty( ) const { return head == 0 ; } 30 void Display ( ) const ; 31 p r i v a t e : 32 QueueItem<Type> * head ; 33 QueueItem<Type> * t a i l ; 34 void Destroy ( ) ; // d e l e t e a l l the elements 35 void CopyElements ( const MyQueue &) ; f r i e n d std : : ostream & operator<< <Type> ( std : : ostream &, const MyQueue<Type> &) ; 38 } ; template<c l a s s Type> void MyQueue<Type >:: Destroy ( ) { 42 while (! Empty() ) 43 Pop ( ) ; 44 } template<c l a s s Type> void MyQueue<Type >::Pop ( ) { 47 QueueItem<Type> * p = head ; 48 head = head >next ; 15

16 6 MYQUEUE 49 d e l e t e p ; 50 } template<c l a s s Type> void MyQueue<Type >:: Push ( const Type & val ) { 53 QueueItem<Type> * pt = new QueueItem<Type>( v a l ) ; 54 i f (Empty() ) 55 head = t a i l = pt ; 56 e l s e { 57 t a i l >next = pt ; 58 t a i l = pt ; 59 } 60 } template<c l a s s Type> void MyQueue<Type >:: CopyElements ( const MyQueue<Type> &o r i g ) { 63 f o r ( QueueItem<Type> * pt = o r i g. head ; pt ; pt = pt >next ) 64 Push ( pt >item ) ; 65 } template<c l a s s Type> MyQueue<Type> & MyQueue<Type >:: operator=(const MyQueue<Type> & o r i g ) { 68 f o r ( QueueItem<Type> * pt = o r i g. head ; pt ; pt = pt >next ) 69 Push ( pt >item ) ; 70 return * t h i s ; 71 } template<c l a s s Type> void MyQueue<Type >:: Display ( ) const { 74 f o r ( QueueItem<Type> * pt = head ; pt ; pt = pt >next ) 75 cout<<pt >item<<" " ; 76 } template<c l a s s Type> ostream & operator <<(ostream & os, const MyQueue<Type> & q ) { 79 os<<"< " ; 80 QueueItem<Type> * p ; 81 f o r (p = q. head ; p ; p = p >next ) 82 os<<p >item<<" " ; 83 os<<">" ; 84 return os ; 85 } i n t main ( ) 88 { 89 MyQueue<int > q i ; 90 qi. Push (1) ; 91 qi. Push (2) ; 92 qi. Push (3) ; 93 qi. Push (4) ; 94 qi. Push (5) ; 95 qi. Pop ( ) ; 96 qi. Display ( ) ; 16

17 6 MYQUEUE 97 cout<<"\n" ; 98 cout<<q i ; 99 cout<<endl ; MyQueue<int> qi2 ( qi ) ; 102 qi2. Display ( ) ; 103 cout<<endl ; MyQueue<int> qi3 ; 106 qi3 = qi ; 107 cout<<qi3 ; return 0 ; 110 } 17

18 7 SEARCH 7 Search 题目描述 设计一个函数模板, 实现在一个给定的数组中查找给定的元素的值是否存在, 如果存在则输出该元素在数组中最小的下标, 如果不存在, 输出 -1 int main() { int n, d; cin >> n >> d; int *nvalues = new int[n]; for (int i = 0; i < n; i++) { cin >> nvalues[i]; } cout << Search(nValues, n, d) << endl; delete[] nvalues; double f; cin >> n >> f; double *dvalues = new double[n]; for (int i = 0; i < n; i++) { cin >> dvalues[i]; } cout << Search(dValues, n, f) << endl; delete[] dvalues; } char c; cin >> n >> c; char *cvalues = new char[n]; for (int i = 0; i < n; i++) { cin >> cvalues[i]; } cout << Search(cValues, n, c) << endl; delete[] cvalues; return 0; 输入 输入共三组数据, 每组数据占两行 第一组数据的第一行为一个整数 n1 和 d, 第二行是 n1 个整数 第二组数据的第一行为一个整数 n2 和一个浮点数 f, 第二行是 n2 个浮点数 第三组数据的第一行为一个整数 n3 和一个字符 c, 第二行是 n3 个字符 输出 对于每一组输入, 如果给定元素 ( 上述示例中分别为 d,f,c) 存在, 则输出其最小下标 ( 下标从 0 开始计 ), 否则输出 -1 样例输入 j B J F U 样例输出 提示 使用模板函数 template <class T> int Search(const T * array, int arraylen, 18 const T &value)

19 7 SEARCH 1 #i n c l u d e <iostream> 2 using namespace std ; 3 4 template <c l a s s T> 5 i n t Search ( const T * array, i n t arraylen, const T &value ) 6 { 7 f o r ( i n t i =0; i<arraylen ; i++) 8 i f ( array [ i ] == value ) 9 return i ; 10 return 1; 11 } i n t main ( ) 14 { 15 i n t n, d ; 16 cin >> n >> d ; 17 i n t *nvalues = new i n t [ n ] ; 18 f o r ( i n t i = 0 ; i < n ; i++) { 19 cin >> nvalues [ i ] ; 20 } 21 cout << Search ( nvalues, n, d) << endl ; 22 d e l e t e [ ] nvalues ; double f ; 25 cin >> n >> f ; 26 double * dvalues = new double [ n ] ; 27 f o r ( i n t i = 0 ; i < n ; i++) { 28 cin >> dvalues [ i ] ; 29 } 30 cout << Search ( dvalues, n, f ) << endl ; 31 d e l e t e [ ] dvalues ; char c ; 34 cin >> n >> c ; 35 char * cvalues = new char [ n ] ; 36 f o r ( i n t i = 0 ; i < n ; i++) { 37 cin >> cvalues [ i ] ; 38 } 39 cout << Search ( cvalues, n, c ) << endl ; 40 d e l e t e [ ] cvalues ; 41 return 0 ; 42 } 19

20 8 COMPLEX 8 Complex 题目描述 设计一个复数类 Complex, 要求对运算符 + - * / 和 += -= *= /= 进行重载, 完成复数的加减乘除以及加减乘除复合赋值运算 ; 并且重载 << 和 >> 操作符完成复数的输入和输出 最后, 重载 = = 和!= 比较两个复数是否相等 </br> 使用以下 main 函数测试你的复数类 </br> ``` int main(){ Complex c1(-4, 6), c2(2, 5); cout << "c1 = " << c1 << "\n" << "c2 = " << c2 << endl; cout << "c1+c2 = " << c1 + c2 << endl; cout << "c1-c2 = " << c1 - c2 << endl; cout << "c1*c2 = " << c1 * c2 << endl; cout << "c1/c2 = " << c1 / c2 << endl; cout << (c1 += c2) << endl; cout << (c1 -= c2) << endl; cout << (c1 *= c2) << endl; cout << (c1 /= c2) << endl; cout << (c1 == c2) << " " << (c1!= c2) << endl; Complex c3; cin >> c3; cout << c3 << endl; return 0; } ``` 输入 1 2 输出 c1 = i c2 = 2 + 5i c1+c2 = i c1-c2 = i c1*c2 = i c1/c2 = i i i i i i 样例输入 null 样例输出 c1 = i c2 = 2 + 5i c1+c2 = i c1-c2 = i c1*c2 = i c1/c2 = i i i i i i 提示 复数加法公式 :(a+bi)+(c+di)=(a+c)+(b+d)i 复数减法公式 :(a+bi)-(c+di)=(a-c)+(b-d)i 20 复数乘法公式 :(a+bi)(c+di)=(ac-bd)+(ad+bc)i

21 8 COMPLEX 1 #i n c l u d e <iostream> 2 #i n c l u d e <c s t d l i b > 3 using namespace std ; c l a s s Complex { 7 p r i v a t e : 8 double x ; 9 double y ; 10 public : 11 Complex ( double x = 0. 0, double y = 0. 0 ) ; 12 Complex & operator+=(const Complex &) ; 13 Complex & operator =(const Complex &) ; 14 Complex & operator *=( const Complex &) ; 15 Complex & operator /=( const Complex &) ; 16 f r i e n d Complex operator+(const Complex &, const Complex &) ; 17 f r i e n d Complex operator ( const Complex &, const Complex &) ; 18 f r i e n d Complex operator *( const Complex &, const Complex &) ; 19 f r i e n d Complex operator /( const Complex &, const Complex &) ; 20 f r i e n d bool operator==(const Complex &, const Complex &) ; 21 f r i e n d bool operator!=( const Complex &, const Complex &) ; 22 f r i e n d ostream & operator <<(ostream &, const Complex &) ; 23 f r i e n d istream & operator >>(istream &, Complex &) ; 24 } ; Complex : : Complex ( double x, double y ) : x ( x ), y ( y ) {} Complex & Complex : : operator+=(const Complex & c ) { 29 return * t h i s = * t h i s + c ; 30 } Complex & Complex : : operator =(const Complex & c ) { 33 return * t h i s = * t h i s c ; 34 } Complex & Complex : : operator *=( const Complex & c ) { 37 return * t h i s = * t h i s * c ; 38 } Complex & Complex : : operator /=( const Complex & c ) { 41 return * t h i s = * t h i s / c ; 42 } Complex operator+(const Complex & c1, const Complex & c2 ) { 45 Complex temp ; 46 temp. x = c1. x + c2. x ; 47 temp. y = c1. y + c2. y ; 48 return temp ; 49 } 21

22 8 COMPLEX Complex operator ( const Complex & c1, const Complex & c2 ) { 52 Complex temp ; 53 temp. x = c1. x c2. x ; 54 temp. y = c1. y c2. y ; 55 return temp ; 56 } Complex operator *( const Complex & a, const Complex & b) 59 { 60 return Complex ( a. x*b. x a. y*b. y, a. x*b. y + b. x*a. y ) ; 61 } Complex operator /( const Complex & a, const Complex & c ) 64 { 65 return Complex ( ( a. x*c. x + a. y*c. y ) / ( c. x*c. x + c. y*c. y ), // [ ( ac+bd ) /( c*c+d*d ) ]+[( bc ad ) /( c*c+d*d ) ] i 66 ( a. y*c. x a. x*c. y ) / ( c. x*c. x + c. y*c. y ) ) ; 67 } bool operator==(const Complex & a, const Complex & b) { return ( ( a. x == b. x ) && ( a. y == b. y ) ) ; } bool operator!=( const Complex & a, const Complex & b) { return! ( a == b) ; } ostream & operator <<(ostream & os, const Complex & c ) { 74 os << c. x << " + " << c. y << "i" ; 75 return os ; 76 } istream & operator >>(istream & i s, Complex & c ) { 79 i s >> c. x >> c. y ; 80 return i s ; 81 } i n t main ( ) { 85 Complex c1 ( 4, 6), c2 (2, 5) ; 86 cout << "c1 = " << c1 << "\n" << "c2 = " << c2 << endl ; 87 cout << "c1+c2 = " << c1 + c2 << endl ; 88 cout << "c1-c2 = " << c1 c2 << endl ; 89 cout << "c1*c2 = " << c1 * c2 << endl ; 90 cout << "c1/c2 = " << c1 / c2 << endl ; 91 cout << ( c1 += c2 ) << endl ; 92 cout << ( c1 = c2 ) << endl ; 93 cout << ( c1 *= c2 ) << endl ; 94 cout << ( c1 /= c2 ) << endl ; 95 cout << ( c1 == c2 ) << " " << ( c1!= c2 ) << endl ; 96 Complex c3 ; 22

23 8 COMPLEX 97 cin >> c3 ; 98 cout << c3 << endl ; return 0 ; 101 } 23

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

C++ 程序设计 OJ4 - 参考答案 MASTER 2017 年 5 月 21 日 1 C++ 程序设计 OJ4 - 参考答案 MASTER 2017 年 5 月 21 日 1 1 SWAP 1 Swap 题目描述 用函数模板的方式实现对不同数据类型的数组中的数据进行输入 从小到大排序和输出 使用如下主函数测试你的模板设计一个函数模板 Swap, 实现任意数据类型的两个数据的交换, 分别用 int 型 double 型和 char 型的数据进行测试 main 函数如下 : int main()

More information

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

C++ 程序设计 OJ4 - 参考答案 MASTER 2019 年 5 月 3 日 1 C++ 程序设计 OJ4 - 参考答案 MASTER 2019 年 5 月 3 日 1 1 MYQUEUE 1 MyQueue 题目描述 设计一个 MyQueue 类模板, 类模板说明如下 : template class MyQueue; template std::ostream & operator

More information

C++ 程序设计 OJ9 - 参考答案 MASTER 2019 年 6 月 7 日 1

C++ 程序设计 OJ9 - 参考答案 MASTER 2019 年 6 月 7 日 1 C++ 程序设计 OJ9 - 参考答案 MASTER 2019 年 6 月 7 日 1 1 CARDGAME 1 CardGame 题目描述 桌上有一叠牌, 从第一张牌 ( 即位于顶面的牌 ) 开始从上往下依次编号为 1~n 当至少还剩两张牌时进行以下操作 : 把第一张牌扔掉, 然后把新的第一张放到整叠牌的最后 请模拟这个过程, 依次输出每次扔掉的牌以及最后剩下的牌的编号 输入 输入正整数 n(n

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

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

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

C++ 程序设计 OJ4 - 参考答案 MASTER 2019 年 5 月 30 日 1 C++ 程序设计 OJ4 - 参考答案 MASTER 2019 年 月 30 日 1 1 STRINGSORT 1 StringSort 题目描述 编写程序, 利用 string 类完成一个字符串中字符的排序 ( 降序 ) 并输出 输入描述 输入仅一行, 是一个仅由大小写字母和数字组成的字符串 输出描述 输出排序后的字符串 样例输入 abcde 样例输出 edcba 提示 使用 std::sort

More information

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

C++ 程序设计 OJ4 - 参考答案 MASTER 2019 年 5 月 30 日 1 C++ 程序设计 OJ4 - 参考答案 MASTER 2019 年 5 月 30 日 1 1 ANTI-PHRASE 1 Anti-phrase 题目描述 输入一些单词, 找出所有满足以下条件的单词 : 该单词不能通过字母重排, 得到输入文本中的另外一些单词 在判断是否满足条件时, 字母不区分大小写 如单词 tied 可以通过重排得到单词 EdiT, 重排时不考虑大小写 输出时应保留输入时的大小写,

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

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

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++ 程序设计 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

FY.DOC

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

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++入門編 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

IO

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

More information

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

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++ 程序设计 实验 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

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

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

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

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

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

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

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

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

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

More information

Chapter12 Derived Classes

Chapter12   Derived Classes 继 承 -- 派 生 类 复 习 1. 有 下 面 类 的 说 明, 有 错 误 的 语 句 是 : class X { A) const int a; B) X(); C) X(int val) {a=2 D) ~X(); 答 案 :C 不 正 确, 应 改 成 X(int val) : a(2) { 2. 下 列 静 态 数 据 成 员 的 特 性 中, 错 误 的 是 A) 说 明 静 态 数

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

Strings

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

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

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 料 類 說 Tang, Shih-Hsuan 2006/07/26 ~ 2006/09/02 六 PM 7:00 ~ 9:30 聯 ives.net@gmail.com www.csie.ntu.edu.tw/~r93057/aspnet134 度 C# 力 度 C# Web SQL 料 DataGrid DataList 參 ASP.NET 1.0 C# 例 ASP.NET 立

More information

提问袁小兵:

提问袁小兵: C++ 面 试 试 题 汇 总 柯 贤 富 管 理 软 件 需 求 分 析 篇 1. STL 类 模 板 标 准 库 中 容 器 和 算 法 这 部 分 一 般 称 为 标 准 模 板 库 2. 为 什 么 定 义 虚 的 析 构 函 数? 避 免 内 存 问 题, 当 你 可 能 通 过 基 类 指 针 删 除 派 生 类 对 象 时 必 须 保 证 基 类 析 构 函 数 为 虚 函 数 3.

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

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

Microsoft Word - 把时间当作朋友(2011第3版)3.0.b.06.doc

Microsoft Word - 把时间当作朋友(2011第3版)3.0.b.06.doc 2 5 8 11 0 13 1. 13 2. 15 3. 18 1 23 1. 23 2. 26 3. 28 2 36 1. 36 2. 39 3. 42 4. 44 5. 49 6. 51 3 57 1. 57 2. 60 3. 64 4. 66 5. 70 6. 75 7. 83 8. 85 9. 88 10. 98 11. 103 12. 108 13. 112 4 115 1. 115 2.

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

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

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

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

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

上海交通大学

上海交通大学 一 读程序, 写结果 ( 每题 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

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

Microsoft Word - 970617cppFinalSolution.doc

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

More information

運算子多載 Operator Overloading

運算子多載 Operator Overloading 函數樣板 (Function Template) 與 類別樣板 (Class Template) 講師 : 洪安 1 資料結構與 C++ 程式設計進階班 為何需要通用函數? (1/2) int abs(int x) { return (x>0)?x:-x; 取名困難不好記 float fabs(float x) { return (x>0)?x:-x; complex cabs(complex x)

More information

Eclipse C C++, or

Eclipse C C++,  or Eclipse C C++, Emailctchen@pl.csie.ntut.edu.tw or s1669021@ntut.edu.tw, s2598003@ntut.edu.tw http://pl.csie.ntut.edu.tw/~ctchen, http://www.ntut.edu.tw/~s2598003/ 2004/9/10 (0.02 ) Eclipse http://www.eclipse.org

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

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/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

Open topic Bellman-Ford算法与负环

Open topic   Bellman-Ford算法与负环 Open topic Bellman-Ford 2018 11 5 171860508@smail.nju.edu.cn 1/15 Contents 1. G s BF 2. BF 3. BF 2/15 BF G Bellman-Ford false 3/15 BF G Bellman-Ford false G c = v 0, v 1,..., v k (v 0 = v k ) k w(v i 1,

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

Microsoft Word - 01.DOC

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

More information

Microsoft Word - 97.01.30軟體設計第二部份範例試題_C++_ _1_.doc

Microsoft Word - 97.01.30軟體設計第二部份範例試題_C++_ _1_.doc 電 腦 軟 體 設 計 乙 級 技 術 士 技 能 檢 定 術 科 測 試 範 例 試 題 (C++) 試 題 編 號 :11900-920201-4 審 定 日 期 : 94 年 7 月 1 日 修 訂 日 期 : 96 年 2 月 1 日 97 年 1 月 30 日 ( 第 二 部 份 ) 電 腦 軟 體 設 計 乙 級 技 術 士 技 能 檢 定 術 科 測 試 應 檢 參 考 資 料 壹 試

More information

untitled

untitled 1 Outline 類别 欄 (1) 類 類 狀 更 易 類 理 若 類 利 來 利 using 來 namespace 類 ; (2) namespace IBM class Notebook namespace Compaq class Notebook 類别 類 來 類 列 欄 (field) (property) (method) (event) 類 例 立 來 車 類 類 立 車 欄 料

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

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

先生別耍我

先生別耍我 先 生 別 耍 我. 夏 雪 3 目 錄 : 第 一 章 005 第 二 章 019 第 三 章 044 第 四 章 058 第 五 章 077 第 六 章 101 第 七 章 121 第 八 章 136 4 目 錄 第 九 章 151 第 十 章 172 尾 聲 196 關 於 夏 雪 197 先 生 別 耍 我. 夏 雪 5 第 一 章 姜 曦 在 照 片 裡 翻 閱 照 片 的 是 一 個

More information

おおさか経済の動き pwd

おおさか経済の動き pwd http://www.pref.osaka.jp/aid/sangyou/index.html 100 90 80 70 1 2 3 4 5 6 7 8 9 101112 1 2 3 4 5 6 7 8 9 101112 1 2 3 4 5 6 7 8 9 101112 H22 H23 H24-5 -10-15 5 0 10 1 2 3 4 5 6 7 8 9 101112 1 2 3 4 5 6

More information

Microsoft PowerPoint - 4. 数组和字符串Arrays and Strings.ppt [兼容模式]

Microsoft PowerPoint - 4. 数组和字符串Arrays and Strings.ppt [兼容模式] Arrays and Strings 存储同类型的多个元素 Store multi elements of the same type 数组 (array) 存储固定数目的同类型元素 如整型数组存储的是一组整数, 字符数组存储的是一组字符 数组的大小称为数组的尺度 (dimension). 定义格式 : type arrayname[dimension]; 如声明 4 个元素的整型数组 :intarr[4];

More information

untitled

untitled 1 1.1 1.2 1.3 1.4 1.5 ++ 1.6 ++ 2 BNF 3 4 5 6 7 8 1.2 9 1.2 IF ELSE 10 1.2 11 1.2 12 1.3 Ada, Modula-2 Simula Smalltalk-80 C++, Objected Pascal(Delphi), Java, C#, VB.NET C++: C OOPL Java: C++ OOPL C# C++

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

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

ebook39-6

ebook39-6 6 first-in-first-out, FIFO L i n e a r L i s t 3-1 C h a i n 3-8 5. 5. 3 F I F O L I F O 5. 5. 6 5. 5. 6.1 [ ] q u e n e ( r e a r ) ( f r o n t 6-1a A 6-1b 6-1b D C D 6-1c a) b) c) 6-1 F I F O L I F ADT

More information

epub83-1

epub83-1 C++Builder 1 C + + B u i l d e r C + + B u i l d e r C + + B u i l d e r C + + B u i l d e r 1.1 1.1.1 1-1 1. 1-1 1 2. 1-1 2 A c c e s s P a r a d o x Visual FoxPro 3. / C / S 2 C + + B u i l d e r / C

More information

2.3 链表

2.3  链表 数据结构与算法 ( 二 ) 张铭主讲 采用教材 : 张铭, 王腾蛟, 赵海燕编写高等教育出版社,2008. 6 ( 十一五 国家级规划教材 ) https://pkumooc.coursera.org/bdsalgo-001/ 第二章线性表 2.1 线性表 2.2 顺序表 tail head a 0 a 1 a n-1 2.4 顺序表和链表的比较 2 链表 (linked list) 通过指针把它的一串存储结点链接成一个链

More information

Strings

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

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

,,,,,,,,,, : 12, 2 ; 1921,,,, ( ) ( ), ( ) ( ) ( ) ( ) 1945, 44 9, 33 4 1956 1 97 14, 73 8,,, 1949,,,,,,, ( ),, ( ),,, ( ),,,,,, 2 ,,,,,,,,,,,,, ; ;,,,,,, 3 1925,,,,, ( ),,,, 1 ( ),, 1922, ( ), 1925,,

More information

Ps22Pdf

Ps22Pdf 990 1995 ( ),,,,,,, ( ) ( ) ;, ;,, ( ),, 2000 7 1 ( 1 ) ( 4 ) ( 6 ) ( 15 ) ( 21 ) ( 33 ) ( 36 ) ( 43 ) ( 53 ) ( 60 ) ( 65 ) ( 74 ) ( 84 ) ( 87 ) ( 92 ) ( 97 ) (100) (111) (116) (119) (122) (127) (138)

More information

北京大学

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

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

エスポラージュ株式会社 住所 : 東京都江東区大島 東急ドエルアルス大島 HP: ******************* * 关于 Java 测试试题 ******

エスポラージュ株式会社 住所 : 東京都江東区大島 東急ドエルアルス大島 HP:  ******************* * 关于 Java 测试试题 ****** ******************* * 关于 Java 测试试题 ******************* 問 1 运行下面的程序, 选出一个正确的运行结果 public class Sample { public static void main(string[] args) { int[] test = { 1, 2, 3, 4, 5 ; for(int i = 1 ; i System.out.print(test[i]);

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

程序设计语言及基础

程序设计语言及基础 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

全国计算机技术与软件专业技术资格(水平)考试

全国计算机技术与软件专业技术资格(水平)考试 全 国 计 算 机 技 术 与 软 件 专 业 技 术 资 格 ( 水 平 ) 考 试 2008 年 上 半 年 程 序 员 下 午 试 卷 ( 考 试 时 间 14:00~16:30 共 150 分 钟 ) 试 题 一 ( 共 15 分 ) 阅 读 以 下 说 明 和 流 程 图, 填 补 流 程 图 中 的 空 缺 (1)~(9), 将 解 答 填 入 答 题 纸 的 对 应 栏 内 [ 说 明

More information

C/C++ 语言 - 循环

C/C++ 语言 - 循环 C/C++ Table of contents 7. 1. 2. while 3. 4. 5. for 6. 8. (do while) 9. 10. (nested loop) 11. 12. 13. 1 // summing.c: # include int main ( void ) { long num ; long sum = 0L; int status ; printf

More information

Guava学习之CharSequenceReader

Guava学习之CharSequenceReader CharSequenceReader 类是以 CharSequence 的形式读取字符 CharSequenceReader 类继承自 Reader 类, 除了 remaining() hasremaining() 以及 checkopen() 函数之后, 其他的函数都是重写 Reader 类中的函数 CharSequenceReader 类声明没有用 public 关键字, 所以我们暂时还不能调用这个类

More information

《C语言程序设计》教材习题参考答案

《C语言程序设计》教材习题参考答案 教材名称 : C 语言程序设计 ( 第 1 版 ) 黄保和 江弋编著清华大学出版社 ISBN:978-7-302-13599-9, 红色封面 答案制作时间 :2011 年 2 月 -5 月 一 选择题 1. 设已定义 int a, * p, 下列赋值表达式中正确的是 :C)p=&a 2. 设已定义 int x,*p=&x;, 则下列表达式中错误的是 :B)&*x 3. 若已定义 int a=1,*b=&a;,

More information

第七讲 继承与多态

第七讲  继承与多态 第 七 章 继 承 与 派 生 1 本 章 主 要 内 容 的 继 承 成 员 的 访 问 控 制 单 继 承 与 多 继 承 派 生 的 构 造 析 构 函 数 成 员 的 标 识 与 访 问 深 度 探 索 2 的 继 承 与 派 生 的 继 承 与 派 生 保 持 已 有 的 特 性 而 构 造 新 的 过 程 称 为 继 承 在 已 有 的 基 础 上 新 增 自 己 的 特 性 而 产 生

More information

Microsoft Word - CPE考生使用手冊160524.docx

Microsoft Word - CPE考生使用手冊160524.docx 大 學 程 式 能 力 檢 定 (CPE) 考 生 使 用 手 冊 2016 年 5 月 24 日 這 份 手 冊 提 供 給 參 加 CPE 檢 定 考 試 的 考 生 內 容 包 含 考 試 環 境 的 使 用, 以 及 解 題 時 所 使 用 I/O 的 基 本 知 識 1. 如 欲 報 名 參 加 CPE 考 試, 請 先 於 CPE 網 站 完 成 帳 號 註 冊, 然 後 再 報 名 該

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

51 C 51 isp 10 C PCB C C C C KEIL

51 C 51 isp 10   C   PCB C C C C KEIL http://wwwispdowncom 51 C " + + " 51 AT89S51 In-System-Programming ISP 10 io 244 CPLD ATMEL PIC CPLD/FPGA ARM9 ISP http://wwwispdowncom/showoneproductasp?productid=15 51 C C C C C ispdown http://wwwispdowncom

More information

!"#$%"#$!& () #*("+$,# -+(&. )!""# $ $ $ $ $ $ $ $ $ !!!"#$%#$&!"#$% #" %#&# %# (%!) (&#"*%!!!!!!!!!!!!!!!!!!!!!!! " "# (&$")(!*+,*)-%$ ".%).(%/!!!!!!!!!!!!!!!!!!!!!!!!!!!! $ (&$")(!*+ &$*$(&$(!*+,*)-%$

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 - 把时间当作朋友(2011第3版)3.0.b.07.doc

Microsoft Word - 把时间当作朋友(2011第3版)3.0.b.07.doc 2 5 8 11 0 1. 13 2. 15 3. 18 1 1. 22 2. 25 3. 27 2 1. 35 2. 38 3. 41 4. 43 5. 48 6. 50 3 1. 56 2. 59 3. 63 4. 65 5. 69 13 22 35 56 6. 74 7. 82 8. 84 9. 87 10. 97 11. 102 12. 107 13. 111 4 114 1. 114 2.

More information

0 1!, 10,,,,,, ( 1) 1 ( ) ( ) ( ) ( ) 3. 3 0. 4 50. 4 1. 7 32. 7 1. 5 34. 3 1. 2 3. 2 0. 4 49. 8 1. 6 32. 6 1. 4 33. 9 1. 2, 5 8 3 4, 7 10, 600,

0 1!, 10,,,,,, ( 1) 1 ( ) ( ) ( ) ( ) 3. 3 0. 4 50. 4 1. 7 32. 7 1. 5 34. 3 1. 2 3. 2 0. 4 49. 8 1. 6 32. 6 1. 4 33. 9 1. 2, 5 8 3 4, 7 10, 600, 0 1 1 1 2 19 2 3 33 3 4 45 4 5 57 5 6 71 6 8 83 8 10 95 10 12 107 12 15 119 15 18 131 18 21 143 21 24 155 2 2 167 2 3 179 [ ] 191 0 1!, 10,,,,,, ( 1) 1 ( ) ( ) ( ) ( ) 3. 3 0. 4 50. 4 1. 7 32. 7 1. 5 34.

More information

戲劇研究 創刊號 詞之雅化 實為 折子戲 源生之三個重要背景 歷代戲曲劇種如先秦至唐代之 戲曲小戲 宋金雜劇院本 北曲雜劇四折每折作獨立性演出 乃至明清民間 小戲與南雜劇之一折短劇 均實為折子戲之 先驅 則明正德至嘉靖間北劇南 戲選本之 摘套 與 散齣 迎神賽社禮節傳簿 中之 零折散齣 均可 視之為

戲劇研究 創刊號 詞之雅化 實為 折子戲 源生之三個重要背景 歷代戲曲劇種如先秦至唐代之 戲曲小戲 宋金雜劇院本 北曲雜劇四折每折作獨立性演出 乃至明清民間 小戲與南雜劇之一折短劇 均實為折子戲之 先驅 則明正德至嘉靖間北劇南 戲選本之 摘套 與 散齣 迎神賽社禮節傳簿 中之 零折散齣 均可 視之為 戲 劇 研 究 200 年1月 創刊號 頁1 2 論說 折子戲 曾永義 世新大學講座教授 緒論 折子戲 這一戲曲名詞 大家耳熟能詳 但如果進一步思考 1. 折子戲 之名始於何時 2. 折子戲 之詞彙結構如何形成 3.如果把 折子戲 當作一生命體 那麼其源生 形成 成熟與衰老的不同 階段 各自如何 其源生 形成的背景如何 其成熟興盛和衰老頹廢的原因又是 如何 4.當折子戲成熟之時 折子戲本身具有何等樣的周延義涵

More information

2009年挑战乔戈里

2009年挑战乔戈里 2009 年 挑 战 乔 戈 里 活 动 概 况 : 乔 戈 里 峰 海 拔 8611 米, 它 是 喀 喇 昆 仑 山 脉 的 主 峰, 是 世 界 上 第 二 高 峰, 国 外 又 称 K2 峰 乔 戈 里 峰, 国 际 登 山 界 公 认 的 攀 登 难 度 较 大 的 山 峰 之 一 乔 戈 里 峰 峰 巅 呈 金 字 塔 形, 冰 崖 壁 立, 山 势 险 峻, 在 陡 峭 的 坡 壁 上

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

zt

zt ! ! !"" #" $ !"#$ % & " ())! "# ( ( * % & * % (+() (%, !"#$ "%& ( % !"!#$% $%&!"%! %& ( !" #$ %$!#!" & !" #$%$ &" ( ( ) * !! " #!$!! %&!! % ( ( &% )* )" ") (! !"#!"#!"$!!%!#%!&!(!(!)*!**!!%*!$* #") #")

More information

untitled

untitled 1 7 7.1 7.2 7.3 7.4 7.5 2 7.1 VFT virtual 7.1 3 1 1. 2. public protected public 3. VFT 4. this const volatile 4 2 5. ( ) ( ) 7.1 6. no-static virtual 7.2 7. inline 7.3 5 3 8. this this 9. ( ) ( ) delete

More information

第三节 软件测试的过程与策略

第三节 软件测试的过程与策略 ...1...4...9...17...25...29...34...40...46...55...65...73 1 2 3 4 5 6 7 8 9 10 11 1 12 13 1 ABCD 2 A B C D 3 ABCD 4 A1/2 B1/3 C1/4 D2/3 5 % A20 B30 C40 D50 6 A B C D 7 A B C D / 8 A B C D 9 A B C D 10

More information

C/C++ - 数组与指针

C/C++ - 数组与指针 C/C++ Table of contents 1. 2. 3. 4. 5. 6. 7. 8. 1 float candy [ 365]; char code [12]; int states [50]; 2 int array [6] = {1, 2, 4, 6, 8, 10}; 3 // day_mon1.c: # include # define MONTHS 12 int

More information

<4D6963726F736F667420506F776572506F696E74202D20332D322E432B2BC3E6CFF2B6D4CFF3B3CCD0F2C9E8BCC6A1AAD6D8D4D8A1A2BCCCB3D0A1A2B6E0CCACBACDBEDBBACF2E707074>

<4D6963726F736F667420506F776572506F696E74202D20332D322E432B2BC3E6CFF2B6D4CFF3B3CCD0F2C9E8BCC6A1AAD6D8D4D8A1A2BCCCB3D0A1A2B6E0CCACBACDBEDBBACF2E707074> 程 序 设 计 实 习 INFO130048 3-2.C++ 面 向 对 象 程 序 设 计 重 载 继 承 多 态 和 聚 合 复 旦 大 学 计 算 机 科 学 与 工 程 系 彭 鑫 pengxin@fudan.edu.cn 内 容 摘 要 方 法 重 载 类 的 继 承 对 象 引 用 和 拷 贝 构 造 函 数 虚 函 数 和 多 态 性 类 的 聚 集 复 旦 大 学 计 算 机 科 学

More information

WHUST 2017 Div.2 Day 3.5 C++ 标准模版库

WHUST 2017 Div.2 Day 3.5  C++ 标准模版库 标准模版库 标准模版库 集训队郭松 集训队郭松 标准模版库 标准模版库 纲 介绍算法竞赛中, 需要 到的 知识命名空间代码框架实参 类型模版函数简介 模版类简介 集训队郭松 标准模版库 标准模版库介绍算法竞赛中, 需要 到的 知识算法竞赛中, 需要 到的 知识标准命名空间 std 集训队郭松 标准模版库 标准模版库介绍算法竞赛中, 需要 到的 知识算法竞赛中, 需要 到的 知识标准命名空间 std

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

立 志 于 打 造 最 贴 近 考 生 实 际 的 辅 导 书 计 算 机 考 研 之 数 据 结 构 高 分 笔 记 率 辉 编 著 周 伟 张 浩 审 核 讨 论 群 :15945769

立 志 于 打 造 最 贴 近 考 生 实 际 的 辅 导 书 计 算 机 考 研 之 数 据 结 构 高 分 笔 记 率 辉 编 著 周 伟 张 浩 审 核 讨 论 群 :15945769 立 志 于 打 造 最 贴 近 考 生 实 际 的 辅 导 书 计 算 机 考 研 之 数 据 结 构 高 分 笔 记 率 辉 编 著 周 伟 张 浩 审 核 讨 论 群 :15945769 前 言 在 计 算 机 统 考 的 四 门 专 业 课 中, 最 难 拿 高 分 的 就 是 数 据 结 构 但 是 这 门 课 本 身 的 难 度 并 不 是 考 生 最 大 的 障 碍, 真 正 的 障 碍

More information

untitled

untitled (encapsulation) 例 類 說 類 料 來 料 information hiding 念 (inheritance) 來說 類 類 類 類 類 類 行 利 來 (polymorphism) 不 類 數 不 1 2 3 4 類 類 不 類 不 類 5 6 7 // virtual 不見了 #include #include using namespace

More information

3. 給 定 一 整 數 陣 列 a[0] a[1] a[99] 且 a[k]=3k+1, 以 value=100 呼 叫 以 下 兩 函 式, 假 設 函 式 f1 及 f2 之 while 迴 圈 主 體 分 別 執 行 n1 與 n2 次 (i.e, 計 算 if 敘 述 執 行 次 數, 不

3. 給 定 一 整 數 陣 列 a[0] a[1] a[99] 且 a[k]=3k+1, 以 value=100 呼 叫 以 下 兩 函 式, 假 設 函 式 f1 及 f2 之 while 迴 圈 主 體 分 別 執 行 n1 與 n2 次 (i.e, 計 算 if 敘 述 執 行 次 數, 不 1. 右 側 程 式 正 確 的 輸 出 應 該 如 下 : * *** ***** ******* ********* 在 不 修 改 右 側 程 式 之 第 4 行 及 第 7 行 程 式 碼 的 前 提 下, 最 少 需 修 改 幾 行 程 式 碼 以 得 到 正 確 輸 出? (A) 1 (B) 2 (C) 3 (D) 4 1 int k = 4; 2 int m = 1; 3 for (int

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