内容发布更新时间 : 2024/12/28 6:10:32星期一 下面是文章的全部内容请认真阅读。
C++突击题 2012-06-08
(答对得5分,其中构造函数3分,析构函数1分,studyFor()函数1分) 五、
1. 在class CCourse定义中增加一条: public:
virtual void studyFor() { cout << \ (答对得2分) 增加:
#include
char choice, instructor[10]; float credit; long id;
CCourse *p_course;
cout << \
cout << \ cout << \ cin >> choice;
cout << \ cin >> id;
cout << \ cin >> credit;
cout << \ cin >> instructor; switch (choice){ case '1':
p_course = new CHLP(id, \高级语言程序设计\ break; case '2':
p_course = new COOP(id, \面向对象程序设计\ break; default: exit(0); }
p_course->studyFor(); delete p_course; }
(答对得13分) 2.
#include
temp = a; a = b; b = temp;
-6-
C++突击题 2012-06-08
}
template
void bubbleSort(T a[], int n){ int i, j;
for (i=1; i < n; i++)
for (j=0; j < n-i; j++) if (a[j] > a[j+1])
swap(a[j], a[j+1]); }
template
void print(T1 a[], int n){ for (int i=0; i < n; i++) cout << a[i] << \ cout << endl; }
void main(){
int a[] = {2, 3, 1, 6, 43, 22};
double b[] = {2.3, 3.2, 1.6, -6.0, 4.3, 2.2}; print(a, 6);
bubbleSort(a, 6); print(a, 6); print(b, 6);
bubbleSort(b, 6); print(b, 6); (答对得15分)
-7-