Advertisement
Guest User

Rekordy

a guest
Jan 9th, 2012
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.45 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. typedef struct Car{
  4. char Mark[10];
  5. int ID, model, mileage, currentREPAIRS, archiveREPAIRS;
  6. } Car[30];
  7.  
  8.  
  9. typedef struct Service {
  10. char FULLname[20];
  11. int ID, repairTIMES, SERVICEhistory;
  12. } Service[30][10];
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22. struct Car *p[30];
  23. struct Service *r[30][10];
  24.  
  25. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  26.  
  27.  
  28. void add(int n, int z, int *T)
  29. {
  30. int e=0;
  31.  
  32. p[n-1] = malloc(sizeof(Car));
  33. char CID[10], mark[10], model[10], mileage[10], rep[10], archive[10], RID[10], name[10], reptime[10], history[10], amount[10];
  34. printf("What is car ID?\n");
  35. fgets(CID, sizeof(CID), stdin);
  36. p[n-1] -> ID = atoi(CID);
  37. fflush(stdin);
  38. printf("What is car Mark?\n");
  39. scanf("%s", p[n-1] -> Mark);
  40. fflush(stdin);
  41. printf("What is car Model?\n");
  42. fgets(model, sizeof(model), stdin);
  43. p[n-1] -> model = atoi(model);
  44. fflush(stdin);
  45. printf("What is car Mileage?\n");
  46. fgets(mileage, sizeof(mileage), stdin);
  47. p[n-1] -> mileage = atoi(mileage);
  48. fflush(stdin);
  49. printf("What is car CurrReapir?\n");
  50. fgets(rep, sizeof(rep), stdin);
  51. p[n-1] -> currentREPAIRS = atoi(rep);
  52. fflush(stdin);
  53. printf("How many repiars did it have?\n");
  54. fgets(amount, sizeof(amount),stdin);
  55. printf("What is car AoRepairs?\n");
  56. fgets(archive, sizeof(archive), stdin);
  57. T[n-1]= atoi(amount);
  58. p[n-1] -> archiveREPAIRS = atoi(archive);
  59. fflush(stdin);
  60. for(e=0; e<T[n-1]; e++)
  61. {
  62. r[n-1][e] = malloc(sizeof(Service));
  63. r[n-1][e] = malloc(sizeof(Service));
  64. printf("What is repair ID?\n");
  65. fgets(RID, sizeof(RID), stdin);
  66. r[n-1][e] -> ID = atoi(RID);
  67. fflush(stdin);
  68. printf("What is repair name?\n");
  69. scanf("%s", r[n-1][e] -> FULLname);
  70. fflush(stdin);
  71. printf("What is repair RepTime?\n");
  72. fgets(reptime, sizeof(reptime), stdin);
  73. r[n-1][e] -> repairTIMES = atoi(reptime);
  74. fflush(stdin);
  75. printf("What is repair History?\n");
  76. fgets(history, sizeof(history), stdin);
  77. r[n-1][e] -> SERVICEhistory = atoi(history);
  78. fflush(stdin);
  79. }
  80.  
  81.  
  82.  
  83.  
  84. }
  85.  
  86.  
  87.  
  88. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  89.  
  90.  
  91.  
  92.  
  93. void deleting(int n, int *T)
  94. {
  95. char help[10];
  96. int i=0, e=0;
  97.  
  98. p[n] = malloc(sizeof(Car));
  99. r[n][0] = malloc(sizeof(Service));
  100. printf("Which card should I delete from the list?\n");
  101. fgets(help, sizeof(help), stdin);
  102.  
  103. for(i=0; i<(n-1); i++)
  104. {
  105.  
  106. if((p[i] -> ID )== atoi(help) )
  107. {
  108. break;
  109. }
  110. }
  111. p[i] -> ID = p[n-1] -> ID;
  112. strcpy(p[i] -> Mark, p[n-1] -> Mark);
  113. p[i] -> model = p[n-1] -> model;
  114. p[i] -> mileage = p[n-1] -> mileage;
  115. p[i] -> currentREPAIRS= p[n-1] -> currentREPAIRS;
  116. p[i] -> archiveREPAIRS = p[n-1] -> archiveREPAIRS;
  117. for(e=0; e<T[n-1]; e++)
  118. {
  119. r[i][e] = malloc(sizeof(Service));
  120. strcpy(r[i][e] -> FULLname, r[n-1][e] -> FULLname);
  121. r[i][e] -> ID = r[n-1][e] -> ID;
  122. r[i][e] -> repairTIMES = r[n-1][e] -> repairTIMES;
  123. r[i][e] -> SERVICEhistory = r[n-1][e] -> SERVICEhistory;
  124. }
  125. }
  126.  
  127.  
  128. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  129.  
  130.  
  131.  
  132. void modify(int n, int *T)
  133. {
  134. char help[10], amount[10], CID[10], mark[10], model[10], mileage[10], rep[10], archive[10], RID[10], name[10], reptime[10], history[10];
  135. int i=0, e=0;
  136. printf("Which Car Info would you like to modify?\n");
  137. fgets(help, sizeof(help), stdin);
  138. for(i=0; i<(n-1); i++)
  139. {
  140. if(p[i] -> ID == atoi(help))
  141. break;
  142. }
  143.  
  144. printf("What is car ID?\n");
  145. fgets(CID, sizeof(CID), stdin);
  146. p[i] -> ID = atoi(CID);
  147. fflush(stdin);
  148. printf("What is car Mark?\n");
  149. scanf("%s", p[i] -> Mark);
  150. fflush(stdin);
  151. printf("What is car Model?\n");
  152. fgets(model, sizeof(model), stdin);
  153. p[i] -> model = atoi(model);
  154. fflush(stdin);
  155. printf("What is car Mileage?\n");
  156. fgets(mileage, sizeof(mileage), stdin);
  157. p[i] -> mileage = atoi(mileage);
  158. fflush(stdin);
  159. printf("What is car CurrReapir?\n");
  160. fgets(rep, sizeof(rep), stdin);
  161. p[i] -> currentREPAIRS = atoi(rep);
  162. fflush(stdin);
  163. printf("How many repiars did it have?\n");
  164. fgets(amount, sizeof(amount), stdin);
  165. T[i]= atoi(amount);
  166. printf("What is car AoRepairs?\n");
  167. fgets(archive, sizeof(archive), stdin);
  168. p[i] -> archiveREPAIRS = atoi(archive);
  169. fflush(stdin);
  170.  
  171. for(e=0; e<T[i]; e++)
  172. {
  173. r[i][e] = malloc(sizeof(Service));
  174. printf("What is repair ID?\n");
  175. fgets(RID, sizeof(RID), stdin);
  176. r[i][e] -> ID = atoi(RID);
  177. fflush(stdin);
  178. printf("What is repair name?\n");
  179. scanf("%s", r[i][e] -> FULLname);
  180. fflush(stdin);
  181. printf("What is repair RepTime?\n");
  182. fgets(reptime, sizeof(reptime), stdin);
  183. r[i][e] -> repairTIMES = atoi(reptime);
  184. fflush(stdin);
  185. printf("What is repair History?\n");
  186. fgets(history, sizeof(history), stdin);
  187. r[i][e] -> SERVICEhistory = atoi(history);
  188. fflush(stdin);
  189. }
  190. }
  191.  
  192.  
  193.  
  194.  
  195. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  196.  
  197. void druk(int n, int *T)
  198. {
  199. int i=0, e=0;
  200. for(i=0; i<(n); i++)
  201. {
  202. printf("%i\n", p[i] -> ID);
  203. for(e=0; e<T[i]; e++)
  204. {
  205. printf("\t%i\t", r[i][e] -> ID);
  206. printf("%s\t", r[i][e] -> FULLname);
  207. printf("%i\t", r[i][e] -> repairTIMES);
  208. printf("%i", r[i][e] -> SERVICEhistory);
  209. printf("\n");
  210. }
  211. }
  212.  
  213.  
  214. }
  215.  
  216. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  217.  
  218. void print(int n, int *T)
  219. {
  220. int i=0, e=0;
  221. for(i=0; i<(n); i++)
  222. {
  223. printf("%i\t", p[i] -> ID);
  224. printf("%s\t", p[i] -> Mark);
  225. printf("%i\t", p[i] -> model);
  226. printf("%i\t", p[i] -> mileage);
  227. printf("%i\t", p[i] -> currentREPAIRS);
  228. printf("%i\n", p[i] -> archiveREPAIRS);
  229. }
  230.  
  231. /* for(e=0; e<T[i]; e++)
  232. {
  233. printf("\t%i\t", r[i][e] -> ID);
  234. printf("%s\t", r[i][e] -> FULLname);
  235. printf("%i\t", r[i][e] -> repairTIMES);
  236. printf("%i", r[i][e] -> SERVICEhistory);
  237. printf("\n");
  238. } */
  239.  
  240. druk(n, T);
  241.  
  242. }
  243.  
  244.  
  245. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  246.  
  247. void sort(int n, int *T)
  248. {
  249. int i=0, j=0, e=0, temp1, temp2, temp3, temp4, temp5, temp6, temp7, temp8;
  250. char help[10], help2[20];
  251. int a,b,c,d;
  252.  
  253. p[n] = malloc(sizeof(Car));
  254. r[n][0] = malloc(sizeof(Service));
  255. for (i = 0; i<(n); i++)
  256. {
  257. for (j=0; j<(n-1); j++)
  258. {
  259.  
  260. if ((p[j] -> ID) > (p[j+1] -> ID))
  261. {
  262.  
  263. temp1 = p[j+1] -> ID;
  264. p[j+1] -> ID = p[j] -> ID;
  265. p[j] -> ID = temp1;
  266. strcpy(help, p[j+1] -> Mark);
  267. strcpy(p[j+1] -> Mark, p[j] -> Mark);
  268. strcpy(p[j] -> Mark, help);
  269. temp2 = p[j+1] -> model;
  270. p[j+1] -> model= p[j] -> model;
  271. p[j] -> model = temp2;
  272. temp3 = p[j+1] -> mileage;
  273. p[j+1] -> mileage = p[j] -> mileage;
  274. p[j] -> mileage = temp3;
  275. temp4 = p[j+1] -> currentREPAIRS;
  276. p[j+1] -> currentREPAIRS = p[j] -> currentREPAIRS;
  277. p[j] -> currentREPAIRS = temp4;
  278. temp5 = p[j+1] -> archiveREPAIRS;
  279. p[j+1] -> archiveREPAIRS = p[j] -> archiveREPAIRS;
  280. p[j] -> archiveREPAIRS = temp5;
  281. if(T[j] > T[j+1])
  282. {
  283. for(e=0; e<T[j]; e++)
  284. {
  285. r[j][e] = malloc(sizeof(Service));
  286. temp6 = r[j+1][e] -> ID;
  287. r[j+1][e] -> ID = r[j][e] -> ID;
  288. r[j][e] -> ID = temp6;
  289. strcpy(help2, r[j+1][e] -> FULLname);
  290. strcpy(r[j+1][e] -> FULLname, r[j][e] -> FULLname);
  291. strcpy(r[j][e] -> FULLname, help2);
  292. temp7 = r[j+1][e] -> repairTIMES;
  293. r[j+1][e] -> repairTIMES = r[j][e] -> repairTIMES;
  294. r[j][e] -> repairTIMES = temp7;
  295. temp8 = r[j+1][e] -> SERVICEhistory;
  296. r[j+1][e] -> SERVICEhistory = r[j][e] -> SERVICEhistory;
  297. r[j][e] -> SERVICEhistory = temp8;
  298. }
  299. }
  300. else
  301. {
  302. for(e=0; e<T[j+1]; e++)
  303. {
  304. r[j][e] = malloc(sizeof(Service));
  305. temp6 = r[j+1][e] -> ID;
  306. r[j+1][e] -> ID = r[j][e] -> ID;
  307. r[j][e] -> ID = temp6;
  308. strcpy(help2, r[j+1][e] -> FULLname);
  309. strcpy(r[j+1][e] -> FULLname, r[j][e] -> FULLname);
  310. strcpy(r[j][e] -> FULLname, help2);
  311. temp7 = r[j+1][e] -> repairTIMES;
  312. r[j+1][e] -> repairTIMES = r[j][e] -> repairTIMES;
  313. r[j][e] -> repairTIMES = temp7;
  314. temp8 = r[j+1][e] -> SERVICEhistory;
  315. r[j+1][e] -> SERVICEhistory = r[j][e] -> SERVICEhistory;
  316. r[j][e] -> SERVICEhistory = temp8;
  317. }
  318. }
  319.  
  320. }
  321. }
  322. }
  323.  
  324. print( n, T );
  325.  
  326. }
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  339.  
  340. void main()
  341. {
  342. int menu, n=0, z=0;
  343. char tabela[5];
  344. int repair[30], *T;
  345. T = &repair[30];
  346.  
  347.  
  348.  
  349.  
  350.  
  351. do
  352. {
  353. printf("Menu\n");
  354. printf("1. Adding record\n");
  355. printf("2. Removing record\n");
  356. printf("3. Modify record\n");
  357. printf("4. Print all records\n");
  358. printf("5. Sort records\n");
  359. printf("6. Print current list of repairs by each car\n");
  360. printf("7. Quit\n");
  361. fgets(tabela, sizeof(tabela), stdin);
  362. menu = atoi(tabela);
  363.  
  364.  
  365.  
  366. switch( menu )
  367. {
  368. case 1 : n++;
  369. add( n, z, T );
  370. break;
  371. case 2 : deleting( n, T );
  372. n--;
  373. break;
  374. case 3 : modify( n, T );
  375. break;
  376. case 4 : print( n, T );
  377. break;
  378. case 5 : sort( n, T );
  379. break;
  380. case 6 : druk( n, T );
  381. break;
  382. case 7 : printf("Good Bye!\n");
  383. break;
  384. deafult: printf("Wrong data!\n");
  385. break;
  386. }
  387. }
  388. while(menu!=7);
  389. system("PAUSE");
  390.  
  391. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement