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

Size: px
Start display at page:

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

Transcription

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

2 1 PERSON 1 Person 题目描述 编写程序, 定义一个基类 Person, 包含 name 和 age 两个数据成员 ; 再由它派生出学生类 Student 和教师类 Teacher, 其中学生类添加学号 no 数据, 教师类添加职称 title 数据 ; 要求每个类均有构造函数 析构函数和显示数据的函数 使用以下函数运行你的程序 : int main() { Person p("mary", 18); p.show(); Student s("tom", 20, 10001); s.show(); Teacher t("john", 30, "Associate Professor"); t.show(); return 0; } 输入 无 输出 Constructor of Person Name: Mary, Age: 18 Constructor of Person Constructor of Student Name: Tom, Age: 20, No: Constructor of Person Constructor of Teacher Name: John, Age: 30, Title: Associate Professor Destructor of Teacher Destructor of Person Destructor of Student Destructor of Person Destructor of Person 样例输入 null 样例输出 Constructor of Person Name: Mary, Age: 18 Constructor of Person Constructor of Student Name: Tom, Age: 20, No: Constructor of Person Constructor of Teacher Name: John, Age: 30, Title: Associate Professor Destructor of Teacher Destructor of Person Destructor of Student Destructor of Person Destructor of Person 注意标点符号是半角字符,:, 后面有一个空格 2

3 1 PERSON 1 #include <iostream > 2 #include <s t r i n g > 3 using namespace std ; 4 5 c l a s s Person 6 { 7 p r o t e c t e d : 8 s t r i n g name ; 9 i n t age ; 10 p u b l i c : 11 Person ( const s t r i n g &name, i n t age ) 12 { 13 t h i s >name = name ; 14 t h i s >age = age ; 15 c o u t << " Constructor of Person\n" ; 16 } 17 ~Person ( ) 18 { 19 c o u t << " Destructor of Person\n" ; 20 } 21 void show ( ) 22 { 23 cout << "Name: " << name << ", " << "Age: " << age << endl ; 24 } 25 } ; c l a s s Student : p u b l i c Person 29 { 30 p r i v a t e : 31 i n t no ; 32 p u b l i c : 33 Student ( const s t r i n g &nname, i n t aage, i n t number ) : Person (nname, aage ), no ( number ) 34 { 35 c o u t << " Constructor of Student\n" ; 36 } 37 ~Student ( ) 38 { 39 c o u t << " Destructor of Student\n" ; 40 } 41 void show ( ) 42 { 43 cout << "Name: " << name << ", " << "Age: " << age << ", " << "No: " << no << endl ; 3

4 1 PERSON 44 } 45 } ; c l a s s Teacher : p u b l i c Person 48 { 49 p r i v a t e : 50 s t r i n g t i t l e ; 51 p u b l i c : 52 Teacher ( s t r i n g n, i n t a, s t r i n g t i ) : Person (n, a ), t i t l e ( t i ) 53 { 54 c o u t << " Constructor of Teacher\n" ; 55 } 56 ~Teacher ( ) 57 { 58 c o u t << " Destructor of Teacher\n" ; 59 } 60 void show ( ) 61 { 62 cout << "Name: " << name << ", " << "Age: " << age << ", " << " Title: " << t i t l e << endl ; 63 } 64 } ; i n t main ( ) 67 { 68 Person p ( "Mary",18) ; 69 p. show ( ) ; 70 Student s ( "Tom",20,10001) ; 71 s. show ( ) ; 72 Teacher t ( "John",30, "Associate Professor" ) ; 73 t. show ( ) ; 74 return 0 ; 75 } 4

5 2 INPUTOUTPUT 2 InputOutput 题目描述 用 cin 输入你的姓名 ( 没有空格 ) 和年龄 ( 整数 ), 并用 cout 输出 输入输出符合以下范例 输入 master 999 输出 I am master, 999 years old. 注意 "," 后面有一个空格,"." 结束, 没有其它格式输出 5

6 2 INPUTOUTPUT 1 #include <iostream > 2 #include <s t r i n g > 3 4 using namespace std ; i n t main ( ) 8 { 9 s t r i n g name ; 10 i n t year ; 11 c i n >> name ; 12 c i n >> year ; 13 cout << "I am " << name << ", " << year << " years old.\n" ; 14 return 0 ; 15 } 6

7 3 REPLACECHAR1 3 ReplaceChar1 题目描述 输入字符串 ( 没有空格字符 ), 替换把其中的字符 'c' 替换成 'C' 并使用以下 main 函数 : int main(){ char str[256]; cin >> str; Replace(str, 'c', 'C'); cout << str << endl; return 0; } 输入描述 字符串 输出描述 结果 输入 abcdedgc 输出 abcdedgc 7

8 3 REPLACECHAR1 1 #i n c l u d e <iostream > 2 using namespace std ; void Replace ( char * s t r, char chsrc, char chdst ) 6 { 7 while (* s t r ) 8 { 9 i f (* s t r==chsrc ) 10 { 11 * s t r = chdst ; 12 } 13 s t r ++; 14 } 15 } i n t main ( ) { 18 char s t r [ ] ; 19 c i n >> s t r ; 20 Replace ( s t r, 'c', 'C' ) ; 21 cout << s t r << endl ; 22 return 0 ; 23 } 8

9 4 REPLACECHAR2 4 ReplaceChar2 题目描述 输入 string 字符串 str( 可以包含空格字符 ), 替换把其中的字符 'c' 替换成 'C' int main(){ string str; // 补充输入 Replace(str, 'c', 'C'); cout << str << endl; return 0; } 输入描述 字符串 输出描述 结果 输入 abcdedgc 输出 abcdedgc 9

10 4 REPLACECHAR2 1 #i n c l u d e <iostream > 2 #i n c l u d e <s t r i n g > 3 using namespace std ; void Replace ( s t r i n g &s t r, char chsrc, char chdst ) 7 { 8 f o r ( i n t i =0; i <s t r. l e n g t h ( ) ; i++) 9 { 10 i f ( s t r [ i ]==chsrc ) 11 { 12 s t r [ i ] = chdst ; 13 } 14 } 15 } i n t main ( ) { 18 s t r i n g s t r ; 19 g e t l i n e ( cin, s t r ) ; 20 Replace ( s t r, 'c', 'C' ) ; 21 cout << s t r << endl ; 22 return 0 ; 23 } 10

11 5 DYNAMICARRAY 5 DynamicArray 题目描述 计算输入小数的和 输入第一行为小数个数, 第二行为小数 ( 空格隔开 ), 输出这些小数的和 输入 第一行为小数个数, 第二行为小数 ( 空格隔开 ) 输出 这些小数的和 输入 输出

12 5 DYNAMICARRAY 1 #i n c l u d e <iostream > 2 #i n c l u d e <s t r i n g > 3 using namespace std ; double Sum( double a r r [ ], i n t n ) 7 { 8 double sum = 0. 0 ; 9 f o r ( i n t i =0; i <n ; i++) 10 sum += a r r [ i ] ; 11 return sum ; 12 } double * Input ( i n t n ) 15 { 16 double * a r r = new double [ n ] ; 17 f o r ( i n t i =0; i <n ; i++) 18 c i n >> a r r [ i ] ; 19 return a r r ; 20 } i n t main ( ) 24 { 25 i n t n ; 26 c i n >> n ; 27 double * a r r ; 28 a r r = Input ( n ) ; 29 cout << Sum( arr, n ) << endl ; 30 d e l e t e [ ] a r r ; 31 return 0 ; 32 } 12

13 6 ARRAY 6 Array 题目描述 计算输入小数的和 输入第一行为小数个数, 第二行为小数 ( 空格隔开 ), 输出这些小数的和 并使用以下 main 函数 int main() { int n; cin >> n; vector<double> arr; Input(arr, n); cout << Sum(arr) << endl; return 0; } 输入 第一行为小数个数, 第二行为小数 ( 空格隔开 ) 输出 小数的和 输入 输出 16.5 提示需要使用引用 以及 vector 的常用方法 如增加元素 push_back(), 向量的长度 size() 等 13

14 6 ARRAY 1 #i n c l u d e <iostream > 2 #i n c l u d e <vector > 3 using namespace std ; double Sum( vector <double> &a r r ) 7 { 8 double sum = 0. 0 ; 9 f o r ( i n t i =0; i <a r r. s i z e ( ) ; i++) 10 sum += a r r [ i ] ; 11 return sum ; 12 } void Input ( vector <double> &arr, i n t n ) 15 { f o r ( i n t i =0; i <n ; i++) 18 { 19 double temp ; 20 c i n >> temp ; 21 a r r. push_back ( temp ) ; 22 } 23 } i n t main ( ) 27 { 28 i n t n ; 29 c i n >> n ; 30 vector <double> a r r ; 31 Input ( arr, n ) ; 32 cout << Sum( a r r ) << endl ; 33 return 0 ; 34 } 14

15 7 STRUCT 7 Struct 题目描述 Vector2D 为二维坐标, 输入两个向量, 计算这两个相邻的和 并使用以下 main 函数测试 int main() { Vector2D v1,v2; Input(v1); Input(&v2); Vector2D v = Sum(v1, v2); } cout << v.x << " " << v.y << endl; return 0; 输入 第一行第一个向量, 第二行为第二个向量 输出 向量的和 输入 输出

16 7 STRUCT 1 #i n c l u d e <iostream > 2 #i n c l u d e <vector > 3 using namespace std ; 4 5 s t r u c t Vector2D 6 { 7 double x, y ; 8 } ; 9 10 void Input ( Vector2D &v ) 11 { 12 c i n >> v. x >> v. y ; 13 } void Input ( Vector2D *v ) 16 { 17 c i n >> v >x >> v >y ; 18 } Vector2D Sum( const Vector2D &v1, const Vector2D &v2 ) 22 { 23 Vector2D v ; 24 v. x = v1. x+v2. x ; 25 v. y = v1. y+v2. y ; 26 return v ; 27 } i n t main ( ) 31 { 32 Vector2D v1, v2 ; 33 Input ( v1 ) ; 34 Input(&v2 ) ; 35 Vector2D v = Sum( v1, v2 ) ; cout << v. x << " " << v. y << endl ; 38 return 0 ; 39 } 16

17 8 TEMPLATE1 8 Template1 描述 使用模板函数求最大值 使用如下 main 函数对程序进行测试 int main() { double a, b; cin >> a >> b; cout << Max(a, b) << endl; int c, d; cin >> c >> d; cout << Max(c, d) << endl; } return 0; 输入 两个小数连个整数 输出 最大小数最大整数 样例输入 样例输出

18 8 TEMPLATE1 1 #include <iostream > 2 using namespace std ; 3 4 template<c l a s s T> 5 T Max( const T &a, const T &b ) 6 { 7 i f ( a>b ) return a ; 8 return b ; 9 } i n t main ( ) 12 { 13 double a, b ; 14 c i n >> a >> b ; 15 cout << Max( a, b ) << endl ; i n t c, d ; 18 c i n >> c >> d ; 19 cout << Max( c, d ) << endl ; return 0 ; 22 } 18

19 9 TEMPLATE2 9 Template2 描述 使用模板函数排序 使用如下 main 函数对程序进行测试 int main() { double a, b, c; cin >> a >> b >> c; Sort(a, b); cout << a << "\t" << b << endl; Sort(a, b, c); cout << a << "\t" << b << "\t" << c << endl; int d, e, f; cin >> d >> e >> f; Sort(d, e); cout << d << "\t" << e << endl; Sort(d, e, f); cout << d << "\t" << e << "\t" << f << endl; } return 0; 输入 三个小数三个整数 输出 两个排好序的小数三个排好序的小数两个排好序的整数三个排好序的整数 样例输入 样例输出

20 9 TEMPLATE2 1 #include <iostream > 2 using namespace std ; 3 4 template<c l a s s T> 5 void Sort (T &a, T &b ) 6 { 7 i f ( a<b ) return ; 8 T temp = a ; 9 a = b ; 10 b = temp ; 11 } template<c l a s s T> 14 void Sort (T &a, T &b, T &c ) 15 { 16 Sort ( a, b ) ; 17 Sort (b, c ) ; 18 Sort ( a, b ) ; 19 } i n t main ( ) 22 { 23 double a, b, c ; 24 c i n >> a >> b >> c ; 25 Sort ( a, b ) ; 26 cout << a << "\t" << b << endl ; 27 Sort ( a, b, c ) ; 28 cout << a << "\t" << b << "\t" << c << endl ; i n t d, e, f ; 31 c i n >> d >> e >> f ; 32 Sort (d, e ) ; 33 cout << d << "\t" << e << endl ; 34 Sort (d, e, f ) ; 35 cout << d << "\t" << e << "\t" << f << endl ; return 0 ; 38 } 20

21 10 PERIMETER 10 Perimeter 描述 编写一个园形类 Circle, 实现半径的输入 周长的计算和输出 使用如下 main 函数对程序进行测试 ( 其中 PI=acos(-1.0)) int main() { double r; cin >> r; Circle ci(a); cout << ci.perimeter(); return 0; } 输入 半径 输出 周长 ( 小数点后两位 ) 样例输入 样例输出 圆周率的取值需要比较精确, 以保证计算结果的精度控制精度可能需要以下代码 #include<iostream> #include<iomanip> cout<<setiosflags(ios::fixed)<<setprecision(2); 21

22 10 PERIMETER 1 #include <iostream > 2 #include <iostream > 3 #include <iomanip> 4 #i n c l u d e <cmath> 5 using namespace std ; 6 7 double PI = acos ( 1.0) ; 8 c l a s s C i r c l e 9 { 10 p r i v a t e : 11 double r ; 12 p u b l i c : 13 C i r c l e ( double r =0.0) { t h i s >r=r ; } ; 14 double Perimeter ( ) { return 2*PI* r ; } 15 } ; i n t main ( ) 18 { 19 double r ; 20 c i n >> r ; 21 C i r c l e c i ( r ) ; 22 cout<<s e t i o s f l a g s ( i o s : : f i x e d )<<s e t p r e c i s i o n ( 2 ) ; 23 cout << c i. Perimeter ( ) ; 24 return 0 ; 25 } 22

23 11 SQUARE 11 Square 描述 编写一个正方形类 Square, 实现边长的输入 面积和周长的计算和输出 使用如下 main 函数对程序进行测试 int main() { double a; cin >> a; Square sq(a); } cout << "Area: "<< sq.area() << "\nperimeter: "<< sq.perimeter(); return 0; 输入 边长 输出 面积周长 样例输入 10.2 样例输出 Area: Perimeter:

24 11 SQUARE 1 #include <iostream > 2 using namespace std ; 3 4 c l a s s Square 5 { 6 p r i v a t e : 7 double a ; 8 p u b l i c : 9 Square ( ) {a = 0. 0 ; } ; 10 Square ( double a ) { t h i s >a=a ; } ; 11 double Area ( ) { return a*a ; } 12 double Perimeter ( ) { return 4*a ; } 13 } ; i n t main ( ) 16 { 17 double a ; 18 c i n >> a ; 19 Square sq ( a ) ; cout << "Area: "<< sq. Area ( ) << "\nperimeter: "<< sq. Perimeter ( ) ; 22 return 0 ; 23 } 24

25 12 BOOK 12 Book 题目描述 完成图书类 Book( 包含书名, 作者, 销量 ), 并用以下 main 函数测试 Book 类 int main() { Book book1; book1.print(); string name, author; int sale; getline(cin, name); getline(cin, author); cin >> sale; } Book book2(name, author, sale); book2.print(); return 0; 输入 第一行书名第二行作者名第三行销量 输出 Name: 书名, Author: 作者, Sale: 销量 Name: 书名, Author: 作者, Sale: 销量 输入样例 The Art of Computer Programming Donald Ervin Knuth 1000 输出样例 Name: no, Author: no, Sale: 0 Name: The Art of Computer Programming, Author: Donald Ervin Knuth, Sale:

26 12 BOOK 1 #include <iostream > 2 #include <s t r i n g > 3 using namespace std ; 4 5 c l a s s Book 6 { 7 p r i v a t e : 8 s t r i n g name ; // 9 s t r i n g author ; // 10 i n t s a l e ; // - 11 p u b l i c : 12 Book ( ) 13 { 14 name = "no" ; 15 author = "no" ; 16 s a l e = 0 ; 17 } 18 Book ( const s t r i n g &n, const s t r i n g &a, i n t s ) 19 { 20 name = n ; 21 author = a ; 22 s a l e = s ; 23 } 24 void Print ( ) 25 { 26 cout<<" Name: "<<name<<", " ; 27 cout<<" Author: "<<author<<", " ; 28 cout<<"sale: "<<s a l e <<endl ; 29 } 30 ~Book ( ) {} 31 } ; i n t main ( ) 34 { 35 Book book1 ; 36 book1. Print ( ) ; s t r i n g name, author ; 39 i n t s a l e ; 40 g e t l i n e ( cin, name) ; 41 g e t l i n e ( cin, author ) ; 42 c i n >> s a l e ; Book book2 (name, author, s a l e ) ; 45 book2. Print ( ) ; 26

27 12 BOOK 46 return 0 ; 47 } 27

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

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

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

新版 明解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

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

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

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

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

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

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

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

第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

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

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

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

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

untitled

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

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

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

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

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

個 人 的 手, 拉 著 瞎 子 的 手 把 他 帶 往 村 外 的 時 候, 對 於 瞎 子 來 講, 那 個 人 的 手 和 耶 穌 的 手 有 沒 有 區 別? 沒 有! 為 什 麼 沒 有 區 別? 因 為 對 於 一 個 瞎 子 來 說, 手 和 耳 朵 就 是 他 接 觸 世 界, 瞭

個 人 的 手, 拉 著 瞎 子 的 手 把 他 帶 往 村 外 的 時 候, 對 於 瞎 子 來 講, 那 個 人 的 手 和 耶 穌 的 手 有 沒 有 區 別? 沒 有! 為 什 麼 沒 有 區 別? 因 為 對 於 一 個 瞎 子 來 說, 手 和 耳 朵 就 是 他 接 觸 世 界, 瞭 課 目 : 講 道 法 學 生 : 楊 建 偉 老 師 : 汪 院 長 時 間 :2009 年 8 月 1 日 靈 命 三 階 ( 可 8:22-26) 在 四 部 福 音 書 中, 這 是 一 段 很 特 別 的 記 載 特 別 在 什 麼 地 方 呢? 是 不 是 特 別 在 耶 穌 基 督 對 一 個 病 人 的 醫 治? 不, 在 耶 穌 三 年 半 的 服 侍 當 中, 曾 經 醫 治 數

More information

IO

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

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 - CPE考生使用手冊160524.docx

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

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

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

C++ 程序设计 OJ10 - 参考答案 MASTER 2019 年 6 月 17 日 1 C++ 程序设计 OJ10 - 参考答案 MASTER 2019 年 6 月 17 日 1 1 STRINGREVERSE 1 StringReverse 题目描述 利用 string 类对字符串进行 ( 按反转后字典序 ) 排序并输出, 例如两个字符串为 aab, cba, 则 cba 应该排在 aab 之前, 因为 cba 反转后为 abc, aab 反转后为 baa. 输入 第一行为一个整数

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

Microsoft Word - 第7章 类与对象.docx

Microsoft Word - 第7章 类与对象.docx 第 7 章类与对象 案例 1 地址类 #include class Address char Name[21]; char Street[51]; char City[51]; char Postcode[10]; SetAddress(char *name,char *street,char *city,char *postcode); void ChangeName(char

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

エスポラージュ株式会社 住所 : 東京都江東区大島 東急ドエルアルス大島 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

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

More information

Strings

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

More information

nooog

nooog C : : : , C C,,, C, C,, C ( ), ( ) C,,, ;,, ; C,,, ;, ;, ;, ;,,,, ;,,, ; : 1 9, 2 3, 4, 5, 6 10 11, 7 8, 12 13,,,,, 2008 1 1 (1 ) 1.1 (1 ) 1.1.1 ( ) 1.1.2 ( ) 1.1.3 ( ) 1.1.4 ( ) 1.1.5 ( ) 1.2 ( ) 1.2.1

More information

FY.DOC

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

More information

北京大学

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

More information

《计算概论》课程 第十九讲 C 程序设计语言应用

《计算概论》课程 第十九讲  C 程序设计语言应用 计算概论 A 程序设计部分 字符数组与字符串 李戈 北京大学信息科学技术学院软件研究所 lige@sei.pku.edu.cn 字符数组的定义 #include int main() char a[10] = 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j' ; for (int i = 0; i < 10; i++) cout

More information

C/C++ - 字符串与字符串函数

C/C++ - 字符串与字符串函数 C/C++ Table of contents 1. 2. 3. 4. 1 char C 2 char greeting [50] = " How " " are " " you?"; char greeting [50] = " How are you?"; 3 printf ("\" Ready, go!\" exclaimed John."); " Ready, go!" exclaimed

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

新・解きながら学ぶ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

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. STL 类 模 板 标 准 库 中 容 器 和 算 法 这 部 分 一 般 称 为 标 准 模 板 库 2. 为 什 么 定 义 虚 的 析 构 函 数? 避 免 内 存 问 题, 当 你 可 能 通 过 基 类 指 针 删 除 派 生 类 对 象 时 必 须 保 证 基 类 析 构 函 数 为 虚 函 数 3.

More information

Microsoft Word - chap10.doc

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

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 料, 數, - 列 串 理 列 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

6 C51 ANSI C Turbo C C51 Turbo C C51 C51 C51 C51 C51 C51 C51 C51 C C C51 C51 ANSI C MCS-51 C51 ANSI C C C51 bit Byte bit sbit

6 C51 ANSI C Turbo C C51 Turbo C C51 C51 C51 C51 C51 C51 C51 C51 C C C51 C51 ANSI C MCS-51 C51 ANSI C C C51 bit Byte bit sbit 6 C51 ANSI C Turbo C C51 Turbo C C51 C51 C51 C51 C51 C51 C51 C51 C51 6.1 C51 6.1.1 C51 C51 ANSI C MCS-51 C51 ANSI C C51 6.1 6.1 C51 bit Byte bit sbit 1 0 1 unsigned char 8 1 0 255 Signed char 8 11 128

More information

第七讲 继承与多态

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

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

C/C++ - 结构体、共用体、枚举体

C/C++ - 结构体、共用体、枚举体 C/C++ Table of contents 1. 2. 3. 4. 5. 6. 7. 8. 1 C C (struct) C 2 C C (struct) C 2 i // book.c: # include < stdio.h> # define MAX_ TITLE 41 # define MAX_ AUTHOR 31 struct book { char title [ MAX_ TITLE

More information

CC213

CC213 : (Ken-Yi Lee), E-mail: feis.tw@gmail.com 177 [P179] (1) - [P181] [P182] (2) - for [P183] (3) - switch [P184] [P187] [P189] [P194] 178 [ ]; : : int var; : int var[3]; var 2293620 var[0] var[1] 2293620

More information

Microsoft Word - 新1-12.doc

Microsoft Word - 新1-12.doc 实训 5 面向对象编程练习 实训 5 面向对象编程练习 5.1 实训目的 通过编程和上机实验理解 Java 语言是如何体现面向对象编程基本思想 以及如何创建类 和对象 了解成员变量和成员方法的特性 5.2 实训要求 编写一个体现面向对象思想的程序 编写一个创建对象和使用对象的方法的程序 5.3 实训内容 5.3.1 创建对象并使用对象 1 定义一个 Person 类 可以在应用程序中使用该类 成员属性

More information

Microsoft Word - 970617cppFinalSolution.doc

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

More information

C++11概要 ライブラリ編

C++11概要 ライブラリ編 C++11 Egtra 2012 6 23 1 Boost. #9 1.1 C++11 1.2 http://creativecommons.org/licenses/by-sa/2.1/jp/ - 2.1 2 Misc 2.1 C++11 unique_ptr shared_ptr // #include std::unique_ptr up(new int(1));

More information

untitled

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

More information

第5章修改稿

第5章修改稿 (Programming Language), ok,, if then else,(), ()() 5.0 5.0.0, (Variable Declaration) var x : T x, T, x,,,, var x : T P = x, x' : T P P, () var x:t P,,, yz, var x : int x:=2. y := x+z = x, x' : int x' =2

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

第一章

第一章 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1500 1450 1400 1350 1300 1250 1200 15 16 17 18 19 20 21 22 23 24 25 26 27 28 INPUT2006 29 30 31 32 33 34 35 9000 8500 8000 7500 7000 6500 6000 5500 5000 4500 4000 3500

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

Python a p p l e b e a r c Fruit Animal a p p l e b e a r c 2-2

Python a p p l e b e a r c Fruit Animal a p p l e b e a r c 2-2 Chapter 02 變數與運算式 2.1 2.1.1 2.1.2 2.1.3 2.1.4 2.2 2.2.1 2.2.2 2.2.3 type 2.2.4 2.3 2.3.1 print 2.3.2 input 2.4 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 + 2.4.6 Python Python 2.1 2.1.1 a p p l e b e a r c 65438790

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

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

内 容 提 要 指 针 持 久 动 态 内 存 分 配 字 符 串 ( 字 符 数 组 ) 2

内 容 提 要 指 针 持 久 动 态 内 存 分 配 字 符 串 ( 字 符 数 组 ) 2 第 六 讲 指 针 与 字 符 串 1 内 容 提 要 指 针 持 久 动 态 内 存 分 配 字 符 串 ( 字 符 数 组 ) 2 指 针 什 么 是 指 针 指 针 的 定 义 与 运 算 指 针 与 一 维 数 组 指 针 数 组 行 指 针 与 二 维 数 组 指 针 与 引 用 指 针 与 函 数 3 指 针 定 义 什 么 是 指 针 指 针 变 量, 简 称 指 针, 用 来 存 放

More information

Microsoft PowerPoint - Class5.pptx

Microsoft PowerPoint - Class5.pptx C++ 程式初探 V 2015 暑期 ver. 1.0.1 C++ 程式語言 大綱 1. 大量檔案讀取 & 計算 2. 指標 3. 動態記憶體 & 動態陣列 4. 標準函式庫 (STL) vector, algorithm 5. 結構與類別 2 大量檔案讀取 & 計算 若目前有一個程式將讀取純文字文件 (.txt) 中的整數, 並將該文件中的整數有小到大排序後, 儲存到另外一個新的純文字件中 假設有

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

数据结构与算法 - Python基础

数据结构与算法 - Python基础 Python 教材及课件 课件及作业见网址 xpzhang.me 1 1. Python 2. 3. (list) (tuple) 4. (dict) (set) 5. 6. 7. 2 Python Python 3 Python 4 Python 1, 100, -8080, 0,... 0x 0-9, a-f 0 xff00, 0 xa432bf 5 1.24, 3.14, -9.80,...

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

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

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

More information

新・解きながら学ぶC言語

新・解きながら学ぶC言語 330!... 67!=... 42 "... 215 " "... 6, 77, 222 #define... 114, 194 #include... 145 %... 21 %... 21 %%... 21 %f... 26 %ld... 162 %lf... 26 %lu... 162 %o... 180 %p... 248 %s... 223, 224 %u... 162 %x... 180

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

38 47995529 威 福 髮 藝 店 桃 園 市 蘆 竹 區 中 山 里 福 祿 一 街 48 號 地 下 一 樓 50,000 獨 資 李 依 純 105/04/06 府 經 登 字 第 1059003070 號 39 47995534 宏 品 餐 飲 桃 園 市 桃 園 區 信 光 里 民

38 47995529 威 福 髮 藝 店 桃 園 市 蘆 竹 區 中 山 里 福 祿 一 街 48 號 地 下 一 樓 50,000 獨 資 李 依 純 105/04/06 府 經 登 字 第 1059003070 號 39 47995534 宏 品 餐 飲 桃 園 市 桃 園 區 信 光 里 民 1 08414159 惠 鴻 眼 鏡 行 桃 園 市 中 壢 區 福 德 里 中 華 路 一 段 186 號 1 樓 30,000 獨 資 宋 耀 鴻 105/04/27 府 經 登 字 第 1059003866 號 2 17891110 承 元 冷 氣 空 調 工 程 行 桃 園 市 桃 園 區 中 德 里 國 際 路 1 段 98 巷 50 號 2 樓 之 4 200,000 獨 資 詹 安 平

More information

C

C C 2017 3 14 1. 2. 3. 4. 2/95 C 1. 3/95 C I 1 // talkback.c: 2 #include 3 #include 4 #define DENSITY 62.4 5 int main(void) 6 { 7 float weight, volume; 8 int size; 9 unsigned long letters;

More information

<4D6963726F736F667420576F7264202D20313034B0EABB79A4E5B8D5C344BBBCB065AAA9>

<4D6963726F736F667420576F7264202D20313034B0EABB79A4E5B8D5C344BBBCB065AAA9> 嘉 義 縣 104 年 新 港 溪 北 六 興 宮 正 黑 麵 三 媽 盃 小 六 學 藝 競 試 國 文 試 卷 一 一 般 選 擇 題 : 1. 下 列 選 項 中, 哪 一 組 字 的 讀 音 是 相 同 的?(A) 躡 足 / 攝 影 (B) 淒 慘 / 妻 兒 (C) 漠 不 關 心 / 眼 角 膜 (D) 韋 編 / 偉 人 2. 下 列 內 的 部 首, 何 者 正 確?(A) 黎 明

More information

凡 例 一 高 淳 县 历 史 悠 久, 文 物 古 迹 颇 丰, 为 全 面 系 统 地 保 存 各 类 文 物 资 料, 介 绍 文 物 工 作 情 况, 达 到 教 育 后 人, 提 供 专 业 研 究 的 目 的, 特 编 纂 本 志 二 本 志 采 用 记 志 述 图 表 等 多 种 体 裁, 翔 实 记 载 高 淳 县 自 旧 石 器 时 代 至 民 国 年 间 的 文 化 遗 存 文

More information

康體藝術

康體藝術 320 321 0.12% (340 ) 3.44% (1.001 ) 0.30% (860 ) 5.93% (7.542 ) 7.83% (2.277 ) ( 7,960 1,810 ) 3.36% (9,770 ) 9.08% (2.642 ) 20.27% (5.898 ) ( ) 29.67% (8.63 ) 322 π 323 324 325 326 327 328 329 330 331

More information

14 14 0 0 XV 13 13 0 0 2015 1 XV 13 13 0 0 2

14 14 0 0 XV 13 13 0 0 2015 1 XV 13 13 0 0 2 1398 2014 12 1 2014 12 8 14 113 13 13 0 0 2014 11 XV 1 14 14 0 0 XV 13 13 0 0 2015 1 XV 13 13 0 0 2 2015 1 XV 14 14 0 0 XV 14 14 0 0 3 XV 14 14 0 0 XV 14 14 0 0 14 14 0 0 2013 6 27 600 2015 12 31 4 2015

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

新・明解C言語入門編『索引』

新・明解C言語入門編『索引』 !... 75!=... 48 "... 234 " "... 9, 84, 240 #define... 118, 213 #include... 148 %... 23 %... 23, 24 %%... 23 %d... 4 %f... 29 %ld... 177 %lf... 31 %lu... 177 %o... 196 %p... 262 %s... 242, 244 %u... 177

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

( CIP) /. :, ( ) ISBN TP CIP ( 2005) : : : : * : : 174 ( A ) : : ( 023) : ( 023)

( CIP) /. :, ( ) ISBN TP CIP ( 2005) : : : : * : : 174 ( A ) : : ( 023) : ( 023) ( CIP) /. :, 2005. 2 ( ) ISBN 7-5624-3339-9.......... TP311. 1 CIP ( 2005) 011794 : : : : * : : 174 ( A ) :400030 : ( 023) 65102378 65105781 : ( 023) 65103686 65105565 : http: / /www. cqup. com. cn : fxk@cqup.

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

科学计算的语言-FORTRAN95

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

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

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++ 類 (Class Inheriance) : 料 ( 異 ), 類 料, 利 類 狀, 不 更 來 data membermember function 類 料 類 類 (Base class) 類, 類 類 (Derived class) 類 利 料 料, 料 不 料, 料 料, 留 類 類, 料, 類 來 類 列 更 類 數 例 : 類 數 類 料 例, String 類, 類 料, 串

More information

Microsoft Word - well_game.doc

Microsoft Word - well_game.doc 智慧型系統控制 趙春棠老師 四技機電四甲 49422019 黃秉宏 井字遊戲並沒有什麼必勝的著法, 但只要適當的回應, 就可保持不敗 也 1 2 3 4 5 6 7 8 9 法則 手玩家的最佳著法其第一步最好下在四個角落 ( 即 2 4 6 8 號位置 ), 因為後手玩家除了下在中央的 5 號位置之外必敗 即使對手下了該位置, 只要回以馬步佈局或對角佈局也還有一半的勝算 先手玩家第一步的次佳選擇在

More information