Advertisement
mcgizmo

Untitled

Dec 4th, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.72 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #define N 2
  5. #define SIZE 20
  6. typedef struct
  7. {
  8. char car_type[SIZE];
  9. int car_number;
  10. float car_weight;
  11. }car;
  12. car carinfo[N];
  13. car *sortinfo;
  14.  
  15. typedef struct
  16. {
  17. int parking[N];
  18. int enterenc[N];
  19. int top;
  20.  
  21. }stack;
  22. typedef struct
  23. {
  24. car carinfo[N];
  25. stack st;
  26. }intel_parking;
  27. intel_parking israel;
  28. void sortcarinfo(car item[], int n);
  29. void getinfo(car info[], int n);
  30. void pushparkstack(car item[], int n);
  31. int pop(car item2[], int n);
  32. void main()
  33. {
  34.  
  35. int temp;
  36. getinfo(carinfo, N);
  37. sortcarinfo(carinfo, N);
  38. pushparkstack(carinfo, N-1);
  39. temp = pop(carinfo, 0);
  40. }
  41. void getinfo(car info[], int n)
  42. {
  43.  
  44. int i, len;
  45. printf("Enter details about the cars that allowed to park:\n");
  46. for (i = 0; i < n; i++)
  47. {
  48. do{
  49. _flushall();
  50. printf("Enter type of the car:\n");
  51. gets(info[i].car_type);
  52.  
  53. } while (len = strlen(info[i].car_type) >= 20);
  54.  
  55. do{
  56. _flushall();
  57. printf("Enter car number (MUST BE A NUMBER ASSEMBLED BY 7 DIGITS):\n");
  58. scanf("%d", &info[i].car_number);
  59.  
  60. } while (info[i].car_number<1000000 || info[i].car_number>9999999);
  61.  
  62. do{
  63. _flushall();
  64. printf("Enter a car weight (in tons one tons and heigher):\n");
  65. scanf("%f", &info[i].car_weight);
  66.  
  67. } while (info[i].car_weight<1.0);
  68.  
  69. }
  70.  
  71. }
  72. void pushparkstack(car item[],int n) {
  73. israel.st.top++;
  74. israel.st.parking[israel.st.top] = item[n].car_weight;
  75. }
  76. int pop(car item2[], int n) {
  77. int item;
  78. item = item2[n].car_number;
  79. israel.st.parking[israel.st.top];
  80. israel.st.top--;
  81.  
  82. return (item);
  83. }
  84.  
  85. void sortcarinfo(car item[], int n)
  86. {
  87. int i, j;
  88. car *sortinfo = (car *)malloc(1*sizeof(car));
  89. if (!sortinfo)
  90. {
  91. printf("error\n");
  92. exit(1);
  93. }
  94. for (i = 0; i < n; i++)
  95. {
  96. for (j = 0; j < n - j - 1; j++)
  97. {
  98. if (item[j].car_weight > item[j + 1].car_weight)
  99. {
  100.  
  101. sortinfo[0].car_weight = item[j].car_weight;
  102. sortinfo[0].car_number = item[j].car_number;
  103. strcpy(sortinfo[0].car_type,item[j].car_type);
  104. item[j].car_weight = item[j+1].car_weight;
  105. item[j].car_number = item[j+1].car_number;
  106. strcpy(item[j].car_type,item[j+1].car_type);
  107. item[j+1].car_weight = sortinfo[0].car_weight;
  108. item[j+1].car_number = sortinfo[0].car_number;
  109. strcpy(item[j+1].car_type,sortinfo[0].car_type);
  110.  
  111.  
  112. }
  113. }
  114. }
  115. free(sortinfo);
  116.  
  117. }
  118.  
  119. #include <stdio.h>
  120. #include <stdlib.h>
  121. #include <string.h>
  122. #define N 2
  123. #define SIZE 20
  124. typedef struct
  125. {
  126. char car_type[SIZE];
  127. int car_number;
  128. float car_weight;
  129. }car;
  130. car carinfo[N];
  131. car *sortinfo;
  132.  
  133. typedef struct
  134. {
  135. int parking[N];
  136. int enterenc[N];
  137. int top;
  138.  
  139. }stack;
  140. typedef struct
  141. {
  142. car carinfo[N];
  143. stack st;
  144. }intel_parking;
  145. intel_parking israel;
  146. void sortcarinfo(car item[], int n);
  147. void getinfo(car info[], int n);
  148. void pushparkstack(car item[], int n);
  149. int pop(car item2[], int n);
  150. void main()
  151. {
  152.  
  153. int temp;
  154. getinfo(carinfo, N);
  155. sortcarinfo(carinfo, N);
  156. pushparkstack(carinfo, N-1);
  157. temp = pop(carinfo, 0);
  158. }
  159. void getinfo(car info[], int n)
  160. {
  161.  
  162. int i, len;
  163. printf("Enter details about the cars that allowed to park:\n");
  164. for (i = 0; i < n; i++)
  165. {
  166. do{
  167. _flushall();
  168. printf("Enter type of the car:\n");
  169. gets(info[i].car_type);
  170.  
  171. } while (len = strlen(info[i].car_type) >= 20);
  172.  
  173. do{
  174. _flushall();
  175. printf("Enter car number (MUST BE A NUMBER ASSEMBLED BY 7 DIGITS):\n");
  176. scanf("%d", &info[i].car_number);
  177.  
  178. } while (info[i].car_number<1000000 || info[i].car_number>9999999);
  179.  
  180. do{
  181. _flushall();
  182. printf("Enter a car weight (in tons one tons and heigher):\n");
  183. scanf("%f", &info[i].car_weight);
  184.  
  185. } while (info[i].car_weight<1.0);
  186.  
  187. }
  188.  
  189. }
  190. void pushparkstack(car item[],int n) {
  191. israel.st.top++;
  192. israel.st.parking[israel.st.top] = item[n].car_weight;
  193. }
  194. int pop(car item2[], int n) {
  195. int item;
  196. item = item2[n].car_number;
  197. israel.st.parking[israel.st.top];
  198. israel.st.top--;
  199.  
  200. return (item);
  201. }
  202.  
  203. void sortcarinfo(car item[], int n)
  204. {
  205. int i, j;
  206. car *sortinfo = (car *)malloc(1*sizeof(car));
  207. if (!sortinfo)
  208. {
  209. printf("error\n");
  210. exit(1);
  211. }
  212. for (i = 0; i < n; i++)
  213. {
  214. for (j = 0; j < n - j - 1; j++)
  215. {
  216. if (item[j].car_weight > item[j + 1].car_weight)
  217. {
  218.  
  219. sortinfo[0].car_weight = item[j].car_weight;
  220. sortinfo[0].car_number = item[j].car_number;
  221. strcpy(sortinfo[0].car_type,item[j].car_type);
  222. item[j].car_weight = item[j+1].car_weight;
  223. item[j].car_number = item[j+1].car_number;
  224. strcpy(item[j].car_type,item[j+1].car_type);
  225. item[j+1].car_weight = sortinfo[0].car_weight;
  226. item[j+1].car_number = sortinfo[0].car_number;
  227. strcpy(item[j+1].car_type,sortinfo[0].car_type);
  228.  
  229.  
  230. }
  231. }
  232. }
  233. free(sortinfo);
  234.  
  235. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement