主题:[讨论]二级指针的问题
#include "stdafx.h"
#include "iostream"
#include "string"
using namespace std;
class subject
{
public:
/* char *set(char **p)
{
return *p;
}
*/
void three_average(int p[][4],int n,char **ptr)
{
int sum=0,i=0;
switch(**ptr)
{
case "chinese":
for(;i<n;i++)
sum+=p[i][0]+0;
break;
case "math":
for(;i<n;i++)
sum+=p[i][0]+1;
break;
case "english":
for(;i<n;i++)
sum+=p[i][0]+2;
break;
case "PE":
for(;i<n;i++)
sum+=p[i][0]+3;
break;
default:
cout<<"no expression";
break;
}
cout<<sum<<endl;
}
};
int main(int argc, char* argv[])
{
char *b[4]={"chinese","math","english","PE"};
int a[3][4]={{1,2,3,4},{5,6,7,8},{9,10,11,12}};
subject s;
for(int i=0;i<sizeof(b)/sizeof(char*);i++)
s.three_average(a,3,b+i);
return 0;
}
高手帮忙解决呀?
#include "iostream"
#include "string"
using namespace std;
class subject
{
public:
/* char *set(char **p)
{
return *p;
}
*/
void three_average(int p[][4],int n,char **ptr)
{
int sum=0,i=0;
switch(**ptr)
{
case "chinese":
for(;i<n;i++)
sum+=p[i][0]+0;
break;
case "math":
for(;i<n;i++)
sum+=p[i][0]+1;
break;
case "english":
for(;i<n;i++)
sum+=p[i][0]+2;
break;
case "PE":
for(;i<n;i++)
sum+=p[i][0]+3;
break;
default:
cout<<"no expression";
break;
}
cout<<sum<<endl;
}
};
int main(int argc, char* argv[])
{
char *b[4]={"chinese","math","english","PE"};
int a[3][4]={{1,2,3,4},{5,6,7,8},{9,10,11,12}};
subject s;
for(int i=0;i<sizeof(b)/sizeof(char*);i++)
s.three_average(a,3,b+i);
return 0;
}
高手帮忙解决呀?