65,211
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
template <typename T>
T showarray(T arr[],int n);
template <typename T>
T showarray(T *arr[],int n);
struct debts
{
char name[50];
double amount;
};
int mian()
{
using namespace std;
int things[6]={13,31,103,301,310,130};
struct debts mr_e[3]=
{
{"Ima Wolfe",2400.0},
{"Ura Foxe",1300.0},
{"Iby Stout",1800.0}
};
double *pd[3];
for(int i=0;i<3;i++)
pd[i]=&mr_e[i].amount;
cout<<"Listing Mr.E's couts of things: \n";
cout<<"total"<<showarray(things,6); //use templateA
cout<<"Listing Mr.E's debts: \n";
cout<<"total"<<showarray(pd,3);//tamplateB
return 0;
}
template <typename T>
T showarray(T arr[],int n)
{
using namespace std;
cout<<"template A\n";
T total=0;
for(int i=0;i<n;i++)
total=total+arr[i];
return total;
}
template <typename T>
T showarray(T *arr[],int n)
{
using namespace std;
cout<<"template B\n";
T total=0;
for(int i=0;i<n;i++)
total=total+ *arr[i];
return total;
}
int mian()
{