• 关于数组的应用问题.
  • 其它

#include
#include
using namespace std;
char date(char x)
{
/*形容词库*/
char d[24][15]={{"optimistic"},{"independent"},{"out-going"},
{"active-able"},{"aggressive"},{"ambitious"},{"amiable"},
{"amicable"},{"analytical"},{"adaptable"},{"active"}

,{"apprehensive"},{"aspiring"} ,{"audacious"}

,{"capable"},{"careful"} ,{"candid"},{"competent"}
,{"constructive"} ,{"cooperative"} ,{"creative"}
,{"humorous"},{"impartial"},{"beautiful"}};
int k;
char u;
k=(int)x-97;

/*这里是想把传过来的字符转成从0开始的数字,然后从二维数组里调形容词出来*/
u=d[k][15];
return u;
/*试图把拉出来的形容词传回去*/
}

int main()
{
char a[5],c[5],d[25]="and";
char m,n,t;
cout<<"You are boy or girl ?"< cin>>c;
cout<<"what's your name ?"< cin>>a;
m=a[0];n=a[1];t=a[2];
/*把输入的名字三个字母分开处理*/
char b[50]={date(m)};
char e[55]={date(n)};
char f[15]={date(t)};
/*拼接得到的形容词*/
strcat(b,strcat(e,strcat(d,f)));
cout<<"I think you are"<<b<<c<<endl;
system("pause");
return 0;
}

这个程序设计的是输入一个名字,如abc,将他分成a,b,c,然后按照字母的位次依次得到一个形容词,最后将他们依次平在一起,但是最后形容词无法输出。
初学数组,对数组使用的规则很不清楚,希望大佬们多多指教。


  • 就几件    2020-04-03 15:40:43
  • 阅读 764    收藏 0    回答 1
  • 邀请
  • 收藏
  • 分享
发送
登录 后发表评论
  • 51testing软件测试圈微信