3 回答
TA贡献1829条经验 获得超7个赞
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 | // baiduzhidao02.cpp : Defines the entry point for the console application. //
#include "stdafx.h" #include <stdio.h>
class MyClass { public: MyClass(){}; ~MyClass(){};
void Print(int a) { printf("int类型:%d\n", a); }; void Print(float a) { printf("float类型:%f\n", a); } void Print(double a) { printf("double类型:%f\n", a); } void Print(int a[]) { int size = sizeof(a) - 1; for (int i = 0; i < size; i++) { Print(a[i]); } } void Print(float a[]) { int size = sizeof(a) - 1; for (int i = 0; i < size; i++) { Print(a[i]); } } void Print(double a[]) { int size = sizeof(a) - 1; for (int i = 0; i < size; i++) { Print(a[i]); } } };
int main(int argc, char* argv[]) { int a = 520; float b = 521.0; double c = 522.0;
int array1[] = { 1, 2, 3 }; float array2[] = { 4.0, 5.0, 6.0 }; double array3[] = { 7.0, 8.0, 9.0 };
MyClass myclass; //输出a,b,c myclass.Print(a); myclass.Print(b); myclass.Print(c);
//输出array1,array2,array3 myclass.Print(array1); myclass.Print(array2); myclass.Print(array3);
return 0; } |
TA贡献1752条经验 获得超4个赞
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 | class MyClass { public: Print(int x){ printf("%d\n",x); } Print(float x){ printf("%f\n",x); } Print(double x){ printf("%lf\n",x); } Print(int* x,int n) { for(int i=0;i<n;i++) { printf("%d\n",*x);x++; } } Print(float* x,int n) { for(int i=0;i<n;i++) { printf("%f\n",*x);x++; } } Print(double* x,int n) { for(int i=0;i<n;i++) { printf("%lf\n",*x);x++; } } };
main() { int a=3;float b=3.14;double c=1.414; int e[]={1,2,3,4}; float f[]={1.23,2.34,3.45}; double g[]={9.87,8.76,7.65,6.54}; MyClass my; my.Print(a); my.Print(b); my.Print(c); my.Print(e,sizeof(e)/sizeof(int)); my.Print(f,sizeof(f)/sizeof(float)); my.Print(g,sizeof(g)/sizeof(double)); } |
- 3 回答
- 0 关注
- 851 浏览
添加回答
举报