Escolar Documentos
Profissional Documentos
Cultura Documentos
Atividade Prática Estrutura de Dados
Atividade Prática Estrutura de Dados
ATIVIDADE PRÁTICA
#include<stdio.h> // INCLUINDO AS BILBIOTECAS NECESSÁRIAS.
#include<stdlib.h>
#include<string.h>
#include <locale.h>
int menu();// DECLARANDO FUNÇÕES E VARIÁVEIS UTILIZADAS.
void InserirInicio(char musica[20], char artista[20], char tempo[20]);
void InserirFim(char musica[20]);
void InserirMeio(char musica[20], int posicao);
int Remover(char musica[20]);
void Listar();
char musica [20];
char artista[20];
char tempo[20];
struct ElementoDaLista_Simples {// CRIANDO ESTRUTURA DE DADOS
char dado[20];
char dado_1[20];
char dado_2[20];
struct ElementoDaLista_Simples *prox;
} *Head;
int main() { //FUNCAO MAIN PRINCIPAL
int op, num, pos, c;
Head = NULL;
setlocale(LC_ALL, "Portuguese"); // permitir acentuação
while (1) {// CRIADO LOOP INFINITO
op = menu();
1
switch (op) {// UTILIZANDO SWITCH CASE PARA OPÇÕES E CHAMAR AS FUNÇÕES
CORRETAS
case 1:
printf("Digite o nome da música : ");
fgets(musica, 20, stdin);// PREFIRO USAR O FGETS
musica[strcspn(musica, "\n")] = 0; // RETIRANDO O /N DO FGETS PARA
NAO PULAR LINHA INDESEJADA.
printf("Digite o nome do artista : ");
fgets(artista, 20, stdin);
artista[strcspn(artista, "\n")] = 0;
printf("Digite a duração da música : ");
fgets(tempo, 20, stdin);
tempo[strcspn(tempo, "\n")] = 0;
while ((c = getchar()) != '\n' && c != EOF) {} // limpe o buffer
do teclado.
InserirInicio(musica,artista,tempo);
break;
case 2:
printf("Digite o nome da música : ");
fgets(musica, 20, stdin);
musica[strcspn(musica, "\n")] = 0;
printf("Digite o nome do artista : ");
fgets(artista, 20, stdin);
artista[strcspn(artista, "\n")] = 0;
printf("Digite a duração da música : ");
fgets(tempo, 20, stdin);
tempo[strcspn(tempo, "\n")] = 0;
while ((c = getchar()) != '\n' && c != EOF) {} // limpe o buffer
do teclado.
InserirFim(musica);
break;
case 3:
Listar();
break;
case 4:
return 0;
default:
printf("Invalido\n");
}
}
return 0;
}
int menu() { // FUNÇÃO MENU.
int op, c;
system("Cls");
printf("\n Playlist de musicas\n\n\n");
printf(" 1.Inserir nova música no inicio da playlist\n");
printf(" 2.Inserir nova música no final da playlist\n");
printf(" 3.Exibir a playlist\n");
printf(" 4.Sair\n\n");
printf(" Digite sua escolha: ");
scanf_s("%d", &op);
while ((c = getchar()) != '\n' && c != EOF) {} // sempre limpe o buffer do te‐
clado.
system("Cls");
return op;
}
void InserirInicio(char musica[20], char artista[20],char tempo[20]) // FUNÇÃO DE IN‐
SERIR NO INICIO DA LISTA ENCADEADA
{
ElementoDaLista_Simples *NovoElemento;
NovoElemento = (struct ElementoDaLista_Simples *)malloc(sizeof(struct Elemento‐
DaLista_Simples));
strcpy_s(NovoElemento‐>dado, musica);
strcpy_s(NovoElemento‐>dado_1, artista);
strcpy_s(NovoElemento‐>dado_2, tempo);
if (Head == NULL)
{
Head = NovoElemento;
Head‐>prox = NULL;
}
else
{
NovoElemento‐>prox = Head;
Head = NovoElemento;
}
}
void InserirFim(char musica[20])// FUNÇÃO DE INSERIR NO FIM DA LISTA ENCADEADA
{
ElementoDaLista_Simples *NovoElemento;
NovoElemento = (struct ElementoDaLista_Simples *)malloc(sizeof(struct Elemento‐
DaLista_Simples));
ElementoDaLista_Simples *ElementoVarredura;
ElementoVarredura = (struct ElementoDaLista_Simples *)malloc(sizeof(struct Ele‐
mentoDaLista_Simples));
strcpy_s(NovoElemento‐>dado, musica);
strcpy_s(NovoElemento‐>dado_1, artista);
strcpy_s(NovoElemento‐>dado_2, tempo);
if (Head == NULL)
{
Head = NovoElemento;
Head‐>prox = NULL;
}
else
{
ElementoVarredura = Head;
while (ElementoVarredura‐>prox != NULL)
ElementoVarredura = ElementoVarredura‐>prox;
ElementoVarredura‐>prox = NovoElemento;
NovoElemento‐>prox = NULL;
}
}
void Listar() // FUNÇÃO PARA LISTAR OS MEMBROS DA LISTA
{
ElementoDaLista_Simples *ElementoVarredura;
ElementoVarredura = (struct ElementoDaLista_Simples *)malloc(sizeof(struct Ele‐
mentoDaLista_Simples));
ElementoVarredura = Head;
if (ElementoVarredura == NULL) {
return;
}
while (ElementoVarredura != NULL) {
printf("%s " "%s " "%s\n",ElementoVarredura‐>dado, ElementoVarredura‐
>dado_1, ElementoVarredura‐>dado_2);
ElementoVarredura = ElementoVarredura‐>prox;
}
printf("\n");
system("pause");
return;
}
#include <stdio.h>// BIBLIOTECAS UTILIZADAS
#include <string.h>
#include <stdlib.h>
int main()//FUNÇÃO MAIN
{
int RUaluno;// DECLARAÇÃO DE VARIÁVEIS
int opcao;
char pause[1];
struct alunos {// ESTRUTURA DE DADOS
char nome[20];
char email[20];
int RU;
};
struct alunos aluno_1, aluno_2, aluno_3, aluno_4, aluno_5, aluno_6, aluno_7,//
ALIMENTANDO A ESTRUTURA CRIADA
aluno_8, aluno_9, aluno_10;
strcpy_s(aluno_1.nome, "Ediney");
strcpy_s(aluno_1.email, "eorocha@eorocha");
aluno_1.RU = 3277023;
strcpy_s(aluno_2.nome, "Fabrício");
strcpy_s(aluno_2.email, "ferro@ferro");
aluno_2.RU = 2222222;
strcpy_s(aluno_3.nome, "Manoel");
strcpy_s(aluno_3.email, "manoel@manoel");
aluno_3.RU = 3333333;
strcpy_s(aluno_4.nome, "Tatiana");
strcpy_s(aluno_4.email, "tatiana@tatiana");
aluno_4.RU = 4444444;
strcpy_s(aluno_5.nome, "Igor");
strcpy_s(aluno_5.email, "igor@igor");
aluno_5.RU = 5555555;
strcpy_s(aluno_6.nome, "Andre");
strcpy_s(aluno_6.email, "andre@andre");
aluno_6.RU = 6666666;
strcpy_s(aluno_7.nome, "Arnaldo");
strcpy_s(aluno_7.email, "arnaldo@arnaldo");
aluno_7.RU = 7777777;
strcpy_s(aluno_8.nome, "Evair");
strcpy_s(aluno_8.email, "evair@evair");
aluno_8.RU = 8888888;
strcpy_s(aluno_9.nome, "Rocha");
strcpy_s(aluno_9.email, "rocha@rocha");
aluno_9.RU = 9999999;
strcpy_s(aluno_10.nome, "Oliveira");
strcpy_s(aluno_10.email, "oliveira@oliveira");
aluno_10.RU = 1000000;
//CRIANDO O MENU
while (1) {
printf(" Cadastro de aluno\n");
printf("Digite a opção desejada\n\n");
printf("1 ‐ Mostrar todos os alunos cadastrados\n");
printf("2 ‐ Buscar aluno.\n");
printf("3 ‐ Sair.\n");
scanf_s("%d", &opcao);
switch (opcao) {//UTILIZANDO SWITCH CASE PARA OPÇÕES
case 1:
printf("%s ""%s ""%d \n", aluno_1.nome, aluno_1.email,
aluno_1.RU);
printf("%s ""%s ""%d \n", aluno_2.nome, aluno_2.email,
aluno_2.RU);
printf("%s ""%s ""%d \n", aluno_3.nome, aluno_3.email,
aluno_3.RU);
printf("%s ""%s ""%d \n", aluno_4.nome, aluno_4.email,
aluno_4.RU);
printf("%s ""%s ""%d \n", aluno_5.nome, aluno_5.email,
aluno_5.RU);
printf("%s ""%s ""%d \n", aluno_6.nome, aluno_6.email,
aluno_6.RU);
printf("%s ""%s ""%d \n", aluno_7.nome, aluno_7.email,
aluno_7.RU);
printf("%s ""%s ""%d \n", aluno_8.nome, aluno_8.email,
aluno_8.RU);
printf("%s ""%s ""%d \n", aluno_9.nome, aluno_9.email,
aluno_9.RU);
printf("%s ""%s ""%d \n\n\n", aluno_10.nome, aluno_10.email,
aluno_10.RU);
system("pause");
system("cls");
break;
case 2:
printf("digite o RU do aluno: ");
scanf_s("%d", &RUaluno);
if (RUaluno == aluno_1.RU) {//DECISÕES PARA ENCONTRAR O ALUNO
printf("%s ""%s ""%d \n", aluno_1.nome, aluno_1.email,
aluno_1.RU);
system("pause");
system("cls");
}
else if (RUaluno == aluno_2.RU) {
printf("%s ""%s ""%d\n \n", aluno_2.nome, aluno_2.email,
aluno_2.RU);
system("pause");
system("cls");
}
else if (RUaluno == aluno_3.RU) {
printf("%s ""%s ""%d\n \n", aluno_3.nome, aluno_3.email,
aluno_3.RU);
system("pause");
system("cls");
}
else if (RUaluno == aluno_4.RU) {
printf("%s ""%s ""%d\n \n", aluno_4.nome, aluno_4.email,
aluno_4.RU);
system("pause");
system("cls");
}
else if (RUaluno == aluno_5.RU) {
printf("%s ""%s ""%d\n \n", aluno_5.nome, aluno_5.email,
aluno_5.RU);
system("pause");
system("cls");
}
else if (RUaluno == aluno_6.RU) {
printf("%s ""%s ""%d\n \n", aluno_6.nome, aluno_6.email,
aluno_6.RU);
system("pause");
system("cls");
}
else if (RUaluno == aluno_7.RU) {
printf("%s ""%s ""%d\n \n", aluno_7.nome, aluno_7.email,
aluno_7.RU);
system("pause");
system("cls");
}
else if (RUaluno == aluno_8.RU) {
printf("%s ""%s ""%d\n \n", aluno_8.nome, aluno_8.email,
aluno_8.RU);
system("pause");
system("cls");
}
else if (RUaluno == aluno_9.RU) {
printf("%s ""%s ""%d\n \n", aluno_9.nome, aluno_9.email,
aluno_9.RU);
system("pause");
system("cls");
}
else if (RUaluno == aluno_10.RU) {
printf("%s ""%s ""%d\n \n", aluno_10.nome, aluno_10.email,
aluno_10.RU);
system("pause");
system("cls");
}
else {
printf("aluno nao encontrado\n\n");
system("pause");
system("cls");
}
break;
case 3:
return 0;
default:
printf("opcao invalida\n\n");
system("pause");
system("cls");
break;
}
}
}