Advertisement
Guest User

Untitled

a guest
May 24th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 33.56 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #define SIZENOME 3000
  5. #define MIN_NOME 5
  6.  
  7. typedef struct pessoa *ListU;
  8. typedef struct pessoa
  9. {
  10. char nome[SIZENOME];
  11. char morada[SIZENOME];
  12. char data_nascimento[SIZENOME];
  13. char telefone[SIZENOME];
  14.  
  15. ListU next;
  16.  
  17. }pnode;
  18.  
  19. typedef struct Locais *ListL;
  20. typedef struct Locais
  21. {
  22. char local[SIZENOME];
  23. char nome[SIZENOME];
  24. char info[SIZENOME];
  25. char horario[SIZENOME];
  26.  
  27. ListL next;
  28.  
  29. }pnodeL;
  30.  
  31. typedef struct votos *ListV;
  32. typedef struct votos
  33. {
  34. char user[SIZENOME];
  35. char locais[SIZENOME];
  36. char hot[SIZENOME];
  37. char pdis[SIZENOME];
  38.  
  39. ListV next;
  40.  
  41. }pnodeV;
  42.  
  43. ListU cria_lista_users()
  44. {
  45. ListU h=(ListU)malloc(sizeof(pnode));
  46. h->next=NULL;
  47. return h;
  48. }
  49.  
  50. ListL cria_lista_POI()
  51. {
  52. ListL h=(ListL)malloc(sizeof(pnodeL));
  53. h->next=NULL;
  54. return h;
  55. }
  56.  
  57. ListV cria_lista_V()
  58. {
  59. ListV h=(ListV)malloc(sizeof(pnodeV));
  60. h->next=NULL;
  61. return h;
  62. }
  63.  
  64. int lista_vazia_POI(ListL h)
  65. {
  66. return h->next==NULL;
  67. }
  68.  
  69. int lista_vazia_users(ListU h)
  70. {
  71. return h->next==NULL;
  72. }
  73.  
  74. int lista_vazia_V(ListV h)
  75. {
  76. return h->next==NULL;
  77. }
  78.  
  79. void inserir_user(ListU h, char *nome, char *morada, char* data_nascimento, char *telefone)
  80. {
  81. while(!lista_vazia_users(h))
  82. {
  83. ListU aux=h->next;
  84. h=aux;
  85. }
  86.  
  87. ListU last=(ListU)malloc(sizeof(pnode));
  88.  
  89. strcpy(last->nome,nome);
  90. strcpy(last->morada,morada);
  91. strcpy(last->data_nascimento,data_nascimento);
  92. strcpy(last->telefone,telefone);
  93. h->next=last;
  94. }
  95.  
  96. void inserir_POI(ListL h, char *local, char *nome, char* info, char *horario)
  97. {
  98. while(!lista_vazia_POI(h))
  99. {
  100. ListL aux=h->next;
  101. h=aux;
  102. }
  103.  
  104. ListL last=(ListL)malloc(sizeof(pnodeL));
  105.  
  106. strcpy(last->local,local);
  107. strcpy(last->nome,nome);
  108. strcpy(last->info,info);
  109. strcpy(last->horario,horario);
  110. h->next=last;
  111. }
  112.  
  113. void inserir_V(ListV h, char *user, char *locais, char* hot, char *pdis)
  114. {
  115. while(!lista_vazia_POI(h))
  116. {
  117. ListV aux=h->next;
  118. h=aux;
  119. }
  120.  
  121. ListV last=(ListV)malloc(sizeof(pnodeV));
  122.  
  123. strcpy(last->user,user);
  124. strcpy(last->locais,locais);
  125. strcpy(last->hot,hot);
  126. strcpy(last->pdis,pdis);
  127.  
  128. h->next=last;
  129. }
  130.  
  131. void imprime_lista_POI(ListL lista)
  132. {
  133. lista = lista->next;
  134. while(lista!=NULL){
  135. printf("\nLocal: %s\nNome: %s\nInformacao: %s\nHorario:%s\n",
  136. lista->local,
  137. lista->nome,
  138. lista->info,
  139. lista->horario);
  140.  
  141. lista=lista->next;
  142. }
  143.  
  144. }
  145.  
  146. void listar_locais(ListL lista)
  147. {
  148. lista = lista->next;
  149. char nome_aux[SIZENOME];
  150. strcpy(nome_aux,"");
  151.  
  152. printf("\n\tLOCAIS");
  153. while(lista!=NULL)
  154. {
  155. if(strcmp(lista->local,nome_aux)!=0)
  156. {
  157. printf("\n%s",
  158. lista->local);
  159. }
  160.  
  161. strcpy(nome_aux,lista->local);
  162. lista=lista->next;
  163. }
  164. printf("\n");
  165. }
  166.  
  167. void listar_PdIs(ListL lista)
  168. {
  169. lista = lista->next;
  170.  
  171. char nome_aux[SIZENOME];
  172. strcpy(nome_aux,"");
  173.  
  174. printf("\n\tPONTOS DE INTERESSE\n");
  175. while(lista!=NULL)
  176. {
  177. if(strcmp(lista->local,nome_aux)!=0)
  178. {
  179. printf("LOCAL: %s\n\tNome: %s\n",
  180. lista->local,
  181. lista->nome);
  182. }
  183. else
  184. {
  185. printf("\t-%s\n",lista->nome);
  186. }
  187.  
  188. strcpy(nome_aux,lista->local);
  189. lista=lista->next;
  190. }
  191. printf("\n");
  192. }
  193.  
  194. void imprime_POIs_az(ListU lista_users,ListL lista, char *nome)
  195. {
  196. int opcao;
  197. lista = lista->next;
  198. char nome_aux[SIZENOME];
  199. strcpy(nome_aux,"");
  200.  
  201. printf("\n\tLOCAIS\n\n");
  202. while(lista!=NULL)
  203. {
  204. if(strcmp(lista->local,nome_aux)!=0)
  205. {
  206. printf("\nLOCAL: %s\n\n\tNome: %s\n\tInformacao: %s\n\tHorario:%s\n",
  207. lista->local,
  208. lista->nome,
  209. lista->info,
  210. lista->horario);
  211. }
  212. else
  213. {
  214. printf("\n\tNome: %s\n\tInformacao: %s\n\tHorario:%s\n",
  215. lista->nome,
  216. lista->info,
  217. lista->horario);
  218. }
  219.  
  220. strcpy(nome_aux,lista->local);
  221. lista=lista->next;
  222. }
  223. printf("\n(1)Voltar ao menu\n");
  224. scanf("%d",&opcao);
  225. getchar();
  226. if(opcao==1)
  227. {
  228. menu(lista_users,lista,nome);
  229. }
  230. /*printf("\n<<%d POIs imprimidos c sucesso.>>\n",cont);*/
  231. }
  232. void imprime_lista_users(ListU lista)
  233. {
  234. int cont=0;
  235. lista = lista->next;
  236. while(lista!=NULL){
  237. printf("\nNome: %s\nMorada: %s\nData de Nascimento: %s\nTelefone:%s\n",
  238. lista->nome,
  239. lista->morada,
  240. lista->data_nascimento,
  241. lista->telefone);
  242. lista=lista->next;
  243. cont++;
  244. }
  245. printf("\n<<%d users imprimidos c sucesso.>>\n",cont);
  246. }
  247.  
  248. void imprimir_user(ListU lista,char*nome)
  249. {
  250. lista=lista->next;
  251. while(lista!=NULL)
  252. {
  253. if(strcmp(lista->nome,nome)==0)
  254. {
  255. printf("\n\nNome: %s\nMorada: %s\nData de Nascimento: %s\nTelefone:%s\n",
  256. lista->nome,
  257. lista->morada,
  258. lista->data_nascimento,
  259. lista->telefone);
  260. }
  261. lista = lista->next;
  262. }
  263. }
  264.  
  265. void imprimir_votos(ListV lista,char*nome)
  266. {
  267. lista=lista->next;
  268. while(lista!=NULL)
  269. {
  270. if(strcmp(lista->user,nome)==0)
  271. {
  272. printf("\nVOTOS\n Locais: ");
  273. imprimir_locais(lista->locais);
  274. printf("\n Ponto de Interesse Hot: ");
  275. imprimir_hot(lista->hot);
  276. printf("\n Pontos de Interese: ");
  277. imprimir_pdis(lista->pdis);
  278. printf("\n\n");
  279. }
  280. lista = lista->next;
  281. }
  282. }
  283.  
  284. void imprimir_locais(char*string)
  285. {
  286. char local_1[SIZENOME],local_2[SIZENOME],local_3[SIZENOME];
  287. if(strcmp(string,"0;0;0")==0)
  288. {
  289. printf("[Ainda Nao Votados]");
  290. }
  291. else
  292. {
  293. sscanf(string,"%[^;];%[^;];%[^;]",local_1,local_2,local_3);
  294. printf("\n -%s \n -%s \n -%s",local_1,local_2,local_3);
  295. }
  296. }
  297.  
  298. void imprimir_pdis(char*string)
  299. {
  300. if(strcmp(string,"0:")==0)
  301. {
  302. printf("[Ainda Nao Votado]");
  303. }
  304. else
  305. {
  306. printf("%s",string);
  307. }
  308. }
  309.  
  310. void imprimir_hot(char*string)
  311. {
  312. if(strcmp(string,"0")==0)
  313. {
  314. printf("[Ainda Nao Votado]");
  315. }
  316. else
  317. {
  318. printf("%s",string);
  319. }
  320. }
  321.  
  322.  
  323. void imprime_lista_votos(ListV lista)
  324. {
  325. lista=lista->next;
  326. while(lista!=NULL)
  327. {
  328. printf("\nUser: %s\nLocais: %s\nPdI Hot: %s\nPdIs: %s\n",
  329. lista->user,
  330. lista->locais,
  331. lista->hot,
  332. lista->pdis);
  333. lista = lista->next;
  334. }
  335. }
  336.  
  337. void liberta_lista_user(ListU lista)
  338. {
  339. ListU aux;
  340. aux=lista->next;
  341. free(lista);
  342. lista=aux;
  343.  
  344. while(lista!=NULL){
  345. aux=lista->next;
  346. free(lista);
  347. lista = aux;
  348.  
  349. }
  350. }
  351.  
  352. void load_users(ListU lista_users)
  353. {
  354. char nome[SIZENOME];
  355. char morada[SIZENOME];
  356. char data_nascimento[SIZENOME];
  357. char telefone[SIZENOME];
  358. char buffer[SIZENOME*4];
  359.  
  360. FILE*f=fopen("users.txt","r");
  361. while(fgets(buffer,1000,f)!=NULL)
  362. {
  363. sscanf(buffer,"%[^:]:%[^:]:%[^:]:%[^\n]",nome,morada,data_nascimento,telefone);
  364. inserir_user(lista_users,nome,morada,data_nascimento,telefone);
  365. }
  366. fclose(f);
  367. }
  368.  
  369. void eliminar_user(ListU lista,ListL lista_locais,char *nome)
  370. {
  371. system("cls");
  372. int opcao;
  373.  
  374. printf("\tELIMINAR CONTA");
  375. imprimir_user(lista,nome);
  376.  
  377. printf("\nTem a certeza que quer eliminar todos os seus dados e votos?\n(1)Confirmar\n(2)Voltar ao menu\n");
  378.  
  379. scanf("%d",&opcao);
  380. getchar();
  381. if(opcao==1)
  382. {
  383. ListU p,q;
  384. p = lista;
  385. q = lista->next;
  386.  
  387. while (q != NULL && !strcmp(q->nome,nome)==0)
  388. {
  389. p = q;
  390. q = q->next;
  391. }
  392. if (q != NULL)
  393. {
  394. p->next = q->next;
  395. free (q);
  396. }
  397. }
  398. if(opcao==2)
  399. {
  400. menu(lista,lista_locais,nome);
  401. }
  402. }
  403.  
  404. void eliminar_user_votos(ListV lista,char *nome)
  405. {
  406. ListV p,q;
  407. p = lista;
  408. q = lista->next;
  409.  
  410. while (q != NULL && !strcmp(q->user,nome)==0)
  411. {
  412. p = q;
  413. q = q->next;
  414. }
  415. if (q != NULL)
  416. {
  417. p->next = q->next;
  418. free (q);
  419. }
  420. }
  421.  
  422. void load_POI(ListL lista)
  423. {
  424.  
  425. char local[SIZENOME];
  426. char nome[SIZENOME];
  427. char info[SIZENOME];
  428. char horario[SIZENOME];
  429. char buffer[SIZENOME*4];
  430.  
  431. FILE*f=fopen("POIs.txt","r");
  432. while(fgets(buffer,1000,f)!=NULL)
  433. {
  434. sscanf(buffer,"%[^|]|%[^:]:%[^|]|%[^\n]",
  435. local,
  436. nome,
  437. info,
  438. horario);
  439. inserir_POI(lista,local,nome,info,horario);
  440. }
  441. fclose(f);
  442. }
  443.  
  444. void load_votos(ListV lista)
  445. {
  446.  
  447. char user[SIZENOME];
  448. char locais[SIZENOME];
  449. char hot[SIZENOME];
  450. char pdis[SIZENOME*4];
  451. char buffer[SIZENOME*8];
  452.  
  453. FILE*f=fopen("votos.txt","r");
  454. while(fgets(buffer,1000,f)!=NULL)
  455. {
  456. sscanf(buffer,"%[^|]|%[^|]|%[^|]|%[^\n]",
  457. user,
  458. locais,
  459. hot,
  460. pdis);
  461. inserir_V(lista,user,locais,hot,pdis);
  462. }
  463. fclose(f);
  464. }
  465.  
  466. void save_users(ListU lista)
  467. {
  468. int cont=0;
  469. FILE*f=fopen("users.txt","w");
  470. ListU l = lista->next;
  471.  
  472. while(l){
  473. fprintf(f,"%s:%s:%s:%s\n",
  474. l->nome,
  475. l->morada,
  476. l->data_nascimento,
  477. l->telefone);
  478.  
  479. cont++;
  480. l=l->next;
  481. }
  482. fclose(f);
  483. }
  484.  
  485. void save_votos(ListV lista)
  486. {
  487. int cont=0;
  488. FILE*f=fopen("votos.txt","w");
  489. ListV l = lista->next;
  490.  
  491. while(l){
  492. fprintf(f,"%s|%s|%s|%s\n",
  493. l->user,
  494. l->locais,
  495. l->hot,
  496. l->pdis);
  497.  
  498. cont++;
  499. l=l->next;
  500. }
  501. fclose(f);
  502. }
  503.  
  504. void validar_lista_votos(ListV lista,ListU lista_user)
  505. {
  506. ListV l=lista;
  507. lista=lista->next;
  508. while(lista!=NULL)
  509. {
  510. if(verificar_user(lista_user,lista->user)==1)
  511. printf("\nUser %s validado!",lista->user);
  512. else
  513. {
  514. printf("\nUser %s nao validado. Eliminado.",lista->user);
  515. eliminar_user_votos(l,lista->user);
  516. }
  517. lista = lista->next;
  518. }
  519. printf("\n");
  520. }
  521.  
  522. int verificar_local(ListL lista,char* local)
  523. {
  524. lista = lista->next;
  525. while(lista!=NULL)
  526. {
  527. if(strcmp(lista->local,local)==0)
  528. return 1;
  529. lista = lista->next;
  530. }
  531. return 0;
  532. }
  533.  
  534. int verificar_locais_votados(ListV lista, char*nome)
  535. {
  536. lista = lista->next;
  537.  
  538. while(lista!=NULL)
  539. {
  540. if(strcmp(lista->user,nome)==0)
  541. {
  542. /*printf("%s",lista->locais);*/
  543.  
  544. if(strcmp(lista->locais,"0;0;0")==0)
  545. return 1;
  546. }
  547. lista = lista->next;
  548. }
  549. return 0;
  550. }
  551.  
  552. int verificar_POI(ListL lista,char* nome)
  553. {
  554. lista = lista->next;
  555. while(lista!=NULL)
  556. {
  557. if(strcmp(lista->nome,nome)==0)
  558. return 1;
  559. lista = lista->next;
  560. }
  561. return 0;
  562. }
  563.  
  564. int verificar_hot(ListV lista,char*hot,char* nome)
  565. {
  566. lista = lista->next;
  567. while(lista!=NULL)
  568. {
  569. if(strcmp(lista->user,nome)==0)
  570. {
  571. /*printf("\n\t<<nome encontrado! %s = %s>>\n",lista->user,nome);*/
  572. if(strstr(lista->pdis,hot)!=NULL)
  573. {
  574. /*printf("\n\t<<[VERIF HOT] HOT:%s encontrado nos PDIS no indice %d de %s>>\n",hot,strstr(lista->pdis,hot),lista->pdis);*/
  575. return 1;
  576. }
  577. /*printf("\n\t[VERIF HOT] <<HOT:%s NAO encontrado nos PDIS %s>>\n",hot,lista->pdis);*/
  578. }
  579.  
  580. lista = lista->next;
  581. }
  582.  
  583. return 0;
  584. }
  585.  
  586. int verificar_pdis(ListV lista,char*pdis,char* nome)
  587. {
  588. lista = lista->next;
  589. while(lista!=NULL)
  590. {
  591. if(strcmp(lista->user,nome)==0)
  592. {
  593. /*printf("\n\t<<nome encontrado! %s = %s>>\n",lista->user,nome);*/
  594. if(strcmp(pdis,lista->hot)==0)
  595. {
  596. return 1;
  597. printf("\n\tHOT JA EXISTENTE!!");
  598. }
  599. /*printf("\n\t<<[VERIF PDIS] HOT:%s| NAO EH IGUAL AO PDI |%s>>\n",lista->hot,pdis);*/
  600. }
  601.  
  602. lista = lista->next;
  603. }
  604. return 0;
  605. }
  606.  
  607. int verificar_user(ListU lista,char* nome) /*1 se encontra, 0 se n encontra*/
  608. {
  609. lista=lista->next;
  610. while(lista!=NULL)
  611. {
  612. if(strcmp(lista->nome,nome)==0)
  613. return 1;
  614. lista = lista->next;
  615. }
  616. return 0;
  617. }
  618.  
  619. int verificar_telemovel(char* telemovel)
  620. {
  621. char nums[]="0123456789";
  622.  
  623. if(strlen(telemovel)>9)/*numero n pode ultrapassar 9 caracteres, 9 algarismos*/
  624. return 1;
  625. if(strspn(telemovel,nums)!=9)/*strspn identifica ate q ponto o telemovel contem caracteres iguais a nums, neste caso garantindo q seja valido*/
  626. return 1;
  627. return 0;
  628. }
  629.  
  630. int verificar_nome(char* nome)
  631. {
  632. char letras[]="ABCDEFGHIJKLMNOPQRSTUVXZWYabcdefghijklmnopqrstuvxzwy ";
  633.  
  634. if(strlen(nome)<MIN_NOME)/*tem de ser maior q min nome*/
  635. return 1;
  636. if(strspn(nome,letras)!=strlen(nome))/*so pode ter letras e espacos*/
  637. return 1;
  638. return 0;
  639. }
  640.  
  641. int verificar_morada(char* nome)
  642. {
  643. char letras[]="ABCDEFGHIJKLMNOPQRSTUVXZWYabcdefghijklmnopqrstuvxzwy 1234567890.";
  644.  
  645. if(strlen(nome)<MIN_NOME*2)/*tem de ser maior q min nome*/
  646. return 1;
  647. if(strspn(nome,letras)!=strlen(nome))/*so pode ter letras e espacos*/
  648. return 1;
  649. return 0;
  650. }
  651.  
  652. int verificar_data(int dia,int mes,int ano)
  653. {
  654. int bissexto;
  655.  
  656. if ( ( ano % 4 == 0 && ano % 100 != 0 ) || ano % 400 == 0 )
  657. bissexto=1;
  658. else
  659. bissexto=0;
  660.  
  661. if ((dia>31) && ((mes==1) || (mes==3) || (mes==5) || (mes==7) || (mes==8) || (mes==10) || (mes==12)))
  662. return 0;
  663. if ((dia>30) && ((mes==4) || (mes==6) || (mes==9) || (mes==11)))
  664. return 0;
  665. if ((dia>29) && (mes==2) && (bissexto==1))
  666. return 0;
  667. if ((dia>28) && (mes==2) && (bissexto==0))
  668. return 0;
  669. if(mes>12)
  670. return 0;
  671. if(ano<=1903||ano>2019)
  672. return 0;
  673. else
  674. return 1;
  675. }
  676.  
  677.  
  678. void log_in(ListU lista_users, ListL lista_locais,ListV lista_votos, char *name)
  679. {
  680. system("cls");
  681. printf("******************************\n\n\tLOG-IN\n\nNome: ");
  682.  
  683. int opcao;
  684. char nome[SIZENOME];
  685. fgets(nome,sizeof(nome)+1,stdin);
  686. nome[strlen(nome)-1]='\0'; /*como o \n (o ENTER) é o q identifica o fim de input, elimina-se o ultimo elemento para o nome ser apenas as letras sem o paragrafo*/
  687.  
  688. if(verificar_user(lista_users,nome)!=1)
  689. {
  690. system("cls");
  691. printf("\t%s Nao Registado.\n\n(1)Tentar Outra Vez\n(2)Registar Novo User\n\n",nome);
  692.  
  693. scanf("%d",&opcao);
  694. getchar();
  695. if(opcao==1)
  696. {
  697. log_in(lista_users,lista_locais,lista_votos,name);
  698. }
  699. if(opcao==2)
  700. {
  701. registar(lista_users,lista_locais,lista_votos,name);
  702. }
  703. }
  704. else
  705. {
  706. system("cls");
  707. strcpy(name,nome);
  708. printf("Bem Vindo, %s\n",name);
  709. menu(lista_users,lista_locais,lista_votos,name);
  710. }
  711. }
  712.  
  713. void escrever_nome(char*string,ListU lista_user)
  714. {
  715. char nome[SIZENOME];
  716.  
  717. fgets(nome,sizeof(nome)+1,stdin);
  718. nome[strlen(nome)-1]='\0'; /*como o \n (o ENTER) é o q identifica o fim de input, elimina-se o ultimo elemento para o nome ser apenas as letras sem o paragrafo*/
  719. while(verificar_user(lista_user,nome)==1||verificar_nome(nome)==1)
  720. {
  721. printf("^Nome Invalido\n-Nao pode ser ja existente\n-Tem de ter mais de %d caracteres\n-So pode conter letras e espacos",MIN_NOME);
  722.  
  723. nome[strlen(nome)-1]='\0';
  724. printf("\n\nNome: ");
  725. fgets(nome,sizeof(nome)+1,stdin);
  726. nome[strlen(nome)-1]='\0';
  727. }
  728. strcpy(string,nome);
  729. }
  730.  
  731. void escrever_morada(char*string,ListU lista_user)
  732. {
  733. char morada[SIZENOME];
  734.  
  735. printf("\nMorada: ");
  736. fgets(morada,sizeof(morada)+1,stdin);
  737. morada[strlen(morada)-1]='\0'; /*como o \n (o ENTER) é o q identifica o fim de input, elimina-se o ultimo elemento para o nome ser apenas as letras sem o paragrafo*/
  738.  
  739. while(verificar_morada(morada)==1)
  740. {
  741. printf("^Morada Invalida\n-Tem de ter mais de %d caracteres\n-So pode conter letras, numeros, espacos e pontos",MIN_NOME*2);
  742.  
  743. morada[strlen(morada)-1]='\0';
  744. printf("\nMorada: ");
  745. fgets(morada,sizeof(morada)+1,stdin);
  746. morada[strlen(morada)-1]='\0';
  747. }
  748.  
  749. strcpy(string,morada);
  750. }
  751.  
  752. void escrever_data(char*string,ListU lista_user)
  753. {
  754. char data[SIZENOME];
  755.  
  756. int dia,mes,ano;
  757.  
  758. printf("\nData de Nascimento (DD/MM/AAAA): ");
  759. scanf("%d/%d/%d",&dia,&mes,&ano);
  760. fflush(stdin);
  761.  
  762. while(verificar_data(dia,mes,ano)==0)
  763. {
  764. printf("^Data Invalida\n-Formato DD/MM/AAAA\n-Nao pode nascer no futuro\n-Nao pode ser mais velho que a pessoa mais velha do mundo");
  765.  
  766. printf("\n\nData de Nascimento (DD/MM/AAAA): ");
  767. scanf("%d/%d/%d",&dia,&mes,&ano);
  768. fflush(stdin);
  769. }
  770.  
  771. sprintf(data, "%d/%d/%d", dia,mes,ano);
  772.  
  773. strcpy(string,data);
  774. }
  775.  
  776. void escrever_telemovel(char*string,ListU lista_user)
  777. {
  778. char telemovel[SIZENOME];
  779.  
  780. printf("\nTelemovel: ");
  781. fgets(telemovel,sizeof(telemovel)+1,stdin);
  782. telemovel[strlen(telemovel)-1]='\0';
  783.  
  784. while(verificar_telemovel(telemovel)==1)
  785. {
  786. printf("^Numero de Telemovel Invalido\n-Tem de ser 9 numeros");
  787.  
  788. printf("\n\nTelemovel: ");
  789. fgets(telemovel,sizeof(telemovel)+1,stdin);
  790. telemovel[strlen(telemovel)-1]='\0';
  791. }
  792.  
  793. strcpy(string,telemovel);
  794. }
  795.  
  796. void escrever_locais(ListU lista_users,ListL lista_locais, ListV lista_votos,char *string, char*nome)
  797. {
  798. listar_locais(lista_locais);
  799. char locais[SIZENOME];
  800. char local[SIZENOME];
  801.  
  802. strcpy(locais,"");
  803.  
  804. int i=0;
  805. while(i<3)
  806. {
  807. printf("\nLocal %d: ",i+1);
  808. fgets(local,sizeof(local)+1,stdin);
  809. local[strlen(local)-1]='\0';
  810.  
  811. while(verificar_local(lista_locais,local)==0||strstr(locais,local)!=NULL)
  812. {
  813. printf("^Local Nao Existente ou Repetido\n");
  814.  
  815. printf("\nLocal %d: ",i+1);
  816. fgets(local,sizeof(local)+1,stdin);
  817. local[strlen(local)-1]='\0';
  818. }
  819. strcat(locais,local);
  820. if(i<2)
  821. strcat(locais,";");
  822. i++;
  823. }
  824.  
  825. strcpy(string,locais);
  826. }
  827.  
  828. void escrever_hot(ListU lista_users,ListL lista_locais, ListV lista_votos,char *string, char*nome)
  829. {
  830. char hot[SIZENOME];
  831.  
  832. listar_PdIs(lista_locais);
  833.  
  834. printf("\nPonto de Interesse Hot: ");
  835. fgets(hot,sizeof(hot)+1,stdin);
  836. hot[strlen(hot)-1]='\0';
  837.  
  838. while(verificar_hot(lista_votos,hot,nome)==1||verificar_POI(lista_locais,hot)==0)
  839. {
  840. printf("^Ponto de Interesse Hot Invalido\n-Tem de Pertencer a Lista\n-Nao Pode Ja Existir Nos Pontos de Interesse Favoritos\n");
  841.  
  842. printf("\n\nPonto de Interesse Hot: ");
  843. fgets(hot,sizeof(hot)+1,stdin);
  844. hot[strlen(hot)-1]='\0';
  845. }
  846.  
  847. strcpy(string,hot);
  848. }
  849.  
  850. void escrever_pdis(ListU lista_users,ListL lista_locais, ListV lista_votos,char *string, char*nome)
  851. {
  852. char pdi[SIZENOME];
  853. char pdis[SIZENOME];
  854.  
  855. strcpy(pdis,"");
  856.  
  857. listar_PdIs(lista_locais);
  858.  
  859. int i=0;
  860. while(i<3)
  861. {
  862. printf("\nPonto de Interesse : ");
  863.  
  864. fgets(pdi,sizeof(pdi)+1,stdin);
  865. pdi[strlen(pdi)-1]='\0';
  866.  
  867. while(verificar_pdis(lista_votos,pdi,nome)==1||verificar_POI(lista_locais,pdi)==0||strstr(pdis,pdi)!=NULL)
  868. {
  869. printf("^Ponto de Interesse Invalido (ver pdis: %d ver POI: %d ver pdi incluido: %d\n-Tem de Pertencer a Lista\n-Nao Pode Ja Existir Como Ponto de Interesse Hot\n-Nao Pode Ser Repetido\n",verificar_pdis(lista_votos,pdi,nome),verificar_POI(lista_locais,pdi),strstr(pdi,pdis));
  870.  
  871. printf("\n\nPonto de Interesse: ");
  872.  
  873. fgets(pdi,sizeof(pdi)+1,stdin);
  874. pdi[strlen(pdi)-1]='\0';
  875. }
  876.  
  877. strcat(pdis,pdi);
  878.  
  879. if(i<2)
  880. strcat(pdis,";");
  881. i++;
  882. }
  883. strcpy(string,pdis);
  884. }
  885.  
  886. void alterar_nome_votos(ListU lista_users,ListL lista_locais, ListV lista, char*string,char*nome)
  887. {
  888. lista=lista->next;
  889. while(lista!=NULL)
  890. {
  891. if(strcmp(lista->user,nome)==0)
  892. strcpy(lista->user,string);
  893. lista = lista->next;
  894. }
  895. }
  896.  
  897. void alterar_locais(ListU lista_users,ListL lista_locais, ListV lista, char*string,char*nome)
  898. {
  899. lista=lista->next;
  900. while(lista!=NULL)
  901. {
  902. if(strcmp(lista->user,nome)==0)
  903. strcpy(lista->locais,string);
  904. lista = lista->next;
  905. }
  906. }
  907.  
  908. void alterar_hot(ListU lista_users,ListL lista_locais, ListV lista, char*string, char*nome)
  909. {
  910. lista=lista->next;
  911. while(lista!=NULL)
  912. {
  913. if(strcmp(lista->user,nome)==0)
  914. strcpy(lista->hot,string);
  915. lista = lista->next;
  916. }
  917. }
  918.  
  919. void alterar_pdis(ListU lista_users,ListL lista_locais, ListV lista, char*string, char*nome)
  920. {
  921. lista=lista->next;
  922. while(lista!=NULL)
  923. {
  924. if(strcmp(lista->user,nome)==0)
  925. strcpy(lista->pdis,string);
  926. lista = lista->next;
  927. }
  928. }
  929.  
  930.  
  931. void alterar_nome(char*nome,char*string,ListU lista)
  932. {
  933. lista=lista->next;
  934. while(lista!=NULL)
  935. {
  936. if(strcmp(lista->nome,nome)==0)
  937. strcpy(lista->nome,string);
  938. lista = lista->next;
  939. }
  940. }
  941.  
  942. void alterar_morada(char*nome,char*string,ListU lista)
  943. {
  944. lista=lista->next;
  945. while(lista!=NULL)
  946. {
  947. if(strcmp(lista->nome,nome)==0)
  948. strcpy(lista->morada,string);
  949. lista = lista->next;
  950. }
  951. }
  952.  
  953. void alterar_data(char*nome,char*string,ListU lista)
  954. {
  955. lista=lista->next;
  956. while(lista!=NULL)
  957. {
  958. if(strcmp(lista->nome,nome)==0)
  959. strcpy(lista->data_nascimento,string);
  960. lista = lista->next;
  961. }
  962. }
  963.  
  964. void alterar_telemovel(char*nome,char*string,ListU lista)
  965. {
  966. lista=lista->next;
  967. while(lista!=NULL)
  968. {
  969. if(strcmp(lista->nome,nome)==0)
  970. strcpy(lista->telefone,string);
  971. lista = lista->next;
  972. }
  973. }
  974.  
  975. void registar(ListU lista_user, ListL lista_locais,ListV lista_votos, char*name)
  976. {
  977. int opcao;
  978.  
  979. system("cls");
  980. printf("******************************\n\n\tREGISTAR\n\nNome: ");
  981.  
  982. /*NOME*/
  983.  
  984. char nome[SIZENOME];
  985.  
  986. escrever_nome(nome,lista_user);
  987.  
  988. /*Morada*/
  989.  
  990. char morada[SIZENOME];
  991.  
  992. escrever_morada(morada,lista_user);
  993.  
  994. /*DATA NASCIMENTO*/
  995.  
  996. char data[SIZENOME];
  997.  
  998. escrever_data(data,lista_user);
  999.  
  1000. /*NUMERO DE TELEMOVEL*/
  1001. char telemovel[SIZENOME];
  1002.  
  1003. escrever_telemovel(telemovel,lista_user);
  1004.  
  1005. system("cls");
  1006. printf("\n\tCONFIRMAR DADOS\n\nNome:%s\nMorada:%s\nData de Nascimento:%s\nTelemovel:%s\n",nome,morada,data,telemovel);
  1007. printf("\n(1)Confirmar\n(2)Editar\n(3)Cancelar\n");
  1008.  
  1009. scanf("%d",&opcao);
  1010. getchar();
  1011. if(opcao==1)
  1012. {
  1013. inserir_user(lista_user,nome,morada,data,telemovel);
  1014. save_users(lista_user);
  1015.  
  1016. inserir_V(lista_votos,nome,"0;0;0","0","0:");
  1017. save_votos(lista_votos);
  1018.  
  1019. menu(lista_user, lista_locais,lista_votos, nome);
  1020. }
  1021. if(opcao==2)
  1022. {
  1023. registar(lista_user,lista_locais,lista_votos,name);
  1024. }
  1025. if(opcao==3)
  1026. {
  1027. log_in(lista_user,lista_locais,lista_votos,name);
  1028. }
  1029. }
  1030.  
  1031. void alterar_dados(ListU lista_users,ListL lista_locais,ListV lista_votos, char* nome)
  1032. {
  1033. system("cls");
  1034. int opcao;
  1035.  
  1036. printf("\tALTERAR DADOS (%s)",nome);
  1037.  
  1038. printf("\n\n(1)Nome\n(2)Morada\n(3)Data de Nascimento\n(4)Telemovel\n(5)Voltar\n");
  1039.  
  1040. scanf("%d",&opcao);
  1041. getchar();
  1042.  
  1043. while(opcao!=5)
  1044. {
  1045. if(opcao==1)
  1046. {
  1047. printf("\nNome: ");
  1048. char novo_nome[SIZENOME];
  1049.  
  1050. escrever_nome(novo_nome,lista_users);
  1051. alterar_nome(nome,novo_nome,lista_users);
  1052. alterar_nome_votos(lista_users,lista_locais, lista_votos, novo_nome, nome);
  1053.  
  1054. save_users(lista_users);
  1055. save_votos(lista_votos);
  1056.  
  1057. printf("^Nome Alterado Com Sucesso!\n\n");
  1058. strcpy(nome,novo_nome);
  1059.  
  1060. scanf("%d",&opcao);
  1061. getchar();
  1062.  
  1063. }
  1064. if(opcao==2)
  1065. {
  1066. char morada[SIZENOME];
  1067.  
  1068. escrever_morada(morada,lista_users);
  1069. alterar_morada(nome,morada,lista_users);
  1070. save_users(lista_users);
  1071.  
  1072. printf("^Morada Alterada Com Sucesso!\n\n");
  1073. scanf("%d",&opcao);
  1074. getchar();
  1075.  
  1076. }
  1077. if(opcao==3)
  1078. {
  1079. char data[SIZENOME];
  1080.  
  1081. escrever_data(data,lista_users);
  1082. alterar_data(nome,data,lista_users);
  1083. save_users(lista_users);
  1084.  
  1085. printf("^Data De Nascimento Alterada Com Sucesso!\n\n");
  1086.  
  1087. scanf("%d",&opcao);
  1088. getchar();
  1089.  
  1090. }
  1091. if(opcao==4)
  1092. {
  1093. char telemovel[SIZENOME];
  1094.  
  1095. escrever_telemovel(telemovel,lista_users);
  1096. alterar_telemovel(nome,telemovel,lista_users);
  1097. save_users(lista_users);
  1098.  
  1099. printf("^Telemovel Alterado Com Sucesso!\n\n");
  1100.  
  1101. scanf("%d",&opcao);
  1102. getchar();
  1103. }
  1104. }
  1105. ver_dados(lista_users,lista_locais, lista_votos, nome);
  1106.  
  1107. }
  1108.  
  1109. void ver_dados(ListU lista_users,ListL lista_locais,ListV lista_votos, char* nome)
  1110. {
  1111. system("cls");
  1112.  
  1113. int opcao;
  1114.  
  1115. printf("\tDADOS PESSOAIS (%s)",nome);
  1116. imprimir_user(lista_users,nome);
  1117.  
  1118. printf("\n(1)Alterar Dados\n(2)Eliminar Conta\n(3)Voltar ao Menu\n");
  1119.  
  1120. scanf("%d",&opcao);
  1121. getchar();
  1122.  
  1123. if(opcao==1)
  1124. {
  1125. alterar_dados(lista_users,lista_locais,lista_votos, nome);
  1126. }
  1127. if(opcao==2)
  1128. {
  1129. eliminar_user(lista_users,lista_locais,nome);
  1130. save_users(lista_users);
  1131.  
  1132. validar_lista_votos(lista_votos,lista_users);
  1133. save_votos(lista_votos);
  1134.  
  1135. log_in(lista_users,lista_locais, lista_votos, nome);
  1136. }
  1137. if(opcao==3)
  1138. {
  1139. menu(lista_users,lista_locais,lista_votos, nome);
  1140. }
  1141. }
  1142.  
  1143. void votar(ListU lista_users,ListL lista_locais, ListV lista_votos, char* nome)
  1144. {
  1145. system("cls");
  1146. int opcao;
  1147.  
  1148. printf("\tGERIR VOTACOES (%s)\n",nome);
  1149. imprimir_votos(lista_votos,nome);
  1150. printf("(1)Alterar Locais\n(2)Alterar Ponto de Interesse Hot\n(3)Alterar Pontos de Interesse\n(4)Voltar\n\n");
  1151.  
  1152. scanf("%d",&opcao);
  1153. getch();
  1154.  
  1155. if(opcao==1)
  1156. {
  1157. char locais[SIZENOME];
  1158. escrever_locais(lista_users,lista_locais,lista_locais,locais,nome);
  1159. alterar_locais(lista_users, lista_locais, lista_votos,locais, nome);
  1160. save_votos(lista_votos);
  1161.  
  1162. printf("^Locais Alterados Com Sucesso!\n\nPrima Qualquer Tecla Para Sair");
  1163.  
  1164. getch();
  1165. fflush(stdin);
  1166. }
  1167. if(opcao==2)
  1168. {
  1169. char hot[SIZENOME];
  1170. escrever_hot(lista_users,lista_locais,lista_locais,hot,nome);
  1171. alterar_hot(lista_users,lista_locais, lista_votos, hot, nome);
  1172. save_votos(lista_votos);
  1173.  
  1174. printf("^Ponto de Interesse Hot Alterado Com Sucesso!\n\nPrima Qualquer Tecla Para Sair");
  1175.  
  1176. getch();
  1177. fflush(stdin);
  1178. }
  1179. if(opcao==3)
  1180. {
  1181. char pdis[SIZENOME];
  1182. escrever_pdis(lista_users,lista_locais,lista_locais,pdis, nome);
  1183. alterar_pdis(lista_users, lista_locais, lista_votos, pdis, nome);
  1184. save_votos(lista_votos);
  1185.  
  1186. printf("^Pontos de Interesse Alterados Com Sucesso!\n\nPrima Qualquer Tecla Para Sair");
  1187.  
  1188. getch();
  1189. fflush(stdin);
  1190. }
  1191. if(opcao==4)
  1192. {
  1193. menu(lista_users,lista_locais,lista_votos, nome);
  1194. }
  1195.  
  1196. }
  1197.  
  1198. void gerar_viagem(ListU lista_users,ListL lista_locais,ListV lista_votos,char*nome)
  1199. {
  1200. int nada;
  1201. system("cls");
  1202. if(verificar_locais_votados(lista_votos,nome)==1)
  1203. {
  1204. printf("\n\tE Necessario Votar Nos Locais Para Gerar Viagem\n\nPrima Qualquer Tecla Para Sair");
  1205. getch();
  1206. fflush(stdin);
  1207. }
  1208. else
  1209. {
  1210. printf("\tVIAGEM");
  1211. getch();
  1212. fflush(stdin);
  1213. }
  1214.  
  1215. }
  1216.  
  1217. void menu(ListU lista_users,ListL lista_locais, ListV lista_votos, char* nome)
  1218. {
  1219. system("cls");
  1220.  
  1221. int opcao;
  1222. char c[1000];
  1223. printf("Bem Vindo, %s\n\n",nome);
  1224. printf("(1) Dados Pessoais \n");
  1225. printf("(2) Visualizar Locais \n");
  1226. printf("(3) Gerir Votos\n");
  1227. printf("(4) Gerar Viagem\n");
  1228. printf("\n(5) Log Out\n");
  1229. printf("(6) Sair\n");
  1230.  
  1231. scanf("%d",&opcao);
  1232. getchar();
  1233. system("cls");
  1234.  
  1235. switch(opcao)
  1236. {
  1237. case 1:
  1238. system("cls");
  1239. ver_dados(lista_users,lista_locais,lista_votos,nome);
  1240. break;
  1241. case 2:
  1242. system("cls");
  1243. imprime_POIs_az(lista_users,lista_locais,nome);
  1244. break;
  1245. case 3:
  1246. votar(lista_users,lista_locais,lista_votos,nome);
  1247. menu(lista_users,lista_locais,lista_votos,nome);
  1248. break;
  1249. case 4:
  1250. system("cls");
  1251. gerar_viagem(lista_users,lista_locais,lista_votos,nome);
  1252. menu(lista_users,lista_locais,lista_votos,nome);
  1253. break;
  1254. case 5:
  1255. system("cls");
  1256. log_in(lista_users,lista_locais,lista_votos,nome);
  1257. break;
  1258. case 6:
  1259. break;
  1260.  
  1261. }
  1262. }
  1263.  
  1264. int main()
  1265. {
  1266. ListU lista_users=cria_lista_users();
  1267. ListL lista_POI=cria_lista_POI();
  1268. ListV lista_votos=cria_lista_V();
  1269.  
  1270. load_POI(lista_POI);
  1271. load_users(lista_users);
  1272. load_votos(lista_votos);
  1273.  
  1274. char nome[SIZENOME];
  1275.  
  1276. log_in(lista_users,lista_POI,lista_votos,nome);
  1277. /*
  1278. imprime_lista_votos(lista_votos);
  1279. validar_lista_votos(lista_votos,lista_users);
  1280. save_votos(lista_votos);
  1281. imprime_lista_votos(lista_votos);
  1282.  
  1283. votar(lista_users,lista_POI,lista_votos, nome);
  1284.  
  1285. char locais[SIZENOME];
  1286. escrever_locais(lista_users, lista_POI, lista_votos,locais, nome);
  1287. alterar_locais(lista_users,lista_POI, lista_votos, locais, nome);
  1288. alterar_hot(lista_users,lista_POI, lista_votos, "blond", nome);
  1289. alterar_pdis(lista_users,lista_POI, lista_votos, "nostalgia ultra", nome);
  1290.  
  1291. imprime_lista_votos(lista_votos);
  1292.  
  1293. printf("\n\nverificar PDI |%s|: %d\n",hot,verificar_POI(lista_POI,hot));
  1294. printf("\nverificar PDI |%s|: %d\n",pdis,verificar_POI(lista_POI,pdis));
  1295. printf("\nverificar HOT |%s|: %d\n",hot,verificar_hot(lista_votos,hot,nome));
  1296. printf("\nverificar PDIS |%s|: %d\n",pdis,verificar_pdis(lista_votos,pdis,nome));
  1297.  
  1298. escrever_hot(lista_users,lista_POI,lista_votos,hot,nome);
  1299. alterar_hot(lista_users,lista_POI,lista_votos,hot,nome);
  1300.  
  1301. imprimir_votos(lista_votos,nome);
  1302.  
  1303. escrever_pdis(lista_users,lista_POI,lista_votos,pdis,nome);
  1304. alterar_pdis(lista_users,lista_POI,lista_votos,pdis,nome);
  1305.  
  1306. imprimir_votos(lista_votos,nome);
  1307.  
  1308. save_votos(lista_votos);
  1309.  
  1310. escrever_hot(lista_users,lista_POI,lista_votos,hot,nome);
  1311. alterar_hot(lista_users,lista_POI,lista_votos,hot,nome);*/
  1312.  
  1313. return 0;
  1314. }
  1315.  
  1316. /*
  1317. typedef struct pessoa
  1318. typedef struct Locais
  1319.  
  1320. ListU cria_lista_users()
  1321. ListL cria_lista_POI()
  1322.  
  1323. int lista_vazia_POI(ListL h)
  1324. int lista_vazia_users(ListU h)
  1325.  
  1326. void liberta_lista(ListU lista)
  1327.  
  1328.  
  1329. void inserir_user(ListU h, char *nome, char *morada, char* data_nascimento, char *telefone)
  1330. void inserir_POI(ListL h, char *local, char *nome, char* info, char *horario)
  1331.  
  1332. void imprime_lista_POI(ListL lista)
  1333. void imprime_POIs_az(ListL lista)
  1334. void imprime_lista_users(ListU lista)
  1335. void imprimir_user(ListU lista,char*nome)
  1336. void listar_locais(ListL lista)
  1337. void listar_PdIs(ListL lista)
  1338. void imprimir_votos(ListV lista,char*nome)
  1339.  
  1340.  
  1341.  
  1342. void load_users(ListU lista_users)
  1343. void eliminar_user(ListU lista,char *nome)
  1344. void alterar_dados(ListU lista_users,ListL lista_locais,char* nome)
  1345. void load_POI(ListL lista)
  1346. void save_users(ListU lista)
  1347.  
  1348. int verificar_local(ListL lista,char* local)
  1349. int verificar_POI(ListL lista,char* nome)
  1350. int verificar_user(ListU lista,char* nome)
  1351. int verificar_telemovel(char* telemovel)
  1352. int verificar_nome(char* nome)
  1353. int verificar_morada(char* nome)
  1354. int verificar_data(int dia,int mes,int ano)
  1355.  
  1356. void alterar_telemovel(char*nome,char*string,ListU lista)
  1357. void alterar_data(char*nome,char*string,ListU lista)
  1358. void alterar_morada(char*nome,char*string,ListU lista)
  1359. void alterar_nome(char*nome,char*string,ListU lista)
  1360.  
  1361. void escrever_telemovel(char*string,ListU lista_user)
  1362. void escrever_data(char*string,ListU lista_user)
  1363. void escrever_morada(char*string,ListU lista_user)
  1364. void escrever_nome(char*string,ListU lista_user)
  1365.  
  1366. void escrever_locais(ListU lista_users,ListL lista_locais, ListV lista_votos,char *string)
  1367. escrever_hot()
  1368.  
  1369. escrever_pdis()
  1370.  
  1371. void alterar_locais(lista_users, lista_locais, lista_votos, string)
  1372. alterar_hot(lista_users,lista_locais, lista_votos, nome)
  1373. alterar_pdis(lista_users, lista_locais, lista_votos, nome);
  1374.  
  1375.  
  1376.  
  1377. void log_in(ListU lista_users)
  1378. void registar(ListU lista_user)
  1379. void ver_dados(ListU lista_users,ListL lista_locais,char* nome)
  1380. void alterar_dados(ListU lista_users,char* nome)
  1381.  
  1382. void menu(ListU lista_users)*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement