鱼C论坛

 找回密码
 立即注册
查看: 2671|回复: 10

[已解决]关于数组的问题。本人小白一个。

[复制链接]
发表于 2019-6-6 19:55:32 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. float Judgepropensity_granularity(int a, int b, int c)
  2. {
  3.     float table[4][3][3] =
  4.     {
  5.         {{0.0,0.0,0.0}, {0.0,0.0,0.1}, {0.1,0.1,0.2}},
  6.         {{0.1,0.1,0.2}, {0.2,0.3,0.4}, {0.4,0.5,0.6}},
  7.         {{0.4,0.5,0.6}, {0.5,0.6,0.7}, {0.8,0.9,1.0}},
  8.         {{0.9,0.9,1.0}, {1.0,1.0,1.0}, {1.0,1.0,1.0}}
  9.     };
  10.         return table[a][b][c];
  11. }


  12. /*
  13.     以整数代表倾向性类型
  14.     0----保守型
  15.     1----普通型
  16.     2----激进型
  17. */
复制代码

大佬们,这是一个评分表,0.1-0.3表示保守型,0.4-0.6普通型,0.7-1激进型,接下来该怎么写,用到哪方面的知识?
最佳答案
2019-6-7 13:40:59
哈蛤哈 发表于 2019-6-6 21:29
大佬,运行到84行的时候,报错undefined reference to ‘propensity_propensity_quantification’,这个 ...

这个代码有好多问题,一两句话说不完
qq: 1440332527
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-6-6 20:07:21 | 显示全部楼层
说一说你这个程序想要实现什么功能?
Judgepropensity_granularity这个函数期望完成什么功能?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-6-6 20:12:01 | 显示全部楼层
人造人 发表于 2019-6-6 20:07
说一说你这个程序想要实现什么功能?
Judgepropensity_granularity这个函数期望完成什么功能?

Judgepropensity_granularity这个函数是根据前边的一些参数的的出的下边那个数组,就是评分表,然后根据分数进行分类,,大概就是这样
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-6-6 20:39:57 | 显示全部楼层
哈蛤哈 发表于 2019-6-6 20:12
Judgepropensity_granularity这个函数是根据前边的一些参数的的出的下边那个数组,就是评分表,然后根据 ...

完全不知道你想要做什么,把你的代码贴完整
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-6-6 20:42:39 | 显示全部楼层
人造人 发表于 2019-6-6 20:39
完全不知道你想要做什么,把你的代码贴完整
  1. #include <stdio.h>
  2. #include <math.h>

  3. //全局变量定义
  4. #define d1 0.61
  5. #define d2 0.93
  6. #define d3 1.4
  7. #define d4 2.55
  8. #define vp 1.4
  9. #define vpMAX 2.9
  10. #define f1=100
  11. #define f2=115

  12. /*
  13. 构建前方步行区域结构体
  14. */
  15. struct Front
  16. {
  17.         float velocity;//跟随状态前方步行者步行速度
  18.         int type;//0为跟随状态,1为非跟随状态
  19.         int distance_range;//距离范围
  20.         int rel_v_range;//相对速度范围
  21.         float PPSgranularity;//倾向性粒度
  22. }frt;

  23. float pedestrian_velocity;//目标步行者当前速度
  24. float Reldistance;//相对距离
  25. float Relvelocity;//相对速度
  26. int pedestrian_velocity_range;//目标步行者速度范围
  27. int frequency;//非跟随状态目标步行者步频
  28. int c1, c2, c3;
  29. int PPStype;//倾向性类型


  30. int JudgeVelocityRange(float a);//速度范围判断
  31. int JudgefrequencyRange(float a);//步频范围判断
  32. int JudgedistanceRange(float a);//距离范围判断
  33. int JudgeRelVelocityRange(float a);//相对速度范围判断
  34. float propensity_quantification(int a, int b, int c);//倾向性量化
  35. void Input(void);//输入
  36. void Judge(void);//判断
  37. void IdentifyPropensity(void);//倾向性判断

  38. int main()
  39. {
  40.     Input();
  41.     Judge();
  42.     IdentifyPropensity();
  43.     return 0;
  44. }

  45. void Input(void)
  46. {
  47.     printf("目标步行者是否处于跟随状态:(0:处于跟随状态,1:处于非跟随状态)\n");
  48.     scanf("%d",&frt.type);
  49.     pedestrian_velocity_range = JudgeVelocityRange(pedestrian_velocity);
  50.     if (frt.type == 0)
  51.         {
  52.             printf("目标步行者的步行速度为:   m/s\n");
  53.             scanf("%f",&pedestrian_velocity);
  54.             printf("与前方步行者的间距为:   m\n");
  55.             scanf("%f",&Reldistance);
  56.             printf("前方步行者的步行速度为:   m/s\n");
  57.             scanf("%f",&frt.velocity);
  58.         }
  59.         else if (frt.type == 1)
  60.         {
  61.             printf("目标步行者的步频为   步/min\n");
  62.             scanf("%d",&frequency);
  63.         }

  64. }

  65. void Judge(void)
  66. {
  67.     if (frt.type == 0)
  68.     {
  69.         JudgedistanceRange(Reldistance);
  70.         Relvelocity = pedestrian_velocity - frt.velocity;
  71.         JudgeRelVelocityRange(Relvelocity);
  72.         c1 = frt.distance_range;
  73.         c2 = frt.rel_v_range;
  74.         c3 = pedestrian_velocity_range;
  75.         frt.PPSgranularity = propensity_quantification(c1, c2, c3);
  76.     }
  77.     else
  78.         JudgefrequencyRange(frequency);
  79. }

  80. /*
  81.         整数代表速度范围
  82.         0----慢
  83.         1----居中
  84.         2----快
  85. */

  86. int JudgeVelocityRange(float a)
  87. {
  88.         if (a < vp / 2)
  89.                 return 0;
  90.         else if (a < (vp + vpMAX) / 2)
  91.                 return 1;
  92.         else
  93.                 return 2;
  94. }


  95. /*
  96.         以整数代表距离范围
  97.         0----危险
  98.         1----近
  99.         2----中
  100.         3----远
  101. */

  102. int JudgedistanceRange(float a)
  103. {
  104.         float a1,a2,a3;
  105.         a1 = (d1 + d2) / 2;
  106.         a2 = (d2 + d3) / 2;
  107.         a3 = (d3 + d4) / 2;
  108.         if (Reldistance < a1)
  109.         a = 0;
  110.     else if (Reldistance < a2)
  111.         a = 1;
  112.     else if (Reldistance < a3)
  113.         a = 2;
  114.     else
  115.         a = 3;
  116. }

  117. /*
  118.         以整数代表相对速度范围
  119.         0----负
  120.         1----零
  121.         2----正
  122. */

  123. int JudgeRelVelocityRange(float a)
  124. {
  125.     if (a < 0)
  126.         return 0;
  127.     else if (a == 0)
  128.         return 1;
  129.     else
  130.         return 2;
  131. }

  132. /*
  133.         用3维数组存储评分表并打分
  134. */

  135. float Judgepropensity_granularity(int a, int b, int c)
  136. {
  137.     float table[4][3][3] =
  138.     {
  139.         {{0.0, 0.0, 0.0}, {0.0, 0.0, 0.1}, {0.1, 0.1, 0.2}},
  140.         {{0.1, 0.1, 0.2}, {0.2, 0.3, 0.4}, {0.4, 0.5, 0.6}},
  141.         {{0.4, 0.5, 0.6}, {0.5, 0.6, 0.7}, {0.8, 0.9, 1.0}},
  142.         {{0.9, 0.9, 1.0}, {1.0, 1.0, 1.0}, {1.0, 1.0, 1.0}}
  143.     };
  144.         return table[a][b][c];
  145. }


  146. /*
  147.     以整数代表倾向性类型
  148.     0----保守型
  149.     1----普通型
  150.     2----激进型
  151. */
  152. void IdentifyPropensity(void)
  153. {
  154.    
  155. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-6-6 20:43:19 | 显示全部楼层
人造人 发表于 2019-6-6 20:39
完全不知道你想要做什么,把你的代码贴完整

目前就写了这些,也不知道有多少错误、。、、、、
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-6-6 20:48:43 | 显示全部楼层
哈蛤哈 发表于 2019-6-6 20:43
目前就写了这些,也不知道有多少错误、。、、、、

你期望这个程序实现什么样的功能?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-6-6 20:55:53 | 显示全部楼层
人造人 发表于 2019-6-6 20:48
你期望这个程序实现什么样的功能?

根据我输入的参数,判断步行者运动的倾向性?我该怎么说。。。。现在我就是不知道怎么根据数组内的评分,把分数分为三类。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-6-6 21:25:42 | 显示全部楼层
  1. #include <stdio.h>
  2. #include <math.h>

  3. //全局变量定义
  4. #define d1 0.61
  5. #define d2 0.93
  6. #define d3 1.4
  7. #define d4 2.55
  8. #define vp 1.4
  9. #define vpMAX 2.9
  10. #define f1 100
  11. #define f2 115

  12. /*
  13. 构建前方步行区域结构体
  14. */
  15. struct Front
  16. {
  17.         float velocity;//跟随状态前方步行者步行速度
  18.         int type;//0为跟随状态,1为非跟随状态
  19.         int distance_range;//距离范围
  20.         int rel_v_range;//相对速度范围
  21.         float PPSgranularity;//倾向性粒度
  22. }frt;

  23. float pedestrian_velocity;//目标步行者当前速度
  24. float Reldistance;//相对距离
  25. float Relvelocity;//相对速度
  26. int pedestrian_velocity_range;//目标步行者速度范围
  27. int frequency;//非跟随状态目标步行者步频
  28. int c1, c2, c3;
  29. int PPStype;//倾向性类型


  30. int JudgeVelocityRange(float a);//速度范围判断
  31. int JudgefrequencyRange(float a);//步频范围判断
  32. int JudgedistanceRange(float a);//距离范围判断
  33. int JudgeRelVelocityRange(float a);//相对速度范围判断
  34. float propensity_quantification(int a, int b, int c);//倾向性量化
  35. void Input(void);//输入
  36. void Judge(void);//判断
  37. void IdentifyPropensity(void);//倾向性判断

  38. int main()
  39. {
  40.     Input();
  41.     Judge();
  42.     IdentifyPropensity();
  43.     return 0;
  44. }

  45. void Input(void)
  46. {
  47.     printf("目标步行者是否处于跟随状态:(0:处于跟随状态,1:处于非跟随状态)\n");
  48.     scanf("%d",&frt.type);
  49.     pedestrian_velocity_range = JudgeVelocityRange(pedestrian_velocity);
  50.     if (frt.type == 0)
  51.         {
  52.             printf("目标步行者的步行速度为:   m/s\n");
  53.             scanf("%f",&pedestrian_velocity);
  54.             printf("与前方步行者的间距为:   m\n");
  55.             scanf("%f",&Reldistance);
  56.             printf("前方步行者的步行速度为:   m/s\n");
  57.             scanf("%f",&frt.velocity);
  58.         }
  59.         else if (frt.type == 1)
  60.         {
  61.             printf("目标步行者的步频为   步/min\n");
  62.             scanf("%d",&frequency);
  63.         }

  64. }

  65. void Judge(void)
  66. {
  67.     if (frt.type == 0)
  68.     {
  69.         JudgedistanceRange(Reldistance);
  70.         Relvelocity = pedestrian_velocity - frt.velocity;
  71.         JudgeRelVelocityRange(Relvelocity);
  72.         c1 = frt.distance_range;
  73.         c2 = frt.rel_v_range;
  74.         c3 = pedestrian_velocity_range;
  75.         frt.PPSgranularity = propensity_quantification(c1, c2, c3);
  76.     }
  77.     else
  78.         JudgefrequencyRange(frequency);
  79. }

  80. /*
  81.         整数代表速度范围
  82.         0----慢
  83.         1----居中
  84.         2----快
  85. */

  86. int JudgeVelocityRange(float a)
  87. {
  88.         if (a < vp / 2)
  89.                 return 0;
  90.         else if (a < (vp + vpMAX) / 2)
  91.                 return 1;
  92.         else
  93.                 return 2;
  94. }


  95. /*
  96.         以整数代表距离范围
  97.         0----危险
  98.         1----近
  99.         2----中
  100.         3----远
  101. */

  102. int JudgedistanceRange(float a)
  103. {
  104.         float a1,a2,a3;
  105.         a1 = (d1 + d2) / 2;
  106.         a2 = (d2 + d3) / 2;
  107.         a3 = (d3 + d4) / 2;
  108.         if (Reldistance < a1)
  109.         a = 0;
  110.     else if (Reldistance < a2)
  111.         a = 1;
  112.     else if (Reldistance < a3)
  113.         a = 2;
  114.     else
  115.         a = 3;
  116. }

  117. /*
  118.         以整数代表相对速度范围
  119.         0----负
  120.         1----零
  121.         2----正
  122. */

  123. int JudgeRelVelocityRange(float a)
  124. {
  125.     if (a < 0)
  126.         return 0;
  127.     else if (a == 0)
  128.         return 1;
  129.     else
  130.         return 2;
  131. }

  132. /*
  133.         用3维数组存储评分表并打分
  134. */

  135. float Judgepropensity_granularity(int a, int b, int c)
  136. {
  137.     float table[4][3][3] =
  138.     {
  139.         {{0.0, 0.0, 0.0}, {0.0, 0.0, 0.1}, {0.1, 0.1, 0.2}},
  140.         {{0.1, 0.1, 0.2}, {0.2, 0.3, 0.4}, {0.4, 0.5, 0.6}},
  141.         {{0.4, 0.5, 0.6}, {0.5, 0.6, 0.7}, {0.8, 0.9, 1.0}},
  142.         {{0.9, 0.9, 1.0}, {1.0, 1.0, 1.0}, {1.0, 1.0, 1.0}}
  143.     };
  144.         return table[a][b][c];
  145. }


  146. int JudgefrequencyRange(float a)
  147. {
  148.    if (a <= f1)
  149.    {
  150.        printf("该步行者的运动倾向性为保守型/n");
  151.    }
  152.    else if (a <= f2 && a>f1)
  153.    {
  154.        printf("该步行者的运动倾向性为普通型/n");
  155.    }
  156.    else
  157.     {
  158.         printf ("该步行者的运动倾向性为激进型/n");
  159.     }
  160. }


  161. /*
  162.     以整数代表倾向性类型
  163.     0----保守型
  164.     1----普通型
  165.     2----激进型
  166. */
  167. void IdentifyPropensity(void)
  168. {
  169.     if (frt.PPSgranularity >= 0.1 && frt.PPSgranularity <= 0.3)
  170.         {
  171.             printf("该步行者的运动倾向性为保守型/n");
  172.         }
  173.     else if (frt.PPSgranularity >= 0.4 && frt.PPSgranularity <= 0.6)
  174.         {
  175.             printf("该步行者的运动倾向性为普通型/n");
  176.         }
  177.     else
  178.     {
  179.         printf ("该步行者的运动倾向性为激进型/n");
  180.     }
  181. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-6-6 21:29:20 | 显示全部楼层
哈蛤哈 发表于 2019-6-6 20:55
根据我输入的参数,判断步行者运动的倾向性?我该怎么说。。。。现在我就是不知道怎么根据数组 ...

大佬,运行到84行的时候,报错undefined reference to ‘propensity_propensity_quantification’,这个可以帮助解决吗
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-6-7 13:40:59 | 显示全部楼层    本楼为最佳答案   
哈蛤哈 发表于 2019-6-6 21:29
大佬,运行到84行的时候,报错undefined reference to ‘propensity_propensity_quantification’,这个 ...

这个代码有好多问题,一两句话说不完
qq: 1440332527
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-5-16 17:26

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表