Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define SIZENOME 3000
- #define MIN_NOME 5
- typedef struct pessoa *ListU;
- typedef struct pessoa
- {
- char nome[SIZENOME];
- char morada[SIZENOME];
- char data_nascimento[SIZENOME];
- char telefone[SIZENOME];
- ListU next;
- }pnode;
- typedef struct Locais *ListL;
- typedef struct Locais
- {
- char local[SIZENOME];
- char nome[SIZENOME];
- char info[SIZENOME];
- char horario[SIZENOME];
- ListL next;
- }pnodeL;
- typedef struct votos *ListV;
- typedef struct votos
- {
- char user[SIZENOME];
- char locais[SIZENOME];
- char hot[SIZENOME];
- char pdis[SIZENOME];
- ListV next;
- }pnodeV;
- ListU cria_lista_users()
- {
- ListU h=(ListU)malloc(sizeof(pnode));
- h->next=NULL;
- return h;
- }
- ListL cria_lista_POI()
- {
- ListL h=(ListL)malloc(sizeof(pnodeL));
- h->next=NULL;
- return h;
- }
- ListV cria_lista_V()
- {
- ListV h=(ListV)malloc(sizeof(pnodeV));
- h->next=NULL;
- return h;
- }
- int lista_vazia_POI(ListL h)
- {
- return h->next==NULL;
- }
- int lista_vazia_users(ListU h)
- {
- return h->next==NULL;
- }
- int lista_vazia_V(ListV h)
- {
- return h->next==NULL;
- }
- void inserir_user(ListU h, char *nome, char *morada, char* data_nascimento, char *telefone)
- {
- while(!lista_vazia_users(h))
- {
- ListU aux=h->next;
- h=aux;
- }
- ListU last=(ListU)malloc(sizeof(pnode));
- strcpy(last->nome,nome);
- strcpy(last->morada,morada);
- strcpy(last->data_nascimento,data_nascimento);
- strcpy(last->telefone,telefone);
- h->next=last;
- }
- void inserir_POI(ListL h, char *local, char *nome, char* info, char *horario)
- {
- while(!lista_vazia_POI(h))
- {
- ListL aux=h->next;
- h=aux;
- }
- ListL last=(ListL)malloc(sizeof(pnodeL));
- strcpy(last->local,local);
- strcpy(last->nome,nome);
- strcpy(last->info,info);
- strcpy(last->horario,horario);
- h->next=last;
- }
- void inserir_V(ListV h, char *user, char *locais, char* hot, char *pdis)
- {
- while(!lista_vazia_POI(h))
- {
- ListV aux=h->next;
- h=aux;
- }
- ListV last=(ListV)malloc(sizeof(pnodeV));
- strcpy(last->user,user);
- strcpy(last->locais,locais);
- strcpy(last->hot,hot);
- strcpy(last->pdis,pdis);
- h->next=last;
- }
- void imprime_lista_POI(ListL lista)
- {
- lista = lista->next;
- while(lista!=NULL){
- printf("\nLocal: %s\nNome: %s\nInformacao: %s\nHorario:%s\n",
- lista->local,
- lista->nome,
- lista->info,
- lista->horario);
- lista=lista->next;
- }
- }
- void listar_locais(ListL lista)
- {
- lista = lista->next;
- char nome_aux[SIZENOME];
- strcpy(nome_aux,"");
- printf("\n\tLOCAIS");
- while(lista!=NULL)
- {
- if(strcmp(lista->local,nome_aux)!=0)
- {
- printf("\n%s",
- lista->local);
- }
- strcpy(nome_aux,lista->local);
- lista=lista->next;
- }
- printf("\n");
- }
- void listar_PdIs(ListL lista)
- {
- lista = lista->next;
- char nome_aux[SIZENOME];
- strcpy(nome_aux,"");
- printf("\n\tPONTOS DE INTERESSE\n");
- while(lista!=NULL)
- {
- if(strcmp(lista->local,nome_aux)!=0)
- {
- printf("LOCAL: %s\n\tNome: %s\n",
- lista->local,
- lista->nome);
- }
- else
- {
- printf("\t-%s\n",lista->nome);
- }
- strcpy(nome_aux,lista->local);
- lista=lista->next;
- }
- printf("\n");
- }
- void imprime_POIs_az(ListU lista_users,ListL lista, char *nome)
- {
- int opcao;
- lista = lista->next;
- char nome_aux[SIZENOME];
- strcpy(nome_aux,"");
- printf("\n\tLOCAIS\n\n");
- while(lista!=NULL)
- {
- if(strcmp(lista->local,nome_aux)!=0)
- {
- printf("\nLOCAL: %s\n\n\tNome: %s\n\tInformacao: %s\n\tHorario:%s\n",
- lista->local,
- lista->nome,
- lista->info,
- lista->horario);
- }
- else
- {
- printf("\n\tNome: %s\n\tInformacao: %s\n\tHorario:%s\n",
- lista->nome,
- lista->info,
- lista->horario);
- }
- strcpy(nome_aux,lista->local);
- lista=lista->next;
- }
- printf("\n(1)Voltar ao menu\n");
- scanf("%d",&opcao);
- getchar();
- if(opcao==1)
- {
- menu(lista_users,lista,nome);
- }
- /*printf("\n<<%d POIs imprimidos c sucesso.>>\n",cont);*/
- }
- void imprime_lista_users(ListU lista)
- {
- int cont=0;
- lista = lista->next;
- while(lista!=NULL){
- printf("\nNome: %s\nMorada: %s\nData de Nascimento: %s\nTelefone:%s\n",
- lista->nome,
- lista->morada,
- lista->data_nascimento,
- lista->telefone);
- lista=lista->next;
- cont++;
- }
- printf("\n<<%d users imprimidos c sucesso.>>\n",cont);
- }
- void imprimir_user(ListU lista,char*nome)
- {
- lista=lista->next;
- while(lista!=NULL)
- {
- if(strcmp(lista->nome,nome)==0)
- {
- printf("\n\nNome: %s\nMorada: %s\nData de Nascimento: %s\nTelefone:%s\n",
- lista->nome,
- lista->morada,
- lista->data_nascimento,
- lista->telefone);
- }
- lista = lista->next;
- }
- }
- void imprimir_votos(ListV lista,char*nome)
- {
- lista=lista->next;
- while(lista!=NULL)
- {
- if(strcmp(lista->user,nome)==0)
- {
- printf("\nVOTOS\n Locais: ");
- imprimir_locais(lista->locais);
- printf("\n Ponto de Interesse Hot: ");
- imprimir_hot(lista->hot);
- printf("\n Pontos de Interese: ");
- imprimir_pdis(lista->pdis);
- printf("\n\n");
- }
- lista = lista->next;
- }
- }
- void imprimir_locais(char*string)
- {
- char local_1[SIZENOME],local_2[SIZENOME],local_3[SIZENOME];
- if(strcmp(string,"0;0;0")==0)
- {
- printf("[Ainda Nao Votados]");
- }
- else
- {
- sscanf(string,"%[^;];%[^;];%[^;]",local_1,local_2,local_3);
- printf("\n -%s \n -%s \n -%s",local_1,local_2,local_3);
- }
- }
- void imprimir_pdis(char*string)
- {
- if(strcmp(string,"0:")==0)
- {
- printf("[Ainda Nao Votado]");
- }
- else
- {
- printf("%s",string);
- }
- }
- void imprimir_hot(char*string)
- {
- if(strcmp(string,"0")==0)
- {
- printf("[Ainda Nao Votado]");
- }
- else
- {
- printf("%s",string);
- }
- }
- void imprime_lista_votos(ListV lista)
- {
- lista=lista->next;
- while(lista!=NULL)
- {
- printf("\nUser: %s\nLocais: %s\nPdI Hot: %s\nPdIs: %s\n",
- lista->user,
- lista->locais,
- lista->hot,
- lista->pdis);
- lista = lista->next;
- }
- }
- void liberta_lista_user(ListU lista)
- {
- ListU aux;
- aux=lista->next;
- free(lista);
- lista=aux;
- while(lista!=NULL){
- aux=lista->next;
- free(lista);
- lista = aux;
- }
- }
- void load_users(ListU lista_users)
- {
- char nome[SIZENOME];
- char morada[SIZENOME];
- char data_nascimento[SIZENOME];
- char telefone[SIZENOME];
- char buffer[SIZENOME*4];
- FILE*f=fopen("users.txt","r");
- while(fgets(buffer,1000,f)!=NULL)
- {
- sscanf(buffer,"%[^:]:%[^:]:%[^:]:%[^\n]",nome,morada,data_nascimento,telefone);
- inserir_user(lista_users,nome,morada,data_nascimento,telefone);
- }
- fclose(f);
- }
- void eliminar_user(ListU lista,ListL lista_locais,char *nome)
- {
- system("cls");
- int opcao;
- printf("\tELIMINAR CONTA");
- imprimir_user(lista,nome);
- printf("\nTem a certeza que quer eliminar todos os seus dados e votos?\n(1)Confirmar\n(2)Voltar ao menu\n");
- scanf("%d",&opcao);
- getchar();
- if(opcao==1)
- {
- ListU p,q;
- p = lista;
- q = lista->next;
- while (q != NULL && !strcmp(q->nome,nome)==0)
- {
- p = q;
- q = q->next;
- }
- if (q != NULL)
- {
- p->next = q->next;
- free (q);
- }
- }
- if(opcao==2)
- {
- menu(lista,lista_locais,nome);
- }
- }
- void eliminar_user_votos(ListV lista,char *nome)
- {
- ListV p,q;
- p = lista;
- q = lista->next;
- while (q != NULL && !strcmp(q->user,nome)==0)
- {
- p = q;
- q = q->next;
- }
- if (q != NULL)
- {
- p->next = q->next;
- free (q);
- }
- }
- void load_POI(ListL lista)
- {
- char local[SIZENOME];
- char nome[SIZENOME];
- char info[SIZENOME];
- char horario[SIZENOME];
- char buffer[SIZENOME*4];
- FILE*f=fopen("POIs.txt","r");
- while(fgets(buffer,1000,f)!=NULL)
- {
- sscanf(buffer,"%[^|]|%[^:]:%[^|]|%[^\n]",
- local,
- nome,
- info,
- horario);
- inserir_POI(lista,local,nome,info,horario);
- }
- fclose(f);
- }
- void load_votos(ListV lista)
- {
- char user[SIZENOME];
- char locais[SIZENOME];
- char hot[SIZENOME];
- char pdis[SIZENOME*4];
- char buffer[SIZENOME*8];
- FILE*f=fopen("votos.txt","r");
- while(fgets(buffer,1000,f)!=NULL)
- {
- sscanf(buffer,"%[^|]|%[^|]|%[^|]|%[^\n]",
- user,
- locais,
- hot,
- pdis);
- inserir_V(lista,user,locais,hot,pdis);
- }
- fclose(f);
- }
- void save_users(ListU lista)
- {
- int cont=0;
- FILE*f=fopen("users.txt","w");
- ListU l = lista->next;
- while(l){
- fprintf(f,"%s:%s:%s:%s\n",
- l->nome,
- l->morada,
- l->data_nascimento,
- l->telefone);
- cont++;
- l=l->next;
- }
- fclose(f);
- }
- void save_votos(ListV lista)
- {
- int cont=0;
- FILE*f=fopen("votos.txt","w");
- ListV l = lista->next;
- while(l){
- fprintf(f,"%s|%s|%s|%s\n",
- l->user,
- l->locais,
- l->hot,
- l->pdis);
- cont++;
- l=l->next;
- }
- fclose(f);
- }
- void validar_lista_votos(ListV lista,ListU lista_user)
- {
- ListV l=lista;
- lista=lista->next;
- while(lista!=NULL)
- {
- if(verificar_user(lista_user,lista->user)==1)
- printf("\nUser %s validado!",lista->user);
- else
- {
- printf("\nUser %s nao validado. Eliminado.",lista->user);
- eliminar_user_votos(l,lista->user);
- }
- lista = lista->next;
- }
- printf("\n");
- }
- int verificar_local(ListL lista,char* local)
- {
- lista = lista->next;
- while(lista!=NULL)
- {
- if(strcmp(lista->local,local)==0)
- return 1;
- lista = lista->next;
- }
- return 0;
- }
- int verificar_locais_votados(ListV lista, char*nome)
- {
- lista = lista->next;
- while(lista!=NULL)
- {
- if(strcmp(lista->user,nome)==0)
- {
- /*printf("%s",lista->locais);*/
- if(strcmp(lista->locais,"0;0;0")==0)
- return 1;
- }
- lista = lista->next;
- }
- return 0;
- }
- int verificar_POI(ListL lista,char* nome)
- {
- lista = lista->next;
- while(lista!=NULL)
- {
- if(strcmp(lista->nome,nome)==0)
- return 1;
- lista = lista->next;
- }
- return 0;
- }
- int verificar_hot(ListV lista,char*hot,char* nome)
- {
- lista = lista->next;
- while(lista!=NULL)
- {
- if(strcmp(lista->user,nome)==0)
- {
- /*printf("\n\t<<nome encontrado! %s = %s>>\n",lista->user,nome);*/
- if(strstr(lista->pdis,hot)!=NULL)
- {
- /*printf("\n\t<<[VERIF HOT] HOT:%s encontrado nos PDIS no indice %d de %s>>\n",hot,strstr(lista->pdis,hot),lista->pdis);*/
- return 1;
- }
- /*printf("\n\t[VERIF HOT] <<HOT:%s NAO encontrado nos PDIS %s>>\n",hot,lista->pdis);*/
- }
- lista = lista->next;
- }
- return 0;
- }
- int verificar_pdis(ListV lista,char*pdis,char* nome)
- {
- lista = lista->next;
- while(lista!=NULL)
- {
- if(strcmp(lista->user,nome)==0)
- {
- /*printf("\n\t<<nome encontrado! %s = %s>>\n",lista->user,nome);*/
- if(strcmp(pdis,lista->hot)==0)
- {
- return 1;
- printf("\n\tHOT JA EXISTENTE!!");
- }
- /*printf("\n\t<<[VERIF PDIS] HOT:%s| NAO EH IGUAL AO PDI |%s>>\n",lista->hot,pdis);*/
- }
- lista = lista->next;
- }
- return 0;
- }
- int verificar_user(ListU lista,char* nome) /*1 se encontra, 0 se n encontra*/
- {
- lista=lista->next;
- while(lista!=NULL)
- {
- if(strcmp(lista->nome,nome)==0)
- return 1;
- lista = lista->next;
- }
- return 0;
- }
- int verificar_telemovel(char* telemovel)
- {
- char nums[]="0123456789";
- if(strlen(telemovel)>9)/*numero n pode ultrapassar 9 caracteres, 9 algarismos*/
- return 1;
- if(strspn(telemovel,nums)!=9)/*strspn identifica ate q ponto o telemovel contem caracteres iguais a nums, neste caso garantindo q seja valido*/
- return 1;
- return 0;
- }
- int verificar_nome(char* nome)
- {
- char letras[]="ABCDEFGHIJKLMNOPQRSTUVXZWYabcdefghijklmnopqrstuvxzwy ";
- if(strlen(nome)<MIN_NOME)/*tem de ser maior q min nome*/
- return 1;
- if(strspn(nome,letras)!=strlen(nome))/*so pode ter letras e espacos*/
- return 1;
- return 0;
- }
- int verificar_morada(char* nome)
- {
- char letras[]="ABCDEFGHIJKLMNOPQRSTUVXZWYabcdefghijklmnopqrstuvxzwy 1234567890.";
- if(strlen(nome)<MIN_NOME*2)/*tem de ser maior q min nome*/
- return 1;
- if(strspn(nome,letras)!=strlen(nome))/*so pode ter letras e espacos*/
- return 1;
- return 0;
- }
- int verificar_data(int dia,int mes,int ano)
- {
- int bissexto;
- if ( ( ano % 4 == 0 && ano % 100 != 0 ) || ano % 400 == 0 )
- bissexto=1;
- else
- bissexto=0;
- if ((dia>31) && ((mes==1) || (mes==3) || (mes==5) || (mes==7) || (mes==8) || (mes==10) || (mes==12)))
- return 0;
- if ((dia>30) && ((mes==4) || (mes==6) || (mes==9) || (mes==11)))
- return 0;
- if ((dia>29) && (mes==2) && (bissexto==1))
- return 0;
- if ((dia>28) && (mes==2) && (bissexto==0))
- return 0;
- if(mes>12)
- return 0;
- if(ano<=1903||ano>2019)
- return 0;
- else
- return 1;
- }
- void log_in(ListU lista_users, ListL lista_locais,ListV lista_votos, char *name)
- {
- system("cls");
- printf("******************************\n\n\tLOG-IN\n\nNome: ");
- int opcao;
- char nome[SIZENOME];
- fgets(nome,sizeof(nome)+1,stdin);
- 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*/
- if(verificar_user(lista_users,nome)!=1)
- {
- system("cls");
- printf("\t%s Nao Registado.\n\n(1)Tentar Outra Vez\n(2)Registar Novo User\n\n",nome);
- scanf("%d",&opcao);
- getchar();
- if(opcao==1)
- {
- log_in(lista_users,lista_locais,lista_votos,name);
- }
- if(opcao==2)
- {
- registar(lista_users,lista_locais,lista_votos,name);
- }
- }
- else
- {
- system("cls");
- strcpy(name,nome);
- printf("Bem Vindo, %s\n",name);
- menu(lista_users,lista_locais,lista_votos,name);
- }
- }
- void escrever_nome(char*string,ListU lista_user)
- {
- char nome[SIZENOME];
- fgets(nome,sizeof(nome)+1,stdin);
- 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*/
- while(verificar_user(lista_user,nome)==1||verificar_nome(nome)==1)
- {
- 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);
- nome[strlen(nome)-1]='\0';
- printf("\n\nNome: ");
- fgets(nome,sizeof(nome)+1,stdin);
- nome[strlen(nome)-1]='\0';
- }
- strcpy(string,nome);
- }
- void escrever_morada(char*string,ListU lista_user)
- {
- char morada[SIZENOME];
- printf("\nMorada: ");
- fgets(morada,sizeof(morada)+1,stdin);
- 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*/
- while(verificar_morada(morada)==1)
- {
- printf("^Morada Invalida\n-Tem de ter mais de %d caracteres\n-So pode conter letras, numeros, espacos e pontos",MIN_NOME*2);
- morada[strlen(morada)-1]='\0';
- printf("\nMorada: ");
- fgets(morada,sizeof(morada)+1,stdin);
- morada[strlen(morada)-1]='\0';
- }
- strcpy(string,morada);
- }
- void escrever_data(char*string,ListU lista_user)
- {
- char data[SIZENOME];
- int dia,mes,ano;
- printf("\nData de Nascimento (DD/MM/AAAA): ");
- scanf("%d/%d/%d",&dia,&mes,&ano);
- fflush(stdin);
- while(verificar_data(dia,mes,ano)==0)
- {
- 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");
- printf("\n\nData de Nascimento (DD/MM/AAAA): ");
- scanf("%d/%d/%d",&dia,&mes,&ano);
- fflush(stdin);
- }
- sprintf(data, "%d/%d/%d", dia,mes,ano);
- strcpy(string,data);
- }
- void escrever_telemovel(char*string,ListU lista_user)
- {
- char telemovel[SIZENOME];
- printf("\nTelemovel: ");
- fgets(telemovel,sizeof(telemovel)+1,stdin);
- telemovel[strlen(telemovel)-1]='\0';
- while(verificar_telemovel(telemovel)==1)
- {
- printf("^Numero de Telemovel Invalido\n-Tem de ser 9 numeros");
- printf("\n\nTelemovel: ");
- fgets(telemovel,sizeof(telemovel)+1,stdin);
- telemovel[strlen(telemovel)-1]='\0';
- }
- strcpy(string,telemovel);
- }
- void escrever_locais(ListU lista_users,ListL lista_locais, ListV lista_votos,char *string, char*nome)
- {
- listar_locais(lista_locais);
- char locais[SIZENOME];
- char local[SIZENOME];
- strcpy(locais,"");
- int i=0;
- while(i<3)
- {
- printf("\nLocal %d: ",i+1);
- fgets(local,sizeof(local)+1,stdin);
- local[strlen(local)-1]='\0';
- while(verificar_local(lista_locais,local)==0||strstr(locais,local)!=NULL)
- {
- printf("^Local Nao Existente ou Repetido\n");
- printf("\nLocal %d: ",i+1);
- fgets(local,sizeof(local)+1,stdin);
- local[strlen(local)-1]='\0';
- }
- strcat(locais,local);
- if(i<2)
- strcat(locais,";");
- i++;
- }
- strcpy(string,locais);
- }
- void escrever_hot(ListU lista_users,ListL lista_locais, ListV lista_votos,char *string, char*nome)
- {
- char hot[SIZENOME];
- listar_PdIs(lista_locais);
- printf("\nPonto de Interesse Hot: ");
- fgets(hot,sizeof(hot)+1,stdin);
- hot[strlen(hot)-1]='\0';
- while(verificar_hot(lista_votos,hot,nome)==1||verificar_POI(lista_locais,hot)==0)
- {
- printf("^Ponto de Interesse Hot Invalido\n-Tem de Pertencer a Lista\n-Nao Pode Ja Existir Nos Pontos de Interesse Favoritos\n");
- printf("\n\nPonto de Interesse Hot: ");
- fgets(hot,sizeof(hot)+1,stdin);
- hot[strlen(hot)-1]='\0';
- }
- strcpy(string,hot);
- }
- void escrever_pdis(ListU lista_users,ListL lista_locais, ListV lista_votos,char *string, char*nome)
- {
- char pdi[SIZENOME];
- char pdis[SIZENOME];
- strcpy(pdis,"");
- listar_PdIs(lista_locais);
- int i=0;
- while(i<3)
- {
- printf("\nPonto de Interesse : ");
- fgets(pdi,sizeof(pdi)+1,stdin);
- pdi[strlen(pdi)-1]='\0';
- while(verificar_pdis(lista_votos,pdi,nome)==1||verificar_POI(lista_locais,pdi)==0||strstr(pdis,pdi)!=NULL)
- {
- 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));
- printf("\n\nPonto de Interesse: ");
- fgets(pdi,sizeof(pdi)+1,stdin);
- pdi[strlen(pdi)-1]='\0';
- }
- strcat(pdis,pdi);
- if(i<2)
- strcat(pdis,";");
- i++;
- }
- strcpy(string,pdis);
- }
- void alterar_nome_votos(ListU lista_users,ListL lista_locais, ListV lista, char*string,char*nome)
- {
- lista=lista->next;
- while(lista!=NULL)
- {
- if(strcmp(lista->user,nome)==0)
- strcpy(lista->user,string);
- lista = lista->next;
- }
- }
- void alterar_locais(ListU lista_users,ListL lista_locais, ListV lista, char*string,char*nome)
- {
- lista=lista->next;
- while(lista!=NULL)
- {
- if(strcmp(lista->user,nome)==0)
- strcpy(lista->locais,string);
- lista = lista->next;
- }
- }
- void alterar_hot(ListU lista_users,ListL lista_locais, ListV lista, char*string, char*nome)
- {
- lista=lista->next;
- while(lista!=NULL)
- {
- if(strcmp(lista->user,nome)==0)
- strcpy(lista->hot,string);
- lista = lista->next;
- }
- }
- void alterar_pdis(ListU lista_users,ListL lista_locais, ListV lista, char*string, char*nome)
- {
- lista=lista->next;
- while(lista!=NULL)
- {
- if(strcmp(lista->user,nome)==0)
- strcpy(lista->pdis,string);
- lista = lista->next;
- }
- }
- void alterar_nome(char*nome,char*string,ListU lista)
- {
- lista=lista->next;
- while(lista!=NULL)
- {
- if(strcmp(lista->nome,nome)==0)
- strcpy(lista->nome,string);
- lista = lista->next;
- }
- }
- void alterar_morada(char*nome,char*string,ListU lista)
- {
- lista=lista->next;
- while(lista!=NULL)
- {
- if(strcmp(lista->nome,nome)==0)
- strcpy(lista->morada,string);
- lista = lista->next;
- }
- }
- void alterar_data(char*nome,char*string,ListU lista)
- {
- lista=lista->next;
- while(lista!=NULL)
- {
- if(strcmp(lista->nome,nome)==0)
- strcpy(lista->data_nascimento,string);
- lista = lista->next;
- }
- }
- void alterar_telemovel(char*nome,char*string,ListU lista)
- {
- lista=lista->next;
- while(lista!=NULL)
- {
- if(strcmp(lista->nome,nome)==0)
- strcpy(lista->telefone,string);
- lista = lista->next;
- }
- }
- void registar(ListU lista_user, ListL lista_locais,ListV lista_votos, char*name)
- {
- int opcao;
- system("cls");
- printf("******************************\n\n\tREGISTAR\n\nNome: ");
- /*NOME*/
- char nome[SIZENOME];
- escrever_nome(nome,lista_user);
- /*Morada*/
- char morada[SIZENOME];
- escrever_morada(morada,lista_user);
- /*DATA NASCIMENTO*/
- char data[SIZENOME];
- escrever_data(data,lista_user);
- /*NUMERO DE TELEMOVEL*/
- char telemovel[SIZENOME];
- escrever_telemovel(telemovel,lista_user);
- system("cls");
- printf("\n\tCONFIRMAR DADOS\n\nNome:%s\nMorada:%s\nData de Nascimento:%s\nTelemovel:%s\n",nome,morada,data,telemovel);
- printf("\n(1)Confirmar\n(2)Editar\n(3)Cancelar\n");
- scanf("%d",&opcao);
- getchar();
- if(opcao==1)
- {
- inserir_user(lista_user,nome,morada,data,telemovel);
- save_users(lista_user);
- inserir_V(lista_votos,nome,"0;0;0","0","0:");
- save_votos(lista_votos);
- menu(lista_user, lista_locais,lista_votos, nome);
- }
- if(opcao==2)
- {
- registar(lista_user,lista_locais,lista_votos,name);
- }
- if(opcao==3)
- {
- log_in(lista_user,lista_locais,lista_votos,name);
- }
- }
- void alterar_dados(ListU lista_users,ListL lista_locais,ListV lista_votos, char* nome)
- {
- system("cls");
- int opcao;
- printf("\tALTERAR DADOS (%s)",nome);
- printf("\n\n(1)Nome\n(2)Morada\n(3)Data de Nascimento\n(4)Telemovel\n(5)Voltar\n");
- scanf("%d",&opcao);
- getchar();
- while(opcao!=5)
- {
- if(opcao==1)
- {
- printf("\nNome: ");
- char novo_nome[SIZENOME];
- escrever_nome(novo_nome,lista_users);
- alterar_nome(nome,novo_nome,lista_users);
- alterar_nome_votos(lista_users,lista_locais, lista_votos, novo_nome, nome);
- save_users(lista_users);
- save_votos(lista_votos);
- printf("^Nome Alterado Com Sucesso!\n\n");
- strcpy(nome,novo_nome);
- scanf("%d",&opcao);
- getchar();
- }
- if(opcao==2)
- {
- char morada[SIZENOME];
- escrever_morada(morada,lista_users);
- alterar_morada(nome,morada,lista_users);
- save_users(lista_users);
- printf("^Morada Alterada Com Sucesso!\n\n");
- scanf("%d",&opcao);
- getchar();
- }
- if(opcao==3)
- {
- char data[SIZENOME];
- escrever_data(data,lista_users);
- alterar_data(nome,data,lista_users);
- save_users(lista_users);
- printf("^Data De Nascimento Alterada Com Sucesso!\n\n");
- scanf("%d",&opcao);
- getchar();
- }
- if(opcao==4)
- {
- char telemovel[SIZENOME];
- escrever_telemovel(telemovel,lista_users);
- alterar_telemovel(nome,telemovel,lista_users);
- save_users(lista_users);
- printf("^Telemovel Alterado Com Sucesso!\n\n");
- scanf("%d",&opcao);
- getchar();
- }
- }
- ver_dados(lista_users,lista_locais, lista_votos, nome);
- }
- void ver_dados(ListU lista_users,ListL lista_locais,ListV lista_votos, char* nome)
- {
- system("cls");
- int opcao;
- printf("\tDADOS PESSOAIS (%s)",nome);
- imprimir_user(lista_users,nome);
- printf("\n(1)Alterar Dados\n(2)Eliminar Conta\n(3)Voltar ao Menu\n");
- scanf("%d",&opcao);
- getchar();
- if(opcao==1)
- {
- alterar_dados(lista_users,lista_locais,lista_votos, nome);
- }
- if(opcao==2)
- {
- eliminar_user(lista_users,lista_locais,nome);
- save_users(lista_users);
- validar_lista_votos(lista_votos,lista_users);
- save_votos(lista_votos);
- log_in(lista_users,lista_locais, lista_votos, nome);
- }
- if(opcao==3)
- {
- menu(lista_users,lista_locais,lista_votos, nome);
- }
- }
- void votar(ListU lista_users,ListL lista_locais, ListV lista_votos, char* nome)
- {
- system("cls");
- int opcao;
- printf("\tGERIR VOTACOES (%s)\n",nome);
- imprimir_votos(lista_votos,nome);
- printf("(1)Alterar Locais\n(2)Alterar Ponto de Interesse Hot\n(3)Alterar Pontos de Interesse\n(4)Voltar\n\n");
- scanf("%d",&opcao);
- getch();
- if(opcao==1)
- {
- char locais[SIZENOME];
- escrever_locais(lista_users,lista_locais,lista_locais,locais,nome);
- alterar_locais(lista_users, lista_locais, lista_votos,locais, nome);
- save_votos(lista_votos);
- printf("^Locais Alterados Com Sucesso!\n\nPrima Qualquer Tecla Para Sair");
- getch();
- fflush(stdin);
- }
- if(opcao==2)
- {
- char hot[SIZENOME];
- escrever_hot(lista_users,lista_locais,lista_locais,hot,nome);
- alterar_hot(lista_users,lista_locais, lista_votos, hot, nome);
- save_votos(lista_votos);
- printf("^Ponto de Interesse Hot Alterado Com Sucesso!\n\nPrima Qualquer Tecla Para Sair");
- getch();
- fflush(stdin);
- }
- if(opcao==3)
- {
- char pdis[SIZENOME];
- escrever_pdis(lista_users,lista_locais,lista_locais,pdis, nome);
- alterar_pdis(lista_users, lista_locais, lista_votos, pdis, nome);
- save_votos(lista_votos);
- printf("^Pontos de Interesse Alterados Com Sucesso!\n\nPrima Qualquer Tecla Para Sair");
- getch();
- fflush(stdin);
- }
- if(opcao==4)
- {
- menu(lista_users,lista_locais,lista_votos, nome);
- }
- }
- void gerar_viagem(ListU lista_users,ListL lista_locais,ListV lista_votos,char*nome)
- {
- int nada;
- system("cls");
- if(verificar_locais_votados(lista_votos,nome)==1)
- {
- printf("\n\tE Necessario Votar Nos Locais Para Gerar Viagem\n\nPrima Qualquer Tecla Para Sair");
- getch();
- fflush(stdin);
- }
- else
- {
- printf("\tVIAGEM");
- getch();
- fflush(stdin);
- }
- }
- void menu(ListU lista_users,ListL lista_locais, ListV lista_votos, char* nome)
- {
- system("cls");
- int opcao;
- char c[1000];
- printf("Bem Vindo, %s\n\n",nome);
- printf("(1) Dados Pessoais \n");
- printf("(2) Visualizar Locais \n");
- printf("(3) Gerir Votos\n");
- printf("(4) Gerar Viagem\n");
- printf("\n(5) Log Out\n");
- printf("(6) Sair\n");
- scanf("%d",&opcao);
- getchar();
- system("cls");
- switch(opcao)
- {
- case 1:
- system("cls");
- ver_dados(lista_users,lista_locais,lista_votos,nome);
- break;
- case 2:
- system("cls");
- imprime_POIs_az(lista_users,lista_locais,nome);
- break;
- case 3:
- votar(lista_users,lista_locais,lista_votos,nome);
- menu(lista_users,lista_locais,lista_votos,nome);
- break;
- case 4:
- system("cls");
- gerar_viagem(lista_users,lista_locais,lista_votos,nome);
- menu(lista_users,lista_locais,lista_votos,nome);
- break;
- case 5:
- system("cls");
- log_in(lista_users,lista_locais,lista_votos,nome);
- break;
- case 6:
- break;
- }
- }
- int main()
- {
- ListU lista_users=cria_lista_users();
- ListL lista_POI=cria_lista_POI();
- ListV lista_votos=cria_lista_V();
- load_POI(lista_POI);
- load_users(lista_users);
- load_votos(lista_votos);
- char nome[SIZENOME];
- log_in(lista_users,lista_POI,lista_votos,nome);
- /*
- imprime_lista_votos(lista_votos);
- validar_lista_votos(lista_votos,lista_users);
- save_votos(lista_votos);
- imprime_lista_votos(lista_votos);
- votar(lista_users,lista_POI,lista_votos, nome);
- char locais[SIZENOME];
- escrever_locais(lista_users, lista_POI, lista_votos,locais, nome);
- alterar_locais(lista_users,lista_POI, lista_votos, locais, nome);
- alterar_hot(lista_users,lista_POI, lista_votos, "blond", nome);
- alterar_pdis(lista_users,lista_POI, lista_votos, "nostalgia ultra", nome);
- imprime_lista_votos(lista_votos);
- printf("\n\nverificar PDI |%s|: %d\n",hot,verificar_POI(lista_POI,hot));
- printf("\nverificar PDI |%s|: %d\n",pdis,verificar_POI(lista_POI,pdis));
- printf("\nverificar HOT |%s|: %d\n",hot,verificar_hot(lista_votos,hot,nome));
- printf("\nverificar PDIS |%s|: %d\n",pdis,verificar_pdis(lista_votos,pdis,nome));
- escrever_hot(lista_users,lista_POI,lista_votos,hot,nome);
- alterar_hot(lista_users,lista_POI,lista_votos,hot,nome);
- imprimir_votos(lista_votos,nome);
- escrever_pdis(lista_users,lista_POI,lista_votos,pdis,nome);
- alterar_pdis(lista_users,lista_POI,lista_votos,pdis,nome);
- imprimir_votos(lista_votos,nome);
- save_votos(lista_votos);
- escrever_hot(lista_users,lista_POI,lista_votos,hot,nome);
- alterar_hot(lista_users,lista_POI,lista_votos,hot,nome);*/
- return 0;
- }
- /*
- typedef struct pessoa
- typedef struct Locais
- ListU cria_lista_users()
- ListL cria_lista_POI()
- int lista_vazia_POI(ListL h)
- int lista_vazia_users(ListU h)
- void liberta_lista(ListU lista)
- void inserir_user(ListU h, char *nome, char *morada, char* data_nascimento, char *telefone)
- void inserir_POI(ListL h, char *local, char *nome, char* info, char *horario)
- void imprime_lista_POI(ListL lista)
- void imprime_POIs_az(ListL lista)
- void imprime_lista_users(ListU lista)
- void imprimir_user(ListU lista,char*nome)
- void listar_locais(ListL lista)
- void listar_PdIs(ListL lista)
- void imprimir_votos(ListV lista,char*nome)
- void load_users(ListU lista_users)
- void eliminar_user(ListU lista,char *nome)
- void alterar_dados(ListU lista_users,ListL lista_locais,char* nome)
- void load_POI(ListL lista)
- void save_users(ListU lista)
- int verificar_local(ListL lista,char* local)
- int verificar_POI(ListL lista,char* nome)
- int verificar_user(ListU lista,char* nome)
- int verificar_telemovel(char* telemovel)
- int verificar_nome(char* nome)
- int verificar_morada(char* nome)
- int verificar_data(int dia,int mes,int ano)
- void alterar_telemovel(char*nome,char*string,ListU lista)
- void alterar_data(char*nome,char*string,ListU lista)
- void alterar_morada(char*nome,char*string,ListU lista)
- void alterar_nome(char*nome,char*string,ListU lista)
- void escrever_telemovel(char*string,ListU lista_user)
- void escrever_data(char*string,ListU lista_user)
- void escrever_morada(char*string,ListU lista_user)
- void escrever_nome(char*string,ListU lista_user)
- void escrever_locais(ListU lista_users,ListL lista_locais, ListV lista_votos,char *string)
- escrever_hot()
- escrever_pdis()
- void alterar_locais(lista_users, lista_locais, lista_votos, string)
- alterar_hot(lista_users,lista_locais, lista_votos, nome)
- alterar_pdis(lista_users, lista_locais, lista_votos, nome);
- void log_in(ListU lista_users)
- void registar(ListU lista_user)
- void ver_dados(ListU lista_users,ListL lista_locais,char* nome)
- void alterar_dados(ListU lista_users,char* nome)
- void menu(ListU lista_users)*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement