我是靠谱客的博主 唠叨香菇,这篇文章主要介绍C++面向对象程序设计编程题答案,现在分享给大家,希望可以做个参考。

复制代码
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
## C++面向对象程序设计编程题答案 自己练习c++时写的一些代码供大家参考,如有错误请大家指出 //1 /* float x, y; cin >> x; if (x < 1)y = x; else if (x >= 1 && x <= 10)y = 2 * x - 1; else y = 3 * x - 11; cout << y << endl; system("pause"); */ //2 /* int i = 0, start; for (start = 100;start < 1000;start++) if ((start % 10 + start / 10 % 10 + start / 100) % 2 == 0) i++; cout << i << endl; system("pause"); */ //3 /* int a,n=0; cin >> a; while (a != 0) { a /= 10; n++; } cout << n; system("pause"); */ //4 /* int n; cin >> n; for (int i = 1;i <= n;i++) { for (int j = 0;j < n - i;j++) cout << ' '; for (int j = 0;j < 2 * i - 1;j++) cout << i; cout << endl; } system("pause"); */ //5 /* int n; cin >> n; for (int i = 1;i <= n;i++) { for (int j = 0;j < n - i;j++) cout << ' '; for (int j = 0;j < 2 * i - 1;j++) cout << '*'; cout << endl; } for (int i = 1;i < n;i++) { cout << " "; for (int j = 0;j < 2 * n - 5;j++) cout << '*'; cout << endl; } system("pause"); */ //6 /* int n; int sum=0; int num=1; cin >> n; for (int i = 1;i <= n;i++) { num *= i; sum += num; } cout << sum; system("pause"); */ //6 /* int n = 2, i = 3, j = 2; while (n < 500) { cout <<"n:"<< n <<"i:"<<i<<"j:"<<j<< endl; n += 3; i += 5; j += 7; } system("pause"); */ //7 /* int num = 0; int k = 0; for(int i=0;i<=10;i++) for (int j = 0;j <= (100 - 10 * i) /5 ;j++) { k = 100 - 10 * i - 5 * j; cout << "i:" << i << "j:" << j << "k:" << k << endl; } system("pause"); */ //9 /* const char*str1 = "ABCDE"; const char*str2 = "JKLMN"; for (int i = 0;i < 5;i++) for (int j = 0;j < 5;j++) if ((i == 0 && j == 0) || (j == 0 && (i == 3 || i == 4))) continue; else cout << "甲队:" << str1[i] << " vs " << "乙队:" << str2[j] << endl; system("pause"); */ //10 /* const char*p[5] = { "zhang","wang","li","zhao","弃权:" }; int n[5] = {0,0,0,0,0}; HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); cout << "zhang:" << n[0] << " wang:" << n[1] << " li:" << n[2] << " zhao:" << n[3]<<" 弃权:"<<n[4]<<endl; cout << "您的选择的是:" << endl; COORD pos[6] = {6,0,13,0,18,0,25,0,13,1,32,0}; cout << endl; int flag; SetConsoleCursorPosition(hOut, pos[4]); cin >> flag; SetConsoleCursorPosition(hOut, pos[4]); cout << ' '; while (flag != -1) { if (flag > 0 && flag < 5) { n[flag - 1]++; SetConsoleCursorPosition(hOut, pos[flag-1]); cout << n[flag - 1]; } else { n[4]++; SetConsoleCursorPosition(hOut, pos[5]); cout << n[4]; } SetConsoleCursorPosition(hOut, pos[4]); cin >> flag; SetConsoleCursorPosition(hOut, pos[4]); cout << ' '; } system("pause"); */ //10 /* int *pArr = new int[5]{1,2,3,4,5}; int n = 1; int temp; temp = n; n = pArr[3]; pArr[3] = temp; for (int i = 0;i < 5;i++) cout << pArr[i] << endl; system("pause"); */

最后

以上就是唠叨香菇最近收集整理的关于C++面向对象程序设计编程题答案的全部内容,更多相关C++面向对象程序设计编程题答案内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(46)

评论列表共有 0 条评论

立即
投稿
返回
顶部