Advertisement
Guest User

Untitled

a guest
May 27th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.35 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include "header.h"
  5.  
  6. int main(){
  7.  
  8. ListP listaPessoa;
  9. listaPessoa = cria_listaPessoa();
  10. //loadPessoa(listaPessoa);
  11.  
  12. ListT listaTarefa;
  13. listaTarefa = cria_listaTarefa();
  14.  
  15. ListTD listaTD, listaDone;
  16. listaTD = cria_listaTodo();
  17. listaDone = cria_listaTodo();
  18.  
  19. ListD listaDoing;
  20. listaDoing = cria_listaDoing();
  21.  
  22. int choice;
  23. a:
  24. choice = menu();
  25. switch(choice){
  26. case 1:
  27. printf("\n\t\t\tLista de Tarefas:\n");
  28. imprimeLista_Tarefas(listaTarefa);
  29. printf("\n\t\t\tLista de Pessoas:\n");
  30. imprimeLista_Pessoas(listaPessoa);
  31. goto a;
  32. case 2:
  33. accao(listaTarefa,listaTD);
  34. goto a;
  35. case 3:
  36. moverDoing(listaTarefa, listaPessoa, listaDoing);
  37. goto a;
  38. case 4:
  39. moverDone(listaTarefa, listaDone);
  40. goto a;
  41. case 5:
  42. removerDone(listaDone);
  43. goto a;
  44. case 6:
  45. printf("\n\t\t\tLista de Tarefas\n");
  46. imprimeLista_TD(listaTD);
  47. //imprimeLista_Doing(listaDoing);
  48. goto a;
  49. case 7:
  50. printf("Shutting down...\n");
  51. exit(0);
  52. default:
  53. printf("Escolha invalida\n");
  54. goto a;
  55. }
  56. }
  57.  
  58. /*MENU*/
  59. int menu(){
  60. int choice;
  61. printf("\n-----//MENU//-----\n");
  62. printf("1:Listar Pessoas\n");
  63. printf("2:Inserir tarefa em To do\n");
  64. printf("3:Mover cartao para Doing\n");
  65. printf("4:Mover cartao para Done\n");
  66. printf("5:Remover cartao de Done\n");
  67. printf("6:Listar Tarefas\n");
  68. printf("7:Sair do Programa\n");
  69. printf("------------------\n");
  70. printf("O que pretende fazer?\n");
  71. scanf("%d",&choice);
  72. return choice;
  73. }
  74.  
  75. /*Criar Listas*/
  76.  
  77. ListTD cria_listaTodo(void){
  78. ListTD aux = (ListTD)malloc(sizeof(List_node_ToDo));
  79. if(aux!= NULL){
  80. aux->next = NULL;
  81. }
  82. return aux;
  83. }
  84.  
  85. ListD cria_listaDoing(void){
  86. ListD aux = (ListD)malloc(sizeof(List_node_Doing));
  87. if(aux!= NULL){
  88. aux->next = NULL;
  89. }
  90. return aux;
  91. }
  92.  
  93. ListT cria_listaTarefa(void){
  94. ListT aux = (ListT)malloc(sizeof(List_node_cartao));
  95. if (aux!=NULL){
  96. aux->next = NULL;
  97. }
  98. return aux;
  99. }
  100.  
  101. ListP cria_listaPessoa(void){
  102. ListP aux = (ListP)malloc(sizeof(List_node_Pessoa));
  103. if (aux!=NULL){
  104. aux->next = NULL;
  105. }
  106. return aux;
  107. }
  108.  
  109. /*Load Ficheiros de Texto*/
  110.  
  111. void loadPessoa(ListP lista){
  112. FILE *file;
  113. int idAux;
  114. char nomeAux[MAX];
  115. char emailAux[MAX];
  116. pessoa aux;
  117. char ch[100];
  118. file = fopen("pessoas.txt","r");
  119. while(fscanf(file,"%[^\t\n]",ch) != EOF){
  120. printf("Entrei\n");
  121. fseek(file,1,SEEK_CUR);
  122. idAux = atoi(ch);
  123. fscanf(file,"%[^\t\n]",nomeAux);
  124. fseek(file,1,SEEK_CUR);
  125. fscanf(file,"%[^\t\n]",emailAux);
  126. fseek(file,2,SEEK_CUR);
  127. printf("ID Fora do ficheiro: %d\n",idAux);
  128. printf("Nome Fora do ficheiro: %s\n",nomeAux);
  129.  
  130. aux = newPessoa(idAux, nomeAux, emailAux);
  131.  
  132. insere_lista_pessoa(lista, aux);
  133.  
  134. }
  135. fclose(file);
  136. }
  137.  
  138. /*Inserções nas Listas*/
  139. void insere_lista_pessoa(ListP lista, pessoa a){
  140. printf("\nEntrei e o nome é %s\n", a->nome);
  141. ListP lst = (ListP) malloc(sizeof(List_node_Pessoa));
  142. if(lst == NULL){
  143. printf("ERRO DE ALOCACAO DE MEMORIA\n");
  144. exit(0);
  145. }
  146. printf("Memory created successfully\n");
  147. ListP aux = lista;
  148. ListP aux2;
  149. lst -> pessoa = a;
  150. if (aux == NULL){
  151. lista -> next = lst;
  152. lst -> next = NULL;
  153. return;
  154. }
  155. while (aux){
  156. aux2 = aux ->next;
  157. if(aux2 == NULL){
  158. aux->next = lst;
  159. lst->next = NULL;
  160. return;
  161. }
  162. aux = aux2;
  163. }
  164. }
  165.  
  166. void insere_lista_tarefa(ListT lista, cartao a){
  167. ListT lst = (ListT)malloc(sizeof(List_node_cartao));
  168. ListT aux = lista;
  169. ListT aux2;
  170. lst->cartao = a;
  171. if(aux==NULL){
  172. lista->next = lst;
  173. lst->next = NULL;
  174. return;
  175. }
  176. while(aux){
  177. aux2 = aux->next;
  178. if(aux2 == NULL){
  179. lst->next = NULL;
  180. aux->next = lst;
  181. return;
  182. }
  183. if(aux2->cartao->prioridade < lst->cartao->prioridade){
  184. lst->next = aux2;
  185. aux->next = lst;
  186. return;
  187. }
  188. aux = aux2;
  189. }
  190. }
  191.  
  192. void insere_lista_todo(ListTD lista, ListTD node){
  193. ListTD aux = lista;
  194. ListTD aux2;
  195. if(aux == NULL){
  196. lista->next = node;
  197. node->next = NULL;
  198. return;
  199. }
  200. while(aux){
  201. aux2 = aux->next;
  202. if(aux2 == NULL){
  203. node->next = NULL;
  204. aux->next = node;
  205. return;
  206. }
  207. aux= aux2;
  208. }
  209. }
  210.  
  211. void insere_lista_Doing(ListD lista, cartao cartao, ListP listaPessoa){
  212. pessoa escolhido;
  213. int id;
  214. printf("Qual o id da pessoa que pretende associar?\n");
  215. scanf("%d",&id);
  216. printf("\n");
  217. escolhido = procuraListaP(id, listaPessoa);
  218. ListD node = (ListD)malloc(sizeof(List_node_Doing));
  219. node->cartao = &cartao;
  220. node->pessoa = &escolhido;
  221. ListD aux = lista;
  222. ListD aux2;
  223. if(aux == NULL){
  224. lista->next = node;
  225. node->next = NULL;
  226. return;
  227. }
  228. while(aux){
  229. aux2 = aux->next;
  230. if(aux2 == NULL){
  231. node->next = NULL;
  232. aux->next = node;
  233. return;
  234. }
  235. aux= aux2;
  236. }
  237. }
  238.  
  239. void insere_lista_Done(ListTD lista, cartao tarefa){
  240. ListTD node = (ListTD)malloc(sizeof(ListTD));
  241. node->cartao = &tarefa;
  242. ListTD aux = lista;
  243. ListTD aux2;
  244. if(aux == NULL){
  245. lista->next = node;
  246. node->next = NULL;
  247. return;
  248. }
  249. while(aux){
  250. aux2 = aux->next;
  251. if(aux2 == NULL){
  252. node->next = NULL;
  253. aux->next = node;
  254. return;
  255. }
  256. aux= aux2;
  257. }
  258. }
  259.  
  260. /*Criar Pessoas e Cartões*/
  261. pessoa newPessoa(int id, char nome[MAX], char email[MAX]){
  262. printf("Entrei na nova pessoa\n");
  263. pessoa aux = (pessoa)malloc(sizeof(Pessoa));
  264. if(aux == NULL){
  265. printf("Randint foda se\n");
  266. exit(-1);
  267. }
  268. aux->id = id;
  269. strcpy(aux->nome, nome);
  270. strcpy(aux->email, email);
  271. return aux;
  272. }
  273.  
  274. cartao newCartao(int id, int prioridade, char desc[MAX]){
  275. cartao card = (cartao)malloc(sizeof(cartao));
  276. if(card == NULL){
  277. exit(-1);
  278. }
  279. card->ID = id;
  280. card->prioridade = prioridade;
  281. strcpy(card->descricao, desc);
  282. return card;
  283. }
  284.  
  285. /*Impressões das Listas*/
  286. void imprimeLista_Tarefas(ListT lista){
  287. ListT aux = lista->next;
  288. while(aux){
  289. printf("\nTarefa %d\tPrioridade%d\n", aux->cartao->ID, aux->cartao->prioridade);
  290. aux = aux->next;
  291. }
  292. }
  293.  
  294. void imprimeLista_Pessoas(ListP lista){
  295. ListP aux = lista->next;
  296. while(aux){
  297. printf("ID: %d\tNome:%s\n", aux->pessoa->id, aux->pessoa->nome);
  298. aux = aux->next;
  299. }
  300. }
  301.  
  302. /*TO-DO*/
  303.  
  304.  
  305. void accao(ListT listaTarefa, ListTD listaTodo){
  306. int id;
  307. int prioridade;
  308. char desc[MAX];
  309. printf("\nID da tarefa:\n");
  310. scanf("%d", &id);
  311. printf("\n");
  312. while(prioridade<0 || prioridade>10){
  313. printf("\nPrioridade da tarefa(1 a 10):\n");
  314. scanf("%d", &prioridade);
  315. printf("\n");
  316. if(prioridade<0 || prioridade > 10){
  317. printf("Escolha Inválida, prioridade tem de ser entre 1 e 10\n");
  318. }
  319. }
  320. printf("\nDescricao da tarefa:\n");
  321. scanf("%s", desc);
  322. cartao aux = newCartao(id,prioridade, desc);
  323. insere_lista_tarefa(listaTarefa, aux);
  324. cartao *pointer = &aux;
  325. ListTD node = (ListTD)malloc(sizeof(List_node_ToDo));
  326. node->cartao = pointer;
  327. insere_lista_todo(listaTodo, node);
  328. prioridade = 100;
  329. }
  330.  
  331. void moverDoing(ListT listaTarefa, ListP listaPessoa, ListD listaDoing){
  332. cartao tarefa;
  333. int choice;
  334. printf("Qual o ID da tarefa que pretende mover?:\n");
  335. scanf("%d",&choice);
  336. printf("tOU AquI\n");
  337. tarefa = procuraListaT(choice, listaTarefa);
  338. printf("Encontrei");
  339. insere_lista_Doing(listaDoing, tarefa, listaPessoa);
  340. }
  341.  
  342. void moverDone(ListT listaTarefa, ListTD listaDone){
  343. cartao tarefa;
  344. int choice;
  345. printf("Qual o ID da tarefa que pretende mover?:\n");
  346. scanf("%d",&choice);
  347. printf("tOU AquI\n");
  348. tarefa = procuraListaT(choice, listaTarefa);
  349. insere_lista_Done(listaDone, tarefa);
  350. }
  351.  
  352. cartao procuraListaT(int id, ListT listaTarefa){
  353. ListT aux;
  354. aux = listaTarefa;
  355. cartao help;
  356. help = aux->cartao;
  357. while(aux){
  358. if(help->ID != id){
  359. aux = aux->next;
  360. }
  361. else
  362. break;
  363. }
  364. return aux->cartao;
  365. }
  366.  
  367. pessoa procuraListaP(int id, ListP lista){
  368. ListP aux;
  369. aux = lista;
  370. while(aux){
  371. if(aux->pessoa->id != id){
  372. aux = aux->next;
  373. }
  374. else
  375. break;
  376. }
  377. return aux->pessoa;
  378. }
  379.  
  380. void removerDone(ListTD lista){
  381. int id;
  382. printf("Qual o ID da tarefa que pretende remover da lista?\n");
  383. scanf("%d",&id);
  384. ListTD node;
  385. node = popListaD(lista, id);
  386. free(node);
  387. }
  388.  
  389. ListTD popListaD(ListTD lista, int id){
  390. ListTD aux = lista;
  391. ListTD aux2;
  392. aux = lista;
  393. aux2 = lista;
  394. cartao help;
  395. help = aux->cartao;
  396. if(help->ID == id){
  397. aux2 = aux->next;
  398. lista = aux2;
  399. return aux;
  400. }
  401. aux = aux->next;
  402. while(aux){
  403. help = aux->cartao;
  404. if(help->ID == id){
  405. aux2->next = aux->next;
  406. return aux;
  407. }
  408. aux2 = aux;
  409. aux = aux->next;
  410. }
  411.  
  412. }
  413.  
  414. void imprimeLista_TD(ListTD lista){
  415. cartao c;
  416. ListTD aux = lista->next;
  417. printf("-\t-\t-\tLISTA TO DO\t-\t-\t-\n");
  418. while(aux){
  419. c = aux->cartao;
  420. printf("\nTarefa: %d\t Prioridade: %d", c->ID, c->prioridade);
  421. aux = aux->next;
  422. }
  423. }
  424.  
  425. void imprimeLista_Doing(ListD lista){
  426. cartao c;
  427. pessoa p;
  428. ListD aux = lista;
  429. printf("-\t-\t-\tLISTA DOING\t-\t-\t-\n");
  430. while(aux){
  431. c = aux->cartao;
  432. p = aux->pessoa;
  433. printf("\nTarefa:%d\t Prioridade: %d\t Pessoa Associada:%s\n",c->ID, c->prioridade, p->nome);
  434.  
  435. }
  436.  
  437. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement