谁能给个这两道题要怎么做,做好有例子,用c++的语言,相似的题也可以,谢谢了
1个回答
展开全部
#include <iostream>
using namespace std;
/* this is a good example to use a pointer and
* a funtion pointer in practice
*/
int compare( int a, int b ) {
if ( a > b ) {
return a;
cout << "max = " << a << endl;
} else {
return b;
cout << "max = " << b << endl;
}
}
void show ( int (*p_com)(int,int), int a, int b ) {
cout << (*p_com)(a,b) << endl;
}
int main(int argc, char *argv[]) {
show( compare, 6,4 );
}
#include <iostream>
using namespace std;
/* this is a good example to use class
*/
class Datebase {
private:
int* p_a;
int size_a;
public:
Datebase ( int* ary, int size ): p_a(ary), size_a(size) {
cout << "initialize class Datebase\n";
}
void get_Datebase() {
for ( int i=0; i<size_a; i++ ) {
cout << *(p_a+i) << " ";
} cout << '\n';
}
void change_Datebase( int val, int item ) {
if ( item <= size_a ) {
*(p_a + item - 1) = val;
} else {
cout << item << " is out of array\n";
}
}
~Datebase() {
get_Datebase();
}
};
int main(int argc, char *argv[]) {
int ary[] = { 2, 5, 7, 9 };
Datebase array( ary, sizeof(ary)/sizeof(int) );
array.get_Datebase();
array.change_Datebase( 20, 2 );
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询